mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch '0.18' into projects
This commit is contained in:
@@ -50,6 +50,7 @@ describe("api/admin/nodes", function() {
|
||||
app.get(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.getSet);
|
||||
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.putModule);
|
||||
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet);
|
||||
app.get("/getIcons",nodes.getIcons);
|
||||
app.delete("/nodes/:id",nodes.delete);
|
||||
sinon.stub(apiUtil,"determineLangFromHeaders", function() {
|
||||
return "en-US";
|
||||
@@ -810,5 +811,29 @@ describe("api/admin/nodes", function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('get icons', function() {
|
||||
it('returns icon list', function(done) {
|
||||
debugger;
|
||||
initNodes({
|
||||
nodes:{
|
||||
getNodeIcons: function() {
|
||||
return {"module":["1.png","2.png","3.png"]};
|
||||
}
|
||||
}
|
||||
});
|
||||
request(app)
|
||||
.get('/getIcons')
|
||||
.expect(200)
|
||||
.end(function(err,res) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
console.log(res.body);
|
||||
res.body.should.have.property("module");
|
||||
res.body.module.should.be.an.Array();
|
||||
res.body.module.should.have.lengthOf(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -31,6 +31,13 @@ var address = '127.0.0.1';
|
||||
var listenPort = 0; // use ephemeral port
|
||||
|
||||
describe("api/editor/comms", function() {
|
||||
|
||||
beforeEach(function (done) {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 55);
|
||||
});
|
||||
|
||||
describe("with default keepalive", function() {
|
||||
var server;
|
||||
var url;
|
||||
@@ -72,7 +79,7 @@ describe("api/editor/comms", function() {
|
||||
comms.publish('topic1', 'foo');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic1","data":"foo"}');
|
||||
msg.should.equal('[{"topic":"topic1","data":"foo"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -85,7 +92,8 @@ describe("api/editor/comms", function() {
|
||||
ws.send('{"subscribe":"topic2"}');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic2","data":"bar"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic2","data":"bar"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -100,7 +108,8 @@ describe("api/editor/comms", function() {
|
||||
comms.publish('topic3', 'new');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic3","data":"new"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic3","data":"new"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -115,7 +124,8 @@ describe("api/editor/comms", function() {
|
||||
comms.publish('topic3', 'correct');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic3","data":"correct"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic3","data":"correct"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -133,7 +143,8 @@ describe("api/editor/comms", function() {
|
||||
comms.publish('topic4', 'bar');
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"topic4","data":"bar"}');
|
||||
console.log(msg);
|
||||
msg.should.equal('[{"topic":"topic4","data":"bar"}]');
|
||||
ws.close();
|
||||
done();
|
||||
});
|
||||
@@ -325,7 +336,7 @@ describe("api/editor/comms", function() {
|
||||
var ws = new WebSocket(url);
|
||||
var count = 0;
|
||||
ws.on('message', function(data) {
|
||||
var msg = JSON.parse(data);
|
||||
var msg = JSON.parse(data)[0];
|
||||
msg.should.have.property('topic','hb');
|
||||
msg.should.have.property('data').be.a.Number();
|
||||
count++;
|
||||
@@ -346,7 +357,7 @@ describe("api/editor/comms", function() {
|
||||
}, 50);
|
||||
});
|
||||
ws.on('message', function(data) {
|
||||
var msg = JSON.parse(data);
|
||||
var msg = JSON.parse(data)[0];
|
||||
// It is possible a heartbeat message may arrive - so ignore them
|
||||
if (msg.topic != "hb") {
|
||||
msg.should.have.property('topic', 'foo');
|
||||
@@ -435,7 +446,7 @@ describe("api/editor/comms", function() {
|
||||
ws.send('{"subscribe":"foo"}');
|
||||
comms.publish('foo', 'correct');
|
||||
} else {
|
||||
msg.should.equal('{"topic":"foo","data":"correct"}');
|
||||
msg.should.equal('[{"topic":"foo","data":"correct"}]');
|
||||
ws.close();
|
||||
}
|
||||
});
|
||||
@@ -509,7 +520,7 @@ describe("api/editor/comms", function() {
|
||||
},200);
|
||||
});
|
||||
ws.on('message', function(msg) {
|
||||
msg.should.equal('{"topic":"foo","data":"correct"}');
|
||||
msg.should.equal('[{"topic":"foo","data":"correct"}]');
|
||||
count++;
|
||||
ws.close();
|
||||
});
|
||||
|
@@ -26,11 +26,11 @@ var registry = require("../../../../red/runtime/nodes/registry");
|
||||
|
||||
describe("red/nodes/index", function() {
|
||||
before(function() {
|
||||
sinon.stub(flows,"startFlows");
|
||||
sinon.stub(index,"startFlows");
|
||||
process.env.NODE_RED_HOME = path.resolve(path.join(__dirname,"..","..","..",".."))
|
||||
});
|
||||
after(function() {
|
||||
flows.startFlows.restore();
|
||||
index.startFlows.restore();
|
||||
delete process.env.NODE_RED_HOME;
|
||||
});
|
||||
|
||||
|
@@ -150,7 +150,46 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
});
|
||||
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) {
|
||||
@@ -196,5 +235,27 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
});
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -72,7 +72,15 @@ describe("red/nodes/registry/registry",function() {
|
||||
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"]
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -198,7 +206,39 @@ describe("red/nodes/registry/registry",function() {
|
||||
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() {
|
||||
@@ -334,7 +374,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
enabled: true,
|
||||
loaded: false,
|
||||
config: "configB",
|
||||
types: [ "test-a","test-b"]
|
||||
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');
|
||||
@@ -493,7 +533,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
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')});
|
||||
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);
|
||||
});
|
||||
@@ -505,4 +545,24 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
});
|
||||
|
||||
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"]});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
BIN
test/red/runtime/nodes/resources/userDir/lib/icons/test_icon.png
Normal file
BIN
test/red/runtime/nodes/resources/userDir/lib/icons/test_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 B |
@@ -17,8 +17,10 @@
|
||||
var should = require("should");
|
||||
var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var localfilesystem = require("../../../../../red/runtime/storage/localfilesystem");
|
||||
var log = require("../../../../../red/runtime/log");
|
||||
|
||||
describe('storage/localfilesystem', function() {
|
||||
var mockRuntime = {
|
||||
@@ -285,6 +287,45 @@ describe('storage/localfilesystem', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fsync the flows file',function(done) {
|
||||
var flowFile = 'test.json';
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
sinon.spy(fs,"fsync");
|
||||
localfilesystem.saveFlows(testFlow).then(function() {
|
||||
fs.fsync.callCount.should.eql(1);
|
||||
fs.fsync.restore();
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should log fsync errors and continue',function(done) {
|
||||
var flowFile = 'test.json';
|
||||
var flowFilePath = path.join(userDir,flowFile);
|
||||
localfilesystem.init({userDir:userDir, flowFile:flowFilePath}).then(function() {
|
||||
sinon.stub(fs,"fsync", function(fd, cb) {
|
||||
cb(new Error());
|
||||
});
|
||||
sinon.spy(log,"warn");
|
||||
localfilesystem.saveFlows(testFlow).then(function() {
|
||||
log.warn.callCount.should.eql(1);
|
||||
log.warn.restore();
|
||||
fs.fsync.callCount.should.eql(1);
|
||||
fs.fsync.restore();
|
||||
done();
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
}).otherwise(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should backup the flows file', function(done) {
|
||||
var defaultFlowFile = 'flows_'+require('os').hostname()+'.json';
|
||||
var defaultFlowFilePath = path.join(userDir,defaultFlowFile);
|
||||
|
Reference in New Issue
Block a user