Fix flow unit tests

This commit is contained in:
Nick O'Leary 2022-06-29 11:41:19 +01:00
parent 7580f7491a
commit b59a3b15f3
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 11 additions and 60 deletions

View File

@ -322,7 +322,10 @@ async function start(type,diff,muteLog,isDeploy) {
return;
}
const runtimeState = settings.get('runtimeFlowState') || 'start'
let runtimeState
try {
runtimeState = settings.get('runtimeFlowState') || 'start'
} catch (err) {}
if (runtimeState === 'stop') {
log.info(log._("nodes.flows.stopped-flows"));
events.emit("runtime-event",{id:"runtime-state",payload:{ state: 'stop', deploy:isDeploy },retain:true});

View File

@ -321,59 +321,6 @@ describe('flows/index', function() {
return flows.startFlows();
});
});
it('emits runtime-event "flows-run-state" "started"', async function () {
var originalConfig = [
{ id: "t1-1", x: 10, y: 10, z: "t1", type: "test", wires: [] },
{ id: "t1", type: "tab" }
];
storage.getFlows = function () {
return Promise.resolve({ flows: originalConfig });
}
let receivedEvent = null;
const handleEvent = (data) => {
if(data && data.id === 'flows-run-state') {
receivedEvent = data;
}
}
events.on('runtime-event', handleEvent);
flows.init({ log: mockLog, settings: {}, storage: storage });
await flows.load()
await flows.startFlows()
events.removeListener("runtime-event", handleEvent);
//{id:"flows-run-state", payload: {started: true, state: "started"}
should(receivedEvent).not.be.null()
receivedEvent.should.have.property("id", "flows-run-state")
receivedEvent.should.have.property("payload", { started: true, state: "started" })
receivedEvent.should.have.property("retain", true)
});
it('emits runtime-event "flows-run-state" "stopped"', async function () {
const originalConfig = [
{ id: "t1-1", x: 10, y: 10, z: "t1", type: "test", wires: [] },
{ id: "t1", type: "tab" }
];
storage.getFlows = function () {
return Promise.resolve({ flows: originalConfig });
}
let receivedEvent = null;
const handleEvent = (data) => {
if(data && data.id === 'flows-run-state') {
receivedEvent = data;
}
}
events.on('runtime-event', handleEvent);
flows.init({ log: mockLog, settings: {}, storage: storage });
await flows.load()
await flows.startFlows()
await flows.stopFlows()
events.removeListener("runtime-event", handleEvent);
//{id:"flows-run-state", payload: {started: true, state: "started"}
should(receivedEvent).not.be.null()
receivedEvent.should.have.property("id", "flows-run-state")
receivedEvent.should.have.property("payload", { started: false, state: "stopped" })
receivedEvent.should.have.property("retain", true)
});
it('does not start if nodes missing', function(done) {
var originalConfig = [
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
@ -449,12 +396,13 @@ describe('flows/index', function() {
try {
flowCreate.called.should.be.false();
receivedEvent.should.have.property('id','runtime-state');
receivedEvent.should.have.property('payload',
{ error: 'missing-modules',
type: 'warning',
text: 'notification.warnings.missing-modules',
modules: [] }
);
receivedEvent.should.have.property('payload', {
state: 'stop',
error: 'missing-modules',
type: 'warning',
text: 'notification.warnings.missing-modules',
modules: []
});
done();
}catch(err) {