mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Move node registry to its own top level dir
This commit is contained in:
@@ -24,7 +24,7 @@ var flowUtils = require("../../../../../red/runtime/nodes/flows/util");
|
||||
var Flow = require("../../../../../red/runtime/nodes/flows/Flow");
|
||||
var flows = require("../../../../../red/runtime/nodes/flows");
|
||||
var Node = require("../../../../../red/runtime/nodes/Node");
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry");
|
||||
var typeRegistry = require("../../../../../red/runtime-registry");
|
||||
|
||||
|
||||
describe('Flow', function() {
|
||||
|
@@ -23,7 +23,7 @@ var RedNode = require("../../../../../red/runtime/nodes/Node");
|
||||
var RED = require("../../../../../red/runtime/nodes");
|
||||
var events = require("../../../../../red/runtime/events");
|
||||
var credentials = require("../../../../../red/runtime/nodes/credentials");
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry");
|
||||
var typeRegistry = require("../../../../../red/runtime-registry");
|
||||
var Flow = require("../../../../../red/runtime/nodes/flows/Flow");
|
||||
|
||||
describe('flows/index', function() {
|
||||
|
@@ -19,7 +19,7 @@ var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var clone = require("clone");
|
||||
var flowUtil = require("../../../../../red/runtime/nodes/flows/util");
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry");
|
||||
var typeRegistry = require("../../../../../red/runtime-registry");
|
||||
var redUtil = require("../../../../../red/runtime/util");
|
||||
|
||||
describe('flows/util', function() {
|
||||
|
@@ -19,9 +19,12 @@ var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
var when = require("when");
|
||||
var sinon = require('sinon');
|
||||
var inherits = require("util").inherits;
|
||||
|
||||
var index = require("../../../../red/runtime/nodes/index");
|
||||
var flows = require("../../../../red/runtime/nodes/flows");
|
||||
var registry = require("../../../../red/runtime/nodes/registry");
|
||||
var registry = require("../../../../red/runtime-registry");
|
||||
var Node = require("../../../../red/runtime/nodes/Node");
|
||||
|
||||
describe("red/nodes/index", function() {
|
||||
before(function() {
|
||||
@@ -122,7 +125,45 @@ describe("red/nodes/index", function() {
|
||||
registry.registerType.firstCall.args[2].should.eql(TestNode);
|
||||
});
|
||||
});
|
||||
describe("extends constructor with Node constructor", function() {
|
||||
var TestNodeConstructor;
|
||||
before(function() {
|
||||
sinon.stub(registry,"registerType");
|
||||
});
|
||||
after(function() {
|
||||
registry.registerType.restore();
|
||||
});
|
||||
beforeEach(function() {
|
||||
TestNodeConstructor = function TestNodeConstructor() {};
|
||||
var runtime = {
|
||||
settings: settings,
|
||||
storage: storage,
|
||||
log: {debug:function() {}, warn:sinon.spy()},
|
||||
events: new EventEmitter()
|
||||
}
|
||||
index.init(runtime);
|
||||
})
|
||||
it('extends a constructor with the Node constructor', function() {
|
||||
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
||||
index.registerType('node-set','node-type',TestNodeConstructor);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
});
|
||||
it('does not override a constructor prototype', function() {
|
||||
function Foo(){};
|
||||
inherits(TestNodeConstructor,Foo);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
||||
|
||||
index.registerType('node-set','node-type',TestNodeConstructor);
|
||||
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
|
||||
index.registerType('node-set','node-type2',TestNodeConstructor);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
});
|
||||
});
|
||||
describe("register credentials definition", function() {
|
||||
var http = require('http');
|
||||
var express = require('express');
|
||||
@@ -294,7 +335,6 @@ describe("red/nodes/index", function() {
|
||||
});
|
||||
|
||||
describe('allows modules to be removed from the registry', function() {
|
||||
var registry = require("../../../../red/runtime/nodes/registry");
|
||||
var randomNodeInfo = {id:"5678",types:["random"]};
|
||||
var randomModuleInfo = {
|
||||
name:"random",
|
||||
|
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var events = new EventEmitter();
|
||||
|
||||
var should = require("should");
|
||||
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
var library = require("../../../../red/runtime/nodes/library")
|
||||
|
||||
describe("library api", function() {
|
||||
it('returns null list when no modules have been registered', function() {
|
||||
library.init({events:events});
|
||||
should.not.exist(library.getExampleFlows());
|
||||
});
|
||||
it('returns null path when module is not known', function() {
|
||||
library.init({events:events});
|
||||
should.not.exist(library.getExampleFlowPath('foo','bar'));
|
||||
});
|
||||
|
||||
it('returns a valid example path', function(done) {
|
||||
library.init({events:events});
|
||||
events.emit('node-examples-dir',{
|
||||
name: "test-module",
|
||||
path: path.resolve(__dirname+'/../../../resources/examples')
|
||||
});
|
||||
setTimeout(function() {
|
||||
try {
|
||||
var flows = library.getExampleFlows();
|
||||
flows.should.deepEqual({"d":{"test-module":{"f":["one"]}}});
|
||||
|
||||
var examplePath = library.getExampleFlowPath('test-module','one');
|
||||
examplePath.should.eql(path.resolve(__dirname+'/../../../resources/examples/one.json'))
|
||||
|
||||
|
||||
events.emit('node-module-uninstalled', 'test-module');
|
||||
|
||||
setTimeout(function() {
|
||||
try {
|
||||
should.not.exist(library.getExampleFlows());
|
||||
should.not.exist(library.getExampleFlowPath('test-module','one'));
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},20);
|
||||
}catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},20);
|
||||
|
||||
})
|
||||
});
|
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
|
||||
var deprecated = require("../../../../../red/runtime/nodes/registry/deprecated.js");
|
||||
|
||||
describe('deprecated', function() {
|
||||
it('should return info on a node',function() {
|
||||
deprecated.get("irc in").should.eql({module:"node-red-node-irc"});
|
||||
});
|
||||
it('should return null for non-deprecated node',function() {
|
||||
should.not.exist(deprecated.get("foo"));
|
||||
});
|
||||
});
|
@@ -1,129 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var when = require("when");
|
||||
var fs = require("fs");
|
||||
|
||||
var registry = require("../../../../../red/runtime/nodes/registry");
|
||||
|
||||
var installer = require("../../../../../red/runtime/nodes/registry/installer");
|
||||
var loader = require("../../../../../red/runtime/nodes/registry/loader");
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry");
|
||||
|
||||
|
||||
|
||||
|
||||
describe('red/nodes/registry/index', function() {
|
||||
var stubs = [];
|
||||
afterEach(function() {
|
||||
while(stubs.length) {
|
||||
stubs.pop().restore();
|
||||
}
|
||||
})
|
||||
describe('#init',function() {
|
||||
it('intialises components', function() {
|
||||
stubs.push(sinon.stub(installer,"init"));
|
||||
stubs.push(sinon.stub(loader,"init"));
|
||||
stubs.push(sinon.stub(typeRegistry,"init"));
|
||||
|
||||
registry.init({});
|
||||
installer.init.called.should.be.true();
|
||||
loader.init.called.should.be.true();
|
||||
typeRegistry.init.called.should.be.true();
|
||||
})
|
||||
});
|
||||
|
||||
describe('#addModule', function() {
|
||||
it('loads the module and returns its info', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
}));
|
||||
registry.addModule("foo").then(function(info) {
|
||||
info.should.eql("info");
|
||||
done();
|
||||
}).catch(function(err) { done(err); });
|
||||
});
|
||||
it('rejects if loader rejects', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.reject("error");
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
}));
|
||||
registry.addModule("foo").then(function(info) {
|
||||
done(new Error("unexpected resolve"));
|
||||
}).catch(function(err) {
|
||||
err.should.eql("error");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('#enableNode',function() {
|
||||
it('enables a node set',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||
return {id:"node-set",loaded:true};
|
||||
}));
|
||||
registry.enableNode("node-set").then(function(ns) {
|
||||
typeRegistry.enableNodeSet.called.should.be.true();
|
||||
ns.should.have.a.property('id','node-set');
|
||||
done();
|
||||
}).catch(function(err) { done(err); });
|
||||
});
|
||||
|
||||
it('rejects if node unknown',function() {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
throw new Error('failure');
|
||||
}));
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
registry.enableNode("node-set")
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
it('triggers a node load',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
}));
|
||||
var calls = 0;
|
||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||
// loaded=false on first call, true on subsequent
|
||||
return {id:"node-set",loaded:(calls++>0)};
|
||||
}));
|
||||
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return when.resolve();}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
|
||||
|
||||
registry.enableNode("node-set").then(function(ns) {
|
||||
typeRegistry.enableNodeSet.called.should.be.true();
|
||||
loader.loadNodeSet.called.should.be.true();
|
||||
ns.should.have.a.property('id','node-set');
|
||||
ns.should.have.a.property('loaded',true);
|
||||
done();
|
||||
}).catch(function(err) { done(err); });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@@ -1,260 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require('fs');
|
||||
var EventEmitter = require('events');
|
||||
|
||||
var child_process = require('child_process');
|
||||
var installer = require("../../../../../red/runtime/nodes/registry/installer");
|
||||
var registry = require("../../../../../red/runtime/nodes/registry/index");
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry");
|
||||
|
||||
describe('nodes/registry/installer', function() {
|
||||
|
||||
var mockLog = {
|
||||
log: sinon.stub(),
|
||||
debug: sinon.stub(),
|
||||
trace: sinon.stub(),
|
||||
warn: sinon.stub(),
|
||||
info: sinon.stub(),
|
||||
metric: sinon.stub(),
|
||||
_: function() { return "abc"}
|
||||
}
|
||||
|
||||
before(function() {
|
||||
installer.init({log:mockLog, settings:{}});
|
||||
});
|
||||
afterEach(function() {
|
||||
if (child_process.spawn.restore) {
|
||||
child_process.spawn.restore();
|
||||
}
|
||||
if (child_process.execFile.restore) {
|
||||
child_process.execFile.restore();
|
||||
}
|
||||
if (registry.addModule.restore) {
|
||||
registry.addModule.restore();
|
||||
}
|
||||
if (registry.removeModule.restore) {
|
||||
registry.removeModule.restore();
|
||||
}
|
||||
if (typeRegistry.removeModule.restore) {
|
||||
typeRegistry.removeModule.restore();
|
||||
}
|
||||
if (registry.getModuleInfo.restore) {
|
||||
registry.getModuleInfo.restore();
|
||||
}
|
||||
if (typeRegistry.getModuleInfo.restore) {
|
||||
typeRegistry.getModuleInfo.restore();
|
||||
}
|
||||
|
||||
if (require('fs').statSync.restore) {
|
||||
require('fs').statSync.restore();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
describe("installs module", function() {
|
||||
it("rejects when npm returns a 404", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.stderr.emit('data'," 404 this_wont_exist");
|
||||
ee.emit('close',1);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist").catch(function(err) {
|
||||
err.should.have.property("code",404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("rejects when npm does not find specified version", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.stderr.emit('data'," version not found: this_wont_exist@0.1.2");
|
||||
ee.emit('close',1);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
||||
return {
|
||||
version: "0.1.1"
|
||||
}
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist","0.1.2").catch(function(err) {
|
||||
err.code.should.be.eql(404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("rejects when update requested to existing version", function(done) {
|
||||
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
||||
return {
|
||||
version: "0.1.1"
|
||||
}
|
||||
});
|
||||
installer.installModule("this_wont_exist","0.1.1").catch(function(err) {
|
||||
err.code.should.be.eql('module_already_loaded');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("rejects with generic error", function(done) {
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt,cb) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.stderr.emit('data'," kaboom!");
|
||||
ee.emit('close',1);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
}).catch(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("succeeds when module is found", function(done) {
|
||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.emit('close',0);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist").then(function(info) {
|
||||
info.should.eql(nodeInfo);
|
||||
// commsMessages.should.have.length(1);
|
||||
// commsMessages[0].topic.should.equal("node/added");
|
||||
// commsMessages[0].msg.should.eql(nodeInfo.nodes);
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it("rejects when non-existant path is provided", function(done) {
|
||||
this.timeout(10000);
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local","TestNodeModule","node_modules","NonExistant"));
|
||||
installer.installModule(resourcesDir).then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
}).catch(function(err) {
|
||||
if (err.hasOwnProperty("code")) {
|
||||
err.code.should.eql(404);
|
||||
done();
|
||||
}
|
||||
else {
|
||||
console.log("ERRROR::"+err.toString()+"::");
|
||||
err.toString().should.eql("Error: Install failed");
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
it("succeeds when path is valid node-red module", function(done) {
|
||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||
sinon.stub(child_process,"spawn",function(cmd,args,opt) {
|
||||
var ee = new EventEmitter();
|
||||
ee.stdout = new EventEmitter();
|
||||
ee.stderr = new EventEmitter();
|
||||
setTimeout(function() {
|
||||
ee.emit('close',0);
|
||||
},10)
|
||||
return ee;
|
||||
});
|
||||
installer.installModule(resourcesDir).then(function(info) {
|
||||
info.should.eql(nodeInfo);
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
describe("uninstalls module", function() {
|
||||
it("rejects invalid module names", function(done) {
|
||||
var promises = [];
|
||||
promises.push(installer.uninstallModule("this_wont_exist "));
|
||||
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont"));
|
||||
when.settle(promises).then(function(results) {
|
||||
results[0].state.should.be.eql("rejected");
|
||||
results[1].state.should.be.eql("rejected");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects with generic error", function(done) {
|
||||
var nodeInfo = [{module:"foo",types:["a"]}];
|
||||
var removeModule = sinon.stub(registry,"removeModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
});
|
||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
||||
cb(new Error("test_error"),"","");
|
||||
});
|
||||
|
||||
installer.uninstallModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
}).catch(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("succeeds when module is found", function(done) {
|
||||
var nodeInfo = [{module:"foo",types:["a"]}];
|
||||
var removeModule = sinon.stub(typeRegistry,"removeModule",function(md) {
|
||||
return nodeInfo;
|
||||
});
|
||||
var getModuleInfo = sinon.stub(registry,"getModuleInfo",function(md) {
|
||||
return {nodes:[]};
|
||||
});
|
||||
sinon.stub(child_process,"execFile",function(cmd,args,opt,cb) {
|
||||
cb(null,"","");
|
||||
});
|
||||
|
||||
sinon.stub(fs,"statSync", function(fn) { return {}; });
|
||||
|
||||
installer.uninstallModule("this_wont_exist").then(function(info) {
|
||||
info.should.eql(nodeInfo);
|
||||
// commsMessages.should.have.length(1);
|
||||
// commsMessages[0].topic.should.equal("node/removed");
|
||||
// commsMessages[0].msg.should.eql(nodeInfo);
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,608 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
var loader = require("../../../../../red/runtime/nodes/registry/loader");
|
||||
|
||||
var localfilesystem = require("../../../../../red/runtime/nodes/registry/localfilesystem");
|
||||
var registry = require("../../../../../red/runtime/nodes/registry/registry");
|
||||
|
||||
var nodes = require("../../../../../red/runtime/nodes/registry");
|
||||
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local"));
|
||||
|
||||
describe("red/nodes/registry/loader",function() {
|
||||
var stubs = [];
|
||||
before(function() {
|
||||
sinon.stub(localfilesystem,"init");
|
||||
});
|
||||
after(function() {
|
||||
localfilesystem.init.restore();
|
||||
});
|
||||
afterEach(function() {
|
||||
while(stubs.length) {
|
||||
stubs.pop().restore();
|
||||
}
|
||||
})
|
||||
describe("#init",function() {
|
||||
it("init",function() {
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){},log:{info:function(){},_:function(){}}}});
|
||||
localfilesystem.init.called.should.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#load",function() {
|
||||
it("load empty set without settings available", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return false;}}});
|
||||
loader.load("foo",true).then(function() {
|
||||
localfilesystem.getNodeFiles.called.should.be.true();
|
||||
localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo');
|
||||
localfilesystem.getNodeFiles.lastCall.args[1].should.be.true();
|
||||
registry.saveNodeList.called.should.be.false();
|
||||
done();
|
||||
})
|
||||
});
|
||||
it("load empty set with settings available triggers registery save", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};}));
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};}));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load("foo",true).then(function() {
|
||||
registry.saveNodeList.called.should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
})
|
||||
});
|
||||
|
||||
it("load core node files scanned by lfs - single node single file", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"TestNode1": {
|
||||
"file": path.join(resourcesDir,"TestNode1","TestNode1.js"),
|
||||
"module": "node-red",
|
||||
"name": "TestNode1"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-1');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
||||
|
||||
nodes.registerType.calledOnce.should.be.true();
|
||||
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode1');
|
||||
nodes.registerType.lastCall.args[1].should.eql('test-node-1');
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("load core node files scanned by lfs - multiple nodes single file", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"MultipleNodes1": {
|
||||
"file": path.join(resourcesDir,"MultipleNodes1","MultipleNodes1.js"),
|
||||
"module": "node-red",
|
||||
"name": "MultipleNodes1"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/MultipleNodes1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(2);
|
||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-multiple-1a');
|
||||
registry.addNodeSet.lastCall.args[1].types[1].should.eql('test-node-multiple-1b');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
||||
|
||||
nodes.registerType.calledTwice.should.be.true();
|
||||
nodes.registerType.firstCall.args[0].should.eql('node-red/MultipleNodes1');
|
||||
nodes.registerType.firstCall.args[1].should.eql('test-node-multiple-1a');
|
||||
nodes.registerType.secondCall.args[0].should.eql('node-red/MultipleNodes1');
|
||||
nodes.registerType.secondCall.args[1].should.eql('test-node-multiple-1b');
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("load core node files scanned by lfs - node with promise", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"TestNode2": {
|
||||
"file": path.join(resourcesDir,"TestNode2","TestNode2.js"),
|
||||
"module": "node-red",
|
||||
"name": "TestNode2"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode2");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-2');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
||||
|
||||
nodes.registerType.calledOnce.should.be.true();
|
||||
nodes.registerType.lastCall.args[0].should.eql('node-red/TestNode2');
|
||||
nodes.registerType.lastCall.args[1].should.eql('test-node-2');
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it("load core node files scanned by lfs - node with rejecting promise", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"TestNode3": {
|
||||
"file": path.join(resourcesDir,"TestNode3","TestNode3.js"),
|
||||
"module": "node-red",
|
||||
"name": "TestNode3"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/TestNode3");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-3');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err','fail');
|
||||
|
||||
nodes.registerType.calledOnce.should.be.false();
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("load core node files scanned by lfs - missing file", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"DoesNotExist": {
|
||||
"file": path.join(resourcesDir,"doesnotexist"),
|
||||
"module": "node-red",
|
||||
"name": "DoesNotExist"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DoesNotExist");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
|
||||
|
||||
nodes.registerType.calledOnce.should.be.false();
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("load core node files scanned by lfs - missing html file", function(done) {
|
||||
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){
|
||||
var result = {};
|
||||
result["node-red"] = {
|
||||
"name": "node-red",
|
||||
"nodes": {
|
||||
"DuffNode": {
|
||||
"file": path.join(resourcesDir,"DuffNode","DuffNode.js"),
|
||||
"module": "node-red",
|
||||
"name": "DuffNode"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.load().then(function(result) {
|
||||
registry.addNodeSet.called.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("node-red/DuffNode");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"node-red/DuffNode");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"node-red");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',false);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',undefined);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(0);
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('namespace','node-red');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('err');
|
||||
registry.addNodeSet.lastCall.args[1].err.should.endWith("DuffNode.html does not exist");
|
||||
|
||||
nodes.registerType.calledOnce.should.be.false();
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addModule",function() {
|
||||
it("throws error if settings unavailable", function() {
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return false;}}});
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
loader.addModule("test-module");
|
||||
}).should.throw("Settings unavailable");
|
||||
});
|
||||
|
||||
it("returns rejected error if module already loaded", function(done) {
|
||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}}));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
|
||||
loader.addModule("test-module").catch(function(err) {
|
||||
err.code.should.eql("module_already_loaded");
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("returns rejected error if module not found", function(done) {
|
||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return null}));
|
||||
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() {
|
||||
throw new Error("failure");
|
||||
}));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.addModule("test-module").catch(function(err) {
|
||||
err.message.should.eql("failure");
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("loads module by name", function(done) {
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){ return null; }));
|
||||
stubs.push(sinon.stub(localfilesystem,"getModuleFiles", function(){
|
||||
var result = {};
|
||||
result["TestNodeModule"] = {
|
||||
"name": "TestNodeModule",
|
||||
"version": "1.2.3",
|
||||
"nodes": {
|
||||
"TestNode1": {
|
||||
"file": path.join(resourcesDir,"TestNodeModule","node_modules","TestNodeModule","TestNodeModule.js"),
|
||||
"module": "TestNodeModule",
|
||||
"name": "TestNode1",
|
||||
"version": "1.2.3"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
|
||||
loader.addModule("TestNodeModule").then(function(result) {
|
||||
result.should.eql("a node list");
|
||||
registry.addNodeSet.calledOnce.should.be.true();
|
||||
registry.addNodeSet.lastCall.args[0].should.eql("TestNodeModule/TestNode1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('id',"TestNodeModule/TestNode1");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('module',"TestNodeModule");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('enabled',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('loaded',true);
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('version',"1.2.3");
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('types');
|
||||
registry.addNodeSet.lastCall.args[1].types.should.have.a.length(1);
|
||||
registry.addNodeSet.lastCall.args[1].types[0].should.eql('test-node-mod-1');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('config');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('help');
|
||||
registry.addNodeSet.lastCall.args[1].should.have.a.property('namespace','TestNodeModule');
|
||||
registry.addNodeSet.lastCall.args[1].should.not.have.a.property('err');
|
||||
|
||||
nodes.registerType.calledOnce.should.be.true();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("skips module that fails version check", function(done) {
|
||||
// This module isn't already loaded
|
||||
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; }));
|
||||
stubs.push(sinon.stub(registry,"getModuleInfo",function(){ return null; }));
|
||||
stubs.push(sinon.stub(localfilesystem,"getModuleFiles", function(){
|
||||
var result = {};
|
||||
result["TestNodeModule"] = {
|
||||
"name": "TestNodeModule",
|
||||
"version": "1.2.3",
|
||||
"redVersion":"999.0.0",
|
||||
"nodes": {
|
||||
"TestNode1": {
|
||||
"file": path.join(resourcesDir,"TestNodeModule","node_modules","TestNodeModule","TestNodeModule.js"),
|
||||
"module": "TestNodeModule",
|
||||
"name": "TestNode1",
|
||||
"version": "1.2.3"
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}));
|
||||
|
||||
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" }));
|
||||
stubs.push(sinon.stub(registry,"addNodeSet", function(){ return }));
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
|
||||
loader.addModule("TestNodeModule").then(function(result) {
|
||||
result.should.eql("a node list");
|
||||
registry.addNodeSet.called.should.be.false();
|
||||
nodes.registerType.called.should.be.false();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('registers a message catalog');
|
||||
|
||||
|
||||
});
|
||||
describe("#loadNodeSet",function() {
|
||||
it("no-ops the load if node is not enabled", function(done) {
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.loadNodeSet({
|
||||
"file": path.join(resourcesDir,"TestNode1","TestNode1.js"),
|
||||
"module": "node-red",
|
||||
"name": "TestNode1",
|
||||
"enabled": false
|
||||
}).then(function(node) {
|
||||
node.enabled.should.be.false();
|
||||
nodes.registerType.called.should.be.false();
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("handles node that errors on require", function(done) {
|
||||
stubs.push(sinon.stub(nodes,"registerType"));
|
||||
loader.loadNodeSet({
|
||||
"file": path.join(resourcesDir,"TestNode4","TestNode4.js"),
|
||||
"module": "node-red",
|
||||
"name": "TestNode4",
|
||||
"enabled": true
|
||||
}).then(function(node) {
|
||||
node.enabled.should.be.true();
|
||||
nodes.registerType.called.should.be.false();
|
||||
node.should.have.property('err');
|
||||
node.err.toString().should.eql("Error: fail to require (line:1)");
|
||||
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("#getNodeHelp",function() {
|
||||
it("returns preloaded help", function() {
|
||||
loader.getNodeHelp({
|
||||
help:{
|
||||
en:"foo"
|
||||
}
|
||||
},"en").should.eql("foo");
|
||||
});
|
||||
it("loads help, caching result", function() {
|
||||
stubs.push(sinon.stub(fs,"readFileSync", function(path) {
|
||||
return 'bar';
|
||||
}))
|
||||
var node = {
|
||||
template: "/tmp/node/directory/file.html",
|
||||
help:{
|
||||
en:"foo"
|
||||
}
|
||||
};
|
||||
loader.getNodeHelp(node,"fr").should.eql("bar");
|
||||
node.help['fr'].should.eql("bar");
|
||||
fs.readFileSync.calledOnce.should.be.true();
|
||||
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html"));
|
||||
loader.getNodeHelp(node,"fr").should.eql("bar");
|
||||
fs.readFileSync.calledOnce.should.be.true();
|
||||
});
|
||||
it("loads help, defaulting to en-US content", function() {
|
||||
stubs.push(sinon.stub(fs,"readFileSync", function(path) {
|
||||
throw new Error("not found");
|
||||
}))
|
||||
var node = {
|
||||
template: "/tmp/node/directory/file.html",
|
||||
help:{}
|
||||
};
|
||||
node.help['en-US'] = 'foo';
|
||||
|
||||
loader.getNodeHelp(node,"fr").should.eql("foo");
|
||||
node.help['fr'].should.eql("foo");
|
||||
fs.readFileSync.calledOnce.should.be.true();
|
||||
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html"));
|
||||
loader.getNodeHelp(node,"fr").should.eql("foo");
|
||||
fs.readFileSync.calledOnce.should.be.true();
|
||||
});
|
||||
it("loads help, defaulting to en-US content for extra nodes", function() {
|
||||
stubs.push(sinon.stub(fs,"readFileSync", function(path) {
|
||||
if (path.indexOf("en-US") >= 0) {
|
||||
return 'bar';
|
||||
}
|
||||
throw new Error("not found");
|
||||
}));
|
||||
var node = {
|
||||
template: "/tmp/node/directory/file.html",
|
||||
help:{}
|
||||
};
|
||||
delete node.help['en-US'];
|
||||
|
||||
loader.getNodeHelp(node,"fr").should.eql("bar");
|
||||
node.help['fr'].should.eql("bar");
|
||||
fs.readFileSync.calledTwice.should.be.true();
|
||||
fs.readFileSync.firstCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html"));
|
||||
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en-US/file.html"));
|
||||
loader.getNodeHelp(node,"fr").should.eql("bar");
|
||||
fs.readFileSync.calledTwice.should.be.true();
|
||||
});
|
||||
it("fails to load en-US help content", function() {
|
||||
stubs.push(sinon.stub(fs,"readFileSync", function(path) {
|
||||
throw new Error("not found");
|
||||
}));
|
||||
var node = {
|
||||
template: "/tmp/node/directory/file.html",
|
||||
help:{}
|
||||
};
|
||||
delete node.help['en-US'];
|
||||
|
||||
should.not.exist(loader.getNodeHelp(node,"en-US"));
|
||||
should.not.exist(node.help['en-US']);
|
||||
fs.readFileSync.calledTwice.should.be.true();
|
||||
fs.readFileSync.firstCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en-US/file.html"));
|
||||
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en/file.html"));
|
||||
should.not.exist(loader.getNodeHelp(node,"en-US"));
|
||||
fs.readFileSync.callCount.should.eql(4);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
@@ -1,261 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
var localfilesystem = require("../../../../../red/runtime/nodes/registry/localfilesystem");
|
||||
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","local"));
|
||||
var userDir = path.resolve(path.join(__dirname,"..","resources","userDir"));
|
||||
var moduleDir = path.resolve(path.join(__dirname,"..","resources","local","TestNodeModule"));
|
||||
|
||||
describe("red/nodes/registry/localfilesystem",function() {
|
||||
var stubs = [];
|
||||
afterEach(function() {
|
||||
while(stubs.length) {
|
||||
stubs.pop().restore();
|
||||
}
|
||||
})
|
||||
function checkNodes(nodes,shouldHaveNodes,shouldNotHaveNodes,module) {
|
||||
for (var i=0;i<shouldHaveNodes.length;i++) {
|
||||
nodes.should.have.a.property(shouldHaveNodes[i]);
|
||||
nodes[shouldHaveNodes[i]].should.have.a.property('file');
|
||||
nodes[shouldHaveNodes[i]].file.should.equal(path.resolve(nodes[shouldHaveNodes[i]].file));
|
||||
nodes[shouldHaveNodes[i]].should.have.a.property('module',module||'node-red');
|
||||
nodes[shouldHaveNodes[i]].should.have.a.property('name',shouldHaveNodes[i]);
|
||||
}
|
||||
for (i=0;i<shouldNotHaveNodes.length;i++) {
|
||||
nodes.should.not.have.a.property(shouldNotHaveNodes[i]);
|
||||
}
|
||||
}
|
||||
describe("#getNodeFiles",function() {
|
||||
it("Finds all the node files in the resources tree",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:resourcesDir}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
var nodes = nm.nodes;
|
||||
checkNodes(nm.nodes,['TestNode1','MultipleNodes1','NestedNode','TestNode2','TestNode3','TestNode4'],['TestNodeModule']);
|
||||
done();
|
||||
});
|
||||
it("Includes node files from settings",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesIncludes:['TestNode1.js'],coreNodesDir:resourcesDir}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNode1'],['MultipleNodes1','NestedNode','TestNode2','TestNode3','TestNode4','TestNodeModule']);
|
||||
done();
|
||||
});
|
||||
it("Excludes node files from settings",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js'],coreNodesDir:resourcesDir}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['MultipleNodes1','NestedNode','TestNode2','TestNode3','TestNode4'],['TestNode1','TestNodeModule']);
|
||||
done();
|
||||
});
|
||||
it("Finds nodes in userDir/nodes",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{userDir:userDir,coreNodesDir:__dirname}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
|
||||
done();
|
||||
});
|
||||
|
||||
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:userDir,coreNodesDir:__dirname}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
|
||||
done();
|
||||
});
|
||||
it("Finds nodes in settings.nodesDir (string,relative path)",function(done) {
|
||||
var relativeUserDir = path.join("test","red","runtime","nodes","resources","userDir");
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:relativeUserDir,coreNodesDir:__dirname}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
|
||||
done();
|
||||
});
|
||||
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir],coreNodesDir:__dirname}});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNode5'],['TestNode1']);
|
||||
done();
|
||||
});
|
||||
it("Finds nodes module path",function(done) {
|
||||
var _join = path.join;
|
||||
stubs.push(sinon.stub(path,"join",function() {
|
||||
if (arguments[0] == resourcesDir) {
|
||||
// This stops the module tree scan from going any higher
|
||||
// up the tree than resourcesDir.
|
||||
return arguments[0];
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||
var nodeList = localfilesystem.getNodeFiles();
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
nm.should.have.a.property('name','node-red');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,[],['TestNode1']);
|
||||
|
||||
nm = nodeList['TestNodeModule'];
|
||||
nm.should.have.a.property('name','TestNodeModule');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['TestNodeMod1','TestNodeMod2'],[],'TestNodeModule');
|
||||
|
||||
nm = nodeList['VersionMismatchModule'];
|
||||
nm.should.have.a.property('name','VersionMismatchModule');
|
||||
nm.should.have.a.property("nodes");
|
||||
checkNodes(nm.nodes,['VersionMismatchMod1','VersionMismatchMod2'],[],'VersionMismatchModule');
|
||||
|
||||
done();
|
||||
});
|
||||
it.skip("finds locales directory");
|
||||
it.skip("finds icon path directory");
|
||||
it("scans icon files in the resources tree",function(done) {
|
||||
var count = 0;
|
||||
localfilesystem.init({
|
||||
i18n:{registerMessageCatalog:function(){}},
|
||||
events:{emit:function(eventName,dir){
|
||||
if (count === 0) {
|
||||
eventName.should.equal("node-icon-dir");
|
||||
dir.name.should.equal("node-red");
|
||||
dir.icons.should.be.an.Array();
|
||||
count = 1;
|
||||
} else if (count === 1) {
|
||||
done();
|
||||
}
|
||||
}},
|
||||
settings:{coreNodesDir:resourcesDir}
|
||||
});
|
||||
localfilesystem.getNodeFiles(true);
|
||||
});
|
||||
it("scans icons dir in library",function(done) {
|
||||
var count = 0;
|
||||
localfilesystem.init({
|
||||
i18n:{registerMessageCatalog:function(){}},
|
||||
events:{emit:function(eventName,dir){
|
||||
eventName.should.equal("node-icon-dir");
|
||||
if (count === 0) {
|
||||
dir.name.should.equal("node-red");
|
||||
dir.icons.should.be.an.Array();
|
||||
count = 1;
|
||||
} else if (count === 1) {
|
||||
dir.name.should.equal("Library");
|
||||
dir.icons.should.be.an.Array();
|
||||
dir.icons.length.should.equal(1);
|
||||
dir.icons[0].should.be.equal("test_icon.png");
|
||||
done();
|
||||
}
|
||||
}},
|
||||
settings:{userDir:userDir}
|
||||
});
|
||||
localfilesystem.getNodeFiles(true);
|
||||
});
|
||||
});
|
||||
describe("#getModuleFiles",function() {
|
||||
it("gets a nodes module files",function(done) {
|
||||
var _join = path.join;
|
||||
stubs.push(sinon.stub(path,"join",function() {
|
||||
if (arguments[0] == resourcesDir) {
|
||||
// This stops the module tree scan from going any higher
|
||||
// up the tree than resourcesDir.
|
||||
return arguments[0];
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||
nodeModule.should.have.a.property('TestNodeModule');
|
||||
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
||||
nodeModule['TestNodeModule'].should.have.a.property('version','0.0.1');
|
||||
nodeModule['TestNodeModule'].should.have.a.property('nodes');
|
||||
checkNodes(nodeModule['TestNodeModule'].nodes,['TestNodeMod1','TestNodeMod2'],[],'TestNodeModule');
|
||||
|
||||
nodeModule = localfilesystem.getModuleFiles('VersionMismatchModule');
|
||||
nodeModule.should.have.a.property('VersionMismatchModule');
|
||||
nodeModule['VersionMismatchModule'].should.have.a.property('redVersion','100.0.0');
|
||||
|
||||
done();
|
||||
});
|
||||
it("throws an error if a node isn't found",function(done) {
|
||||
var _join = path.join;
|
||||
stubs.push(sinon.stub(path,"join",function() {
|
||||
if (arguments[0] == resourcesDir) {
|
||||
// This stops the module tree scan from going any higher
|
||||
// up the tree than resourcesDir.
|
||||
return arguments[0];
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{coreNodesDir:moduleDir}});
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
localfilesystem.getModuleFiles('WontExistModule');
|
||||
}).should.throw();
|
||||
done();
|
||||
});
|
||||
it.skip("finds locales directory");
|
||||
it.skip("finds icon path directory");
|
||||
it("scans icon files with a module file",function(done) {
|
||||
var _join = path.join;
|
||||
stubs.push(sinon.stub(path,"join",function() {
|
||||
if (arguments[0] == resourcesDir) {
|
||||
// This stops the module tree scan from going any higher
|
||||
// up the tree than resourcesDir.
|
||||
return arguments[0];
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({
|
||||
i18n:{registerMessageCatalog:function(){}},
|
||||
events:{emit:function(eventName,dir){
|
||||
eventName.should.equal("node-icon-dir");
|
||||
dir.name.should.equal("TestNodeModule");
|
||||
dir.icons.should.be.an.Array();
|
||||
done();
|
||||
}},
|
||||
settings:{coreNodesDir:moduleDir}
|
||||
});
|
||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,568 +0,0 @@
|
||||
/**
|
||||
* Copyright JS Foundation and other contributors, http://js.foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
var typeRegistry = require("../../../../../red/runtime/nodes/registry/registry");
|
||||
|
||||
var Node = require("../../../../../red/runtime/nodes/Node");
|
||||
|
||||
var events = require("../../../../../red/runtime/events");
|
||||
|
||||
var inherits = require("util").inherits;
|
||||
|
||||
describe("red/nodes/registry/registry",function() {
|
||||
|
||||
afterEach(function() {
|
||||
typeRegistry.clear();
|
||||
});
|
||||
|
||||
function stubSettings(s,available,initialConfig) {
|
||||
s.available = function() {return available;};
|
||||
s.set = sinon.spy(function(s,v) { return when.resolve();});
|
||||
s.get = function(s) { return initialConfig;};
|
||||
return s;
|
||||
}
|
||||
|
||||
var settings = stubSettings({},false,null);
|
||||
var settingsWithStorageAndInitialConfig = stubSettings({},true,{"node-red":{module:"testModule",name:"testName",version:"testVersion",nodes:{"node":{id:"node-red/testName",name:"test",types:["a","b"],enabled:true}}}});
|
||||
|
||||
var testNodeSet1 = {
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"]
|
||||
};
|
||||
|
||||
var testNodeSet2 = {
|
||||
id: "test-module/test-name-2",
|
||||
module: "test-module",
|
||||
name: "test-name-2",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configB",
|
||||
types: [ "test-c","test-d"]
|
||||
};
|
||||
var testNodeSet2WithError = {
|
||||
id: "test-module/test-name-2",
|
||||
module: "test-module",
|
||||
name: "test-name-2",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
err: "I have an error",
|
||||
config: "configC",
|
||||
types: [ "test-c","test-d"]
|
||||
};
|
||||
var testNodeSet3 = {
|
||||
id: "test-module-2/test-name-3",
|
||||
module: "test-module-2",
|
||||
name: "test-name-3",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configB",
|
||||
types: [ "test-a","test-e"]
|
||||
};
|
||||
|
||||
|
||||
|
||||
describe('#init/load', function() {
|
||||
it('loads initial config', function(done) {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.load();
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
done();
|
||||
});
|
||||
|
||||
it('migrates legacy format', function(done) {
|
||||
var legacySettings = {
|
||||
available: function() { return true; },
|
||||
set: sinon.stub().returns(when.resolve()),
|
||||
get: function() { return {
|
||||
"123": {
|
||||
"name": "72-sentiment.js",
|
||||
"types": [
|
||||
"sentiment"
|
||||
],
|
||||
"enabled": true
|
||||
},
|
||||
"456": {
|
||||
"name": "20-inject.js",
|
||||
"types": [
|
||||
"inject"
|
||||
],
|
||||
"enabled": true
|
||||
},
|
||||
"789": {
|
||||
"name": "testModule:a-module.js",
|
||||
"types": [
|
||||
"example"
|
||||
],
|
||||
"enabled":true,
|
||||
"module":"testModule"
|
||||
}
|
||||
}}
|
||||
};
|
||||
var expected = JSON.parse('{"node-red":{"name":"node-red","nodes":{"sentiment":{"name":"sentiment","types":["sentiment"],"enabled":true,"module":"node-red"},"inject":{"name":"inject","types":["inject"],"enabled":true,"module":"node-red"}}},"testModule":{"name":"testModule","nodes":{"a-module.js":{"name":"a-module.js","types":["example"],"enabled":true,"module":"testModule"}}}}');
|
||||
typeRegistry.init(legacySettings);
|
||||
typeRegistry.load();
|
||||
legacySettings.set.calledOnce.should.be.true();
|
||||
legacySettings.set.args[0][1].should.eql(expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#addNodeSet', function() {
|
||||
it('adds a node set for an unknown module', function() {
|
||||
|
||||
typeRegistry.init(settings);
|
||||
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
var moduleList = typeRegistry.getModuleList();
|
||||
moduleList.should.have.a.property("test-module");
|
||||
moduleList["test-module"].should.have.a.property("name","test-module");
|
||||
moduleList["test-module"].should.have.a.property("version","0.0.1");
|
||||
moduleList["test-module"].should.have.a.property("nodes");
|
||||
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
||||
|
||||
moduleList["test-module"].nodes["test-name"].should.eql({
|
||||
config: 'configA',
|
||||
id: 'test-module/test-name',
|
||||
module: 'test-module',
|
||||
name: 'test-name',
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
types: [ 'test-a', 'test-b' ]
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('adds a node set to an existing module', function() {
|
||||
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
var moduleList = typeRegistry.getModuleList();
|
||||
Object.keys(moduleList).should.have.a.lengthOf(1);
|
||||
moduleList.should.have.a.property("test-module");
|
||||
moduleList["test-module"].should.have.a.property("name","test-module");
|
||||
moduleList["test-module"].should.have.a.property("version","0.0.1");
|
||||
moduleList["test-module"].should.have.a.property("nodes");
|
||||
|
||||
Object.keys(moduleList["test-module"].nodes).should.have.a.lengthOf(1);
|
||||
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
||||
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2);
|
||||
|
||||
typeRegistry.getNodeList().should.have.lengthOf(2);
|
||||
moduleList = typeRegistry.getModuleList();
|
||||
Object.keys(moduleList).should.have.a.lengthOf(1);
|
||||
Object.keys(moduleList["test-module"].nodes).should.have.a.lengthOf(2);
|
||||
moduleList["test-module"].nodes.should.have.a.property("test-name");
|
||||
moduleList["test-module"].nodes.should.have.a.property("test-name-2");
|
||||
});
|
||||
|
||||
it('doesnt add node set types if node set has an error', function() {
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
|
||||
typeRegistry.getTypeId("test-a").should.eql("test-module/test-name");
|
||||
|
||||
should.not.exist(typeRegistry.getTypeId("test-c"));
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
||||
|
||||
should.not.exist(typeRegistry.getTypeId("test-c"));
|
||||
});
|
||||
|
||||
it('doesnt add node set if type already exists', function() {
|
||||
typeRegistry.init(settings);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
should.not.exist(typeRegistry.getTypeId("test-e"));
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
should.exist(typeRegistry.getTypeId("test-a"));
|
||||
typeRegistry.addNodeSet(testNodeSet3.id,testNodeSet3, "0.0.1");
|
||||
typeRegistry.getNodeList().should.have.lengthOf(2);
|
||||
|
||||
// testNodeSet3 registers a duplicate test-a and unique test-e
|
||||
// as test-a is a duplicate, test-e should not get registered
|
||||
should.not.exist(typeRegistry.getTypeId("test-e"));
|
||||
|
||||
var testNodeSet3Result = typeRegistry.getNodeList()[1];
|
||||
should.exist(testNodeSet3Result.err);
|
||||
testNodeSet3Result.err.code.should.equal("type_already_registered");
|
||||
testNodeSet3Result.err.details.type.should.equal("test-a");
|
||||
testNodeSet3Result.err.details.moduleA.should.equal("test-module");
|
||||
testNodeSet3Result.err.details.moduleB.should.equal("test-module-2");
|
||||
|
||||
//
|
||||
// typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
||||
//
|
||||
// should.not.exist(typeRegistry.getTypeId("test-c"));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe("#enableNodeSet", function() {
|
||||
it('throws error if settings unavailable', function() {
|
||||
typeRegistry.init(settings);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.enableNodeSet("test-module/test-name");
|
||||
}).should.throw("Settings unavailable");
|
||||
});
|
||||
|
||||
it('throws error if module unknown', function() {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.enableNodeSet("test-module/unknown");
|
||||
}).should.throw("Unrecognised id: test-module/unknown");
|
||||
});
|
||||
it.skip('enables the node',function(){})
|
||||
|
||||
});
|
||||
describe("#disableNodeSet", function() {
|
||||
it('throws error if settings unavailable', function() {
|
||||
typeRegistry.init(settings);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.disableNodeSet("test-module/test-name");
|
||||
}).should.throw("Settings unavailable");
|
||||
});
|
||||
|
||||
it('throws error if module unknown', function() {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.disableNodeSet("test-module/unknown");
|
||||
}).should.throw("Unrecognised id: test-module/unknown");
|
||||
});
|
||||
it.skip('disables the node',function(){})
|
||||
});
|
||||
|
||||
describe('#getNodeConfig', function() {
|
||||
it('returns nothing for an unregistered type config', function(done) {
|
||||
typeRegistry.init(settings);
|
||||
var config = typeRegistry.getNodeConfig("imaginary-shark");
|
||||
(config === null).should.be.true();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#saveNodeList',function() {
|
||||
it('rejects when settings unavailable',function(done) {
|
||||
typeRegistry.init(stubSettings({},false,{}));
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
typeRegistry.saveNodeList().catch(function(err) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('saves the list',function(done) {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s);
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
typeRegistry.addNodeSet("test-module/test-name-2",testNodeSet2WithError, "0.0.1");
|
||||
typeRegistry.saveNodeList().then(function() {
|
||||
s.set.called.should.be.true();
|
||||
s.set.lastCall.args[0].should.eql('nodes');
|
||||
var nodes = s.set.lastCall.args[1];
|
||||
nodes.should.have.property('test-module');
|
||||
for (var n in nodes['test-module'].nodes) {
|
||||
var nn = nodes['test-module'].nodes[n];
|
||||
nn.should.not.have.property('err');
|
||||
nn.should.not.have.property('id');
|
||||
}
|
||||
done();
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeModule',function() {
|
||||
it('throws error for unknown module', function() {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.removeModule("test-module/unknown");
|
||||
}).should.throw("Unrecognised module: test-module/unknown");
|
||||
});
|
||||
it('throws error for unavaiable settings', function() {
|
||||
var s = stubSettings({},false,{});
|
||||
typeRegistry.init(s);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.removeModule("test-module/unknown");
|
||||
}).should.throw("Settings unavailable");
|
||||
});
|
||||
it('removes a known module', function() {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s);
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1, "0.0.1");
|
||||
var moduleList = typeRegistry.getModuleList();
|
||||
moduleList.should.have.a.property("test-module");
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
|
||||
var info = typeRegistry.removeModule('test-module');
|
||||
moduleList = typeRegistry.getModuleList();
|
||||
moduleList.should.not.have.a.property("test-module");
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#get[All]NodeConfigs', function() {
|
||||
it('returns node config', function() {
|
||||
typeRegistry.init(settings,{
|
||||
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
|
||||
});
|
||||
typeRegistry.addNodeSet("test-module/test-name",{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"]
|
||||
}, "0.0.1");
|
||||
typeRegistry.getNodeConfig("test-module/test-name").should.eql('configAHEtest-nameLP');
|
||||
typeRegistry.getAllNodeConfigs().should.eql('configAHEtest-nameLP');
|
||||
|
||||
typeRegistry.addNodeSet("test-module/test-name-2",{
|
||||
id: "test-module/test-name-2",
|
||||
module: "test-module",
|
||||
name: "test-name-2",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configB",
|
||||
types: [ "test-c","test-d"]
|
||||
}, "0.0.1");
|
||||
typeRegistry.getNodeConfig("test-module/test-name-2").should.eql('configBHEtest-name-2LP');
|
||||
typeRegistry.getAllNodeConfigs().should.eql('configAHEtest-nameLPconfigBHEtest-name-2LP');
|
||||
});
|
||||
});
|
||||
describe('#getModuleInfo', function() {
|
||||
it('returns module info', function() {
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addNodeSet("test-module/test-name",{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"],
|
||||
file: "abc"
|
||||
}, "0.0.1");
|
||||
var moduleInfo = typeRegistry.getModuleInfo("test-module");
|
||||
moduleInfo.should.have.a.property('name','test-module');
|
||||
moduleInfo.should.have.a.property('version','0.0.1');
|
||||
moduleInfo.should.have.a.property('nodes');
|
||||
moduleInfo.nodes.should.have.a.lengthOf(1);
|
||||
moduleInfo.nodes[0].should.have.a.property('id','test-module/test-name');
|
||||
moduleInfo.nodes[0].should.not.have.a.property('file');
|
||||
});
|
||||
});
|
||||
describe('#getNodeInfo', function() {
|
||||
it('returns node info', function() {
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addNodeSet("test-module/test-name",{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"],
|
||||
file: "abc"
|
||||
}, "0.0.1");
|
||||
var nodeSetInfo = typeRegistry.getNodeInfo("test-module/test-name");
|
||||
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
||||
nodeSetInfo.should.not.have.a.property('config');
|
||||
nodeSetInfo.should.not.have.a.property('file');
|
||||
});
|
||||
});
|
||||
describe('#getFullNodeInfo', function() {
|
||||
it('returns node info', function() {
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addNodeSet("test-module/test-name",{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"],
|
||||
file: "abc"
|
||||
|
||||
}, "0.0.1");
|
||||
var nodeSetInfo = typeRegistry.getFullNodeInfo("test-module/test-name");
|
||||
nodeSetInfo.should.have.a.property('id',"test-module/test-name");
|
||||
nodeSetInfo.should.have.a.property('config');
|
||||
nodeSetInfo.should.have.a.property('file');
|
||||
});
|
||||
});
|
||||
describe('#cleanModuleList', function() {
|
||||
it.skip("cleans the module list");
|
||||
});
|
||||
describe('#getNodeList', function() {
|
||||
it("returns a filtered list", function() {
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addNodeSet("test-module/test-name",{
|
||||
id: "test-module/test-name",
|
||||
module: "test-module",
|
||||
name: "test-name",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configA",
|
||||
types: [ "test-a","test-b"],
|
||||
file: "abc"
|
||||
}, "0.0.1");
|
||||
typeRegistry.addNodeSet("test-module/test-name-2",{
|
||||
id: "test-module/test-name-2",
|
||||
module: "test-module",
|
||||
name: "test-name-2",
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configB",
|
||||
types: [ "test-c","test-d"],
|
||||
file: "def"
|
||||
}, "0.0.1");
|
||||
var filterCallCount = 0;
|
||||
var filteredList = typeRegistry.getNodeList(function(n) { filterCallCount++; return n.name === 'test-name-2';});
|
||||
filterCallCount.should.eql(2);
|
||||
filteredList.should.have.a.lengthOf(1);
|
||||
filteredList[0].should.have.a.property('id',"test-module/test-name-2");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#registerNodeConstructor', function() {
|
||||
var TestNodeConstructor;
|
||||
beforeEach(function() {
|
||||
TestNodeConstructor = function TestNodeConstructor() {
|
||||
};
|
||||
sinon.stub(events,'emit');
|
||||
});
|
||||
afterEach(function() {
|
||||
events.emit.restore();
|
||||
});
|
||||
it('registers a node constructor', function() {
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
||||
events.emit.calledOnce.should.be.true();
|
||||
events.emit.lastCall.args[0].should.eql('type-registered');
|
||||
events.emit.lastCall.args[1].should.eql('node-type');
|
||||
})
|
||||
it('throws error on duplicate node registration', function() {
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
||||
events.emit.calledOnce.should.be.true();
|
||||
events.emit.lastCall.args[0].should.eql('type-registered');
|
||||
events.emit.lastCall.args[1].should.eql('node-type');
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
||||
}).should.throw("node-type already registered");
|
||||
events.emit.calledOnce.should.be.true();
|
||||
});
|
||||
it('extends a constructor with the Node constructor', function() {
|
||||
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
});
|
||||
it('does not override a constructor\'s prototype', function() {
|
||||
function Foo(){};
|
||||
inherits(TestNodeConstructor,Foo);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
TestNodeConstructor.prototype.should.not.be.an.instanceOf(Node);
|
||||
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type',TestNodeConstructor);
|
||||
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
|
||||
typeRegistry.registerNodeConstructor('node-set','node-type2',TestNodeConstructor);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Node);
|
||||
TestNodeConstructor.prototype.should.be.an.instanceOf(Foo);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getNodeIconPath', function() {
|
||||
it('returns the default icon when getting an unknown icon', function() {
|
||||
var defaultIcon = path.resolve(__dirname+'/../../../../../public/icons/arrow-in.png');
|
||||
var iconPath = typeRegistry.getNodeIconPath('random-module','youwonthaveme.png');
|
||||
iconPath.should.eql(defaultIcon);
|
||||
});
|
||||
|
||||
it('returns a registered icon' , function() {
|
||||
var testIcon = path.resolve(__dirname+'/../../../../resources/icons/test_icon.png');
|
||||
events.emit("node-icon-dir",{name:"test-module", path: path.resolve(__dirname+'/../../../../resources/icons'), icons:[]});
|
||||
var iconPath = typeRegistry.getNodeIconPath('test-module','test_icon.png');
|
||||
iconPath.should.eql(testIcon);
|
||||
});
|
||||
|
||||
it('returns the debug icon when getting an unknown module', function() {
|
||||
var debugIcon = path.resolve(__dirname+'/../../../../../public/icons/debug.png');
|
||||
var iconPath = typeRegistry.getNodeIconPath('unknown-module', 'debug.png');
|
||||
iconPath.should.eql(debugIcon);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getNodeIcons', function() {
|
||||
it('returns empty icon list when no modules are registered', function() {
|
||||
var iconList = typeRegistry.getNodeIcons();
|
||||
iconList.should.eql({});
|
||||
});
|
||||
|
||||
it('returns an icon list of registered node module', function() {
|
||||
typeRegistry.addNodeSet("test-module/test-name",testNodeSet1,"0.0.1");
|
||||
events.emit("node-icon-dir",{name:"test-module", path:"",icons:["test_icon1.png"]});
|
||||
var iconList = typeRegistry.getNodeIcons();
|
||||
iconList.should.eql({"test-module":["test_icon1.png"]});
|
||||
});
|
||||
|
||||
it('returns an icon list of unregistered node module', function() {
|
||||
events.emit("node-icon-dir",{name:"test-module", path:"", icons:["test_icon1.png", "test_icon2.png"]});
|
||||
var iconList = typeRegistry.getNodeIcons();
|
||||
iconList.should.eql({"test-module":["test_icon1.png","test_icon2.png"]});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function DuffNode(n) {}
|
||||
RED.nodes.registerType("duff-node",DuffNode);
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-1"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-1',{});</script>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function DuplicateTestNode(n) {}
|
||||
RED.nodes.registerType("test-node-1",DuplicateTestNode);
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-multiple-1a"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-multiple-1a"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-multiple-1a',{});</script>
|
||||
<script type="text/x-red" data-template-name="test-node-multiple-1b"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-multiple-1b"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-multiple-1b',{});</script>
|
@@ -1,7 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode1(n) {}
|
||||
RED.nodes.registerType("test-node-multiple-1a",TestNode1);
|
||||
function TestNode2(n) {}
|
||||
RED.nodes.registerType("test-node-multiple-1b",TestNode2);
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="nested-node-1"></script>
|
||||
<script type="text/x-red" data-help-name="nested-node-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('nested-node-1',{});</script>
|
||||
<style></style>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("nested-node-1",TestNode);
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
This file exists just to ensure the 'icons' directory is in the repository.
|
||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
||||
directory can be used for that
|
@@ -1,4 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="should-not-load-1"></script>
|
||||
<script type="text/x-red" data-help-name="should-not-load-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('should-not-load-1',{});</script>
|
||||
<style></style>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("should-not-load-1",TestNode);
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="should-not-load-3"></script>
|
||||
<script type="text/x-red" data-help-name="should-not-load-3"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('should-not-load-3',{});</script>
|
||||
<style></style>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("should-not-load-3",TestNode);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-1"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-1',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-1",TestNode);
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-2"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-2"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-2',{});</script>
|
||||
<style></style>
|
@@ -1,10 +0,0 @@
|
||||
// A test node that exports a function which returns a resolving promise
|
||||
|
||||
var when = require("when");
|
||||
module.exports = function(RED) {
|
||||
return when.promise(function(resolve,reject) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-2",TestNode);
|
||||
resolve();
|
||||
});
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-3"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-3"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-3',{});</script>
|
@@ -1,8 +0,0 @@
|
||||
// A test node that exports a function which returns a rejecting promise
|
||||
|
||||
var when = require("when");
|
||||
module.exports = function(RED) {
|
||||
return when.promise(function(resolve,reject) {
|
||||
reject("fail");
|
||||
});
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-3"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-3"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-3',{});</script>
|
@@ -1 +0,0 @@
|
||||
throw new Error("fail to require");
|
@@ -1 +0,0 @@
|
||||
This file exists just to ensure the parent directory is in the repository.
|
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-mod-1"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-mod-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-mod-1',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-mod-1",TestNode);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-mod-2"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-mod-2"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-mod-2',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1,4 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
throw new Error("fail to load");
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
This file exists just to ensure the 'icons' directory is in the repository.
|
||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
||||
directory can be used for that
|
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name" : "TestNodeModule",
|
||||
"version" : "0.0.1",
|
||||
"description" : "A test node module",
|
||||
"node-red" : {
|
||||
"nodes": {
|
||||
"TestNodeMod1": "TestNodeModule.js",
|
||||
"TestNodeMod2": "TestNodeModule2.js"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-mod-1"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-mod-1"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-mod-1',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1,5 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-mod-1",TestNode);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-mod-2"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-mod-2"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-mod-2',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1,4 +0,0 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
throw new Error("fail to load");
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
This file exists just to ensure the 'icons' directory is in the repository.
|
||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
||||
directory can be used for that
|
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name" : "VersionMismatchModule",
|
||||
"version" : "0.0.1",
|
||||
"description" : "A test node module",
|
||||
"node-red" : {
|
||||
"version": "100.0.0",
|
||||
"nodes": {
|
||||
"VersionMismatchMod1": "TestNodeModule.js",
|
||||
"VersionMismatchMod2": "TestNodeModule2.js"
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 163 B |
@@ -1,5 +0,0 @@
|
||||
<script type="text/x-red" data-template-name="test-node-5"></script>
|
||||
<script type="text/x-red" data-help-name="test-node-5"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('test-node-5',{});</script>
|
||||
<style></style>
|
||||
<p>this should be filtered out</p>
|
@@ -1 +0,0 @@
|
||||
throw new Error("fail to require");
|
Reference in New Issue
Block a user