mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add loadNode api to registry.js
This commit is contained in:
@@ -277,4 +277,50 @@ describe('NodeRegistry', function() {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('allows nodes to be added', function(done) {
|
||||
typeRegistry.init({});
|
||||
typeRegistry.load("wontexist").then(function(){
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.be.empty;
|
||||
|
||||
typeRegistry.loadNode(__dirname+"/resources/TestNode1/TestNode1.js").then(function(node) {
|
||||
list = typeRegistry.getNodeList();
|
||||
list[0].should.have.property("id");
|
||||
list[0].should.have.property("name","TestNode1.js");
|
||||
list[0].should.have.property("types",["test-node-1"]);
|
||||
list[0].should.have.property("enabled",true);
|
||||
list[0].should.not.have.property("err");
|
||||
|
||||
node.should.eql(list[0]);
|
||||
|
||||
done();
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects adding duplicate nodes', function(done) {
|
||||
typeRegistry.init({});
|
||||
typeRegistry.load(__dirname+"/resources/TestNode1").then(function(){
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
|
||||
typeRegistry.loadNode(__dirname+"/resources/TestNode1/TestNode1.js").then(function(node) {
|
||||
done(new Error("duplicate node loaded"));
|
||||
}).otherwise(function(e) {
|
||||
var list = typeRegistry.getNodeList();
|
||||
list.should.be.an.Array.and.have.lengthOf(1);
|
||||
done();
|
||||
});
|
||||
|
||||
}).catch(function(e) {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -0,0 +1,4 @@
|
||||
<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>
|
@@ -0,0 +1,5 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("should-not-load-1",TestNode);
|
||||
}
|
4
test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html
generated
vendored
Normal file
4
test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.html
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
<script type="text/x-red" data-template-name="should-not-load-2"></script>
|
||||
<script type="text/x-red" data-help-name="should-not-load-2"></script>
|
||||
<script type="text/javascript">RED.nodes.registerType('should-not-load-2',{});</script>
|
||||
<style></style>
|
5
test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js
generated
vendored
Normal file
5
test/red/nodes/resources/NestedDirectoryNode/NestedNode/node_modules/ShouldNotLoad.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("should-not-load-2",TestNode);
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
<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>
|
@@ -0,0 +1,5 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("should-not-load-3",TestNode);
|
||||
}
|
@@ -2,3 +2,4 @@
|
||||
<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>
|
||||
|
Reference in New Issue
Block a user