mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix flow unit tests
This commit is contained in:
parent
7580f7491a
commit
b59a3b15f3
@ -322,7 +322,10 @@ async function start(type,diff,muteLog,isDeploy) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const runtimeState = settings.get('runtimeFlowState') || 'start'
|
let runtimeState
|
||||||
|
try {
|
||||||
|
runtimeState = settings.get('runtimeFlowState') || 'start'
|
||||||
|
} catch (err) {}
|
||||||
if (runtimeState === 'stop') {
|
if (runtimeState === 'stop') {
|
||||||
log.info(log._("nodes.flows.stopped-flows"));
|
log.info(log._("nodes.flows.stopped-flows"));
|
||||||
events.emit("runtime-event",{id:"runtime-state",payload:{ state: 'stop', deploy:isDeploy },retain:true});
|
events.emit("runtime-event",{id:"runtime-state",payload:{ state: 'stop', deploy:isDeploy },retain:true});
|
||||||
|
@ -321,59 +321,6 @@ describe('flows/index', function() {
|
|||||||
return flows.startFlows();
|
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) {
|
it('does not start if nodes missing', function(done) {
|
||||||
var originalConfig = [
|
var originalConfig = [
|
||||||
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
{id:"t1-1",x:10,y:10,z:"t1",type:"test",wires:[]},
|
||||||
@ -449,12 +396,13 @@ describe('flows/index', function() {
|
|||||||
try {
|
try {
|
||||||
flowCreate.called.should.be.false();
|
flowCreate.called.should.be.false();
|
||||||
receivedEvent.should.have.property('id','runtime-state');
|
receivedEvent.should.have.property('id','runtime-state');
|
||||||
receivedEvent.should.have.property('payload',
|
receivedEvent.should.have.property('payload', {
|
||||||
{ error: 'missing-modules',
|
state: 'stop',
|
||||||
type: 'warning',
|
error: 'missing-modules',
|
||||||
text: 'notification.warnings.missing-modules',
|
type: 'warning',
|
||||||
modules: [] }
|
text: 'notification.warnings.missing-modules',
|
||||||
);
|
modules: []
|
||||||
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}catch(err) {
|
}catch(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user