mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix error message for missing node html file, and add test.
To close #1053
This commit is contained in:
parent
d042169f2e
commit
74f2180fa4
@ -87,10 +87,10 @@ function createNodeApi(node) {
|
||||
red.server = runtime.adminApi.server;
|
||||
} else {
|
||||
red.comms = {
|
||||
publish: function(){}
|
||||
publish: function() {}
|
||||
};
|
||||
red.library = {
|
||||
register: function(){}
|
||||
register: function() {}
|
||||
};
|
||||
red.auth = {
|
||||
needsPermission: function() {}
|
||||
@ -203,7 +203,7 @@ function loadNodeConfig(fileInfo) {
|
||||
if (!node.types) {
|
||||
node.types = [];
|
||||
}
|
||||
node.err = "Error: "+file+" does not exist";
|
||||
node.err = "Error: "+node.template+" does not exist";
|
||||
} else {
|
||||
node.types = [];
|
||||
node.err = err.toString();
|
||||
@ -215,7 +215,7 @@ function loadNodeConfig(fileInfo) {
|
||||
var regExp = /<script ([^>]*)data-template-name=['"]([^'"]*)['"]/gi;
|
||||
var match = null;
|
||||
|
||||
while((match = regExp.exec(content)) !== null) {
|
||||
while ((match = regExp.exec(content)) !== null) {
|
||||
types.push(match[2]);
|
||||
}
|
||||
node.types = types;
|
||||
@ -226,7 +226,7 @@ function loadNodeConfig(fileInfo) {
|
||||
var mainContent = "";
|
||||
var helpContent = {};
|
||||
var index = 0;
|
||||
while((match = regExp.exec(content)) !== null) {
|
||||
while ((match = regExp.exec(content)) !== null) {
|
||||
mainContent += content.substring(index,regExp.lastIndex-match[1].length);
|
||||
index = regExp.lastIndex;
|
||||
var help = content.substring(regExp.lastIndex-match[1].length,regExp.lastIndex);
|
||||
@ -382,7 +382,6 @@ function getNodeHelp(node,lang) {
|
||||
} else {
|
||||
node.help[lang] = node.help[runtime.i18n.defaultLang];
|
||||
}
|
||||
|
||||
}
|
||||
return node.help[lang];
|
||||
}
|
||||
|
@ -317,6 +317,53 @@ describe("red/nodes/registry/loader",function() {
|
||||
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();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#addModule",function() {
|
||||
|
@ -0,0 +1,5 @@
|
||||
// A test node that exports a function
|
||||
module.exports = function(RED) {
|
||||
function DuffNode(n) {}
|
||||
RED.nodes.registerType("duff-node",DuffNode);
|
||||
}
|
Loading…
Reference in New Issue
Block a user