Fix tests for externalModules component

This commit is contained in:
Nick O'Leary 2021-02-13 00:18:04 +00:00
parent a94c19a6cf
commit e899d2d5b8
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 58 additions and 8 deletions

View File

@ -106,7 +106,7 @@
"marked": "1.2.7",
"minami": "1.2.3",
"mocha": "^5.2.0",
"node-red-node-test-helper": "^0.2.5",
"node-red-node-test-helper": "^0.2.7",
"node-sass": "^4.14.1",
"nodemon": "2.0.6",
"should": "13.2.3",

View File

@ -40,7 +40,7 @@ describe('red/registry/index', function() {
stubs.push(sinon.stub(loader,"init"));
stubs.push(sinon.stub(typeRegistry,"init"));
registry.init({});
registry.init({settings:{}});
installer.init.called.should.be.true();
loader.init.called.should.be.true();
typeRegistry.init.called.should.be.true();

View File

@ -36,6 +36,7 @@ describe('flows/index', function() {
var flowCreate;
var getType;
var checkFlowDependencies;
var mockLog = {
log: sinon.stub(),
@ -52,9 +53,16 @@ describe('flows/index', function() {
getType = sinon.stub(typeRegistry,"get",function(type) {
return type.indexOf('missing') === -1;
});
checkFlowDependencies = sinon.stub(typeRegistry, "checkFlowDependencies", async function(flow) {
if (flow[0].id === "node-with-missing-modules") {
throw new Error("Missing module");
}
});
});
after(function() {
getType.restore();
checkFlowDependencies.restore();
});
@ -306,7 +314,7 @@ describe('flows/index', function() {
flows.init({log:mockLog, settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
return flows.startFlows();
});
});
it('does not start if nodes missing', function(done) {
@ -321,9 +329,14 @@ describe('flows/index', function() {
flows.init({log:mockLog, settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
flowCreate.called.should.be.false();
done();
return flows.startFlows();
}).then(() => {
try {
flowCreate.called.should.be.false();
done();
} catch(err) {
done(err);
}
});
});
@ -339,9 +352,9 @@ describe('flows/index', function() {
}
flows.init({log:mockLog, settings:{},storage:storage});
flows.load().then(function() {
flows.startFlows();
return flows.startFlows();
}).then(() => {
flowCreate.called.should.be.false();
events.emit("type-registered","missing");
setTimeout(function() {
flowCreate.called.should.be.false();
@ -354,7 +367,44 @@ describe('flows/index', function() {
});
});
it('does not start if external modules missing', function(done) {
var originalConfig = [
{id:"node-with-missing-modules",x:10,y:10,z:"t1",type:"test",wires:[]},
{id:"t1",type:"tab"}
];
storage.getFlows = function() {
return Promise.resolve({flows:originalConfig});
}
var receivedEvent = null;
var handleEvent = function(payload) {
receivedEvent = payload;
}
events.on("runtime-event",handleEvent);
//{id:"runtime-state",payload:{error:"missing-modules", type:"warning",text:"notification.warnings.missing-modules",modules:missingModules},retain:true});"
flows.init({log:mockLog, settings:{},storage:storage});
flows.load().then(flows.startFlows).then(() => {
events.removeListener("runtime-event",handleEvent);
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: [] }
);
done();
}catch(err) {
done(err)
}
});
});
});