From b59a3b15f361283d97ddd14bba27fac3841aece1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 29 Jun 2022 11:41:19 +0100 Subject: [PATCH] Fix flow unit tests --- .../@node-red/runtime/lib/flows/index.js | 5 +- .../@node-red/runtime/lib/flows/index_spec.js | 66 ++----------------- 2 files changed, 11 insertions(+), 60 deletions(-) diff --git a/packages/node_modules/@node-red/runtime/lib/flows/index.js b/packages/node_modules/@node-red/runtime/lib/flows/index.js index b2de8ea73..1b5476a3f 100644 --- a/packages/node_modules/@node-red/runtime/lib/flows/index.js +++ b/packages/node_modules/@node-red/runtime/lib/flows/index.js @@ -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}); diff --git a/test/unit/@node-red/runtime/lib/flows/index_spec.js b/test/unit/@node-red/runtime/lib/flows/index_spec.js index 5e8f8a46e..1a0f2a73c 100644 --- a/test/unit/@node-red/runtime/lib/flows/index_spec.js +++ b/test/unit/@node-red/runtime/lib/flows/index_spec.js @@ -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) {