mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge pull request #2772 from node-red/api-tidy
Fully remove when.js dependency
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var when = require("when");
|
||||
var http = require("http");
|
||||
var https = require("https");
|
||||
var should = require("should");
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var ws = require("ws");
|
||||
var when = require("when");
|
||||
var should = require("should");
|
||||
var helper = require("node-red-node-test-helper");
|
||||
var websocketNode = require("nr-test-utils").require("@node-red/nodes/core/network/22-websocket.js");
|
||||
@@ -27,7 +26,7 @@ function getWsUrl(path) {
|
||||
}
|
||||
|
||||
function createClient(listenerid) {
|
||||
return when.promise(function(resolve, reject) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var node = helper.getNode(listenerid);
|
||||
var url = getWsUrl(node.path);
|
||||
var sock = new ws(url);
|
||||
@@ -300,23 +299,33 @@ describe('websocket Node', function() {
|
||||
{ id: "n2", type: "websocket out", server: "n1" },
|
||||
{ id: "n3", type: "helper", wires: [["n2"]] }];
|
||||
helper.load(websocketNode, flow, function() {
|
||||
var def1 = when.defer(),
|
||||
def2 = when.defer();
|
||||
when.all([createClient("n1"), createClient("n1")]).then(function(socks) {
|
||||
socks[0].on("message", function(msg, flags) {
|
||||
msg.should.equal("hello");
|
||||
def1.resolve();
|
||||
});
|
||||
socks[1].on("message", function(msg, flags) {
|
||||
msg.should.equal("hello");
|
||||
def2.resolve();
|
||||
});
|
||||
Promise.all([createClient("n1"), createClient("n1")]).then(function(socks) {
|
||||
var promises = [
|
||||
new Promise((resolve,reject) => {
|
||||
socks[0].on("message", function(msg, flags) {
|
||||
try {
|
||||
msg.should.equal("hello");
|
||||
resolve();
|
||||
} catch(err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}),
|
||||
new Promise((resolve,reject) => {
|
||||
socks[1].on("message", function(msg, flags) {
|
||||
try {
|
||||
msg.should.equal("hello");
|
||||
resolve();
|
||||
} catch(err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
})
|
||||
];
|
||||
helper.getNode("n3").send({
|
||||
payload: "hello"
|
||||
});
|
||||
return when.all([def1.promise, def2.promise]).then(function() {
|
||||
done();
|
||||
});
|
||||
return Promise.all(promises).then(() => {done()});
|
||||
}).catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
|
@@ -19,7 +19,6 @@ var request = require('supertest');
|
||||
var express = require('express');
|
||||
var bodyParser = require('body-parser');
|
||||
var sinon = require('sinon');
|
||||
var when = require('when');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
|
@@ -19,7 +19,6 @@ var request = require('supertest');
|
||||
var express = require('express');
|
||||
var bodyParser = require('body-parser');
|
||||
var sinon = require('sinon');
|
||||
var when = require('when');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
|
||||
var passport = require("passport");
|
||||
@@ -60,7 +59,7 @@ describe("api/auth/index",function() {
|
||||
describe("revoke", function() {
|
||||
it("revokes a token", function(done) {
|
||||
var revokeToken = sinon.stub(Tokens,"revoke",function() {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
var req = { body: { token: "abcdef" } };
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require('when');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -37,7 +36,7 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
it('Handles authentication failure',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
strategies.passwordTokenExchange({},"user","password","scope",function(err,token) {
|
||||
@@ -53,7 +52,7 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
it('Handles scope overreach',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
return when.resolve({username:"user",permissions:"read"});
|
||||
return Promise.resolve({username:"user",permissions:"read"});
|
||||
});
|
||||
|
||||
strategies.passwordTokenExchange({},"user","password","*",function(err,token) {
|
||||
@@ -69,14 +68,14 @@ describe("api/auth/strategies", function() {
|
||||
|
||||
it('Creates new token on authentication success',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
return when.resolve({username:"user",permissions:"*"});
|
||||
return Promise.resolve({username:"user",permissions:"*"});
|
||||
});
|
||||
var tokenDetails = {};
|
||||
var tokenCreate = sinon.stub(Tokens,"create",function(username,client,scope) {
|
||||
tokenDetails.username = username;
|
||||
tokenDetails.client = client;
|
||||
tokenDetails.scope = scope;
|
||||
return when.resolve({accessToken: "123456"});
|
||||
return Promise.resolve({accessToken: "123456"});
|
||||
});
|
||||
|
||||
strategies.passwordTokenExchange({id:"myclient"},"user","password","read",function(err,token) {
|
||||
@@ -100,7 +99,7 @@ describe("api/auth/strategies", function() {
|
||||
describe("Anonymous Strategy", function() {
|
||||
it('Succeeds if anon user enabled',function(done) {
|
||||
var userDefault = sinon.stub(Users,"default",function() {
|
||||
return when.resolve("anon");
|
||||
return Promise.resolve("anon");
|
||||
});
|
||||
strategies.anonymousStrategy._success = strategies.anonymousStrategy.success;
|
||||
strategies.anonymousStrategy.success = function(user) {
|
||||
@@ -113,7 +112,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Fails if anon user not enabled',function(done) {
|
||||
var userDefault = sinon.stub(Users,"default",function() {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail;
|
||||
strategies.anonymousStrategy.fail = function(err) {
|
||||
@@ -132,7 +131,7 @@ describe("api/auth/strategies", function() {
|
||||
describe("Tokens Strategy", function() {
|
||||
it('Succeeds if tokens user enabled custom header',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||
return when.resolve("tokens-"+token);
|
||||
return Promise.resolve("tokens-"+token);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
return "x-test-token";
|
||||
@@ -148,7 +147,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Succeeds if tokens user enabled default header',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function(token) {
|
||||
return when.resolve("tokens-"+token);
|
||||
return Promise.resolve("tokens-"+token);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
return "authorization";
|
||||
@@ -164,7 +163,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Fails if tokens user not enabled',function(done) {
|
||||
var userTokens = sinon.stub(Users,"tokens",function() {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) {
|
||||
return "authorization";
|
||||
@@ -187,7 +186,7 @@ describe("api/auth/strategies", function() {
|
||||
describe("Bearer Strategy", function() {
|
||||
it('Rejects invalid token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
strategies.bearerStrategy("1234",function(err,user) {
|
||||
@@ -204,10 +203,10 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Accepts valid token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
return when.resolve({user:"user",scope:"scope"});
|
||||
return Promise.resolve({user:"user",scope:"scope"});
|
||||
});
|
||||
var getUser = sinon.stub(Users,"get",function(username) {
|
||||
return when.resolve("aUser");
|
||||
return Promise.resolve("aUser");
|
||||
});
|
||||
|
||||
strategies.bearerStrategy("1234",function(err,user,opts) {
|
||||
@@ -226,10 +225,10 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Fail if no user for token',function(done) {
|
||||
var getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
return when.resolve({user:"user",scope:"scope"});
|
||||
return Promise.resolve({user:"user",scope:"scope"});
|
||||
});
|
||||
var getUser = sinon.stub(Users,"get",function(username) {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
|
||||
strategies.bearerStrategy("1234",function(err,user,opts) {
|
||||
@@ -252,7 +251,7 @@ describe("api/auth/strategies", function() {
|
||||
it('Accepts valid client',function(done) {
|
||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
return when.resolve(testClient);
|
||||
return Promise.resolve(testClient);
|
||||
});
|
||||
|
||||
strategies.clientPasswordStrategy(testClient.id,testClient.secret,function(err,client) {
|
||||
@@ -270,7 +269,7 @@ describe("api/auth/strategies", function() {
|
||||
it('Rejects invalid client secret',function(done) {
|
||||
var testClient = {id:"node-red-editor",secret:"not_available"};
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
return when.resolve(testClient);
|
||||
return Promise.resolve(testClient);
|
||||
});
|
||||
|
||||
strategies.clientPasswordStrategy(testClient.id,"invalid_secret",function(err,client) {
|
||||
@@ -287,7 +286,7 @@ describe("api/auth/strategies", function() {
|
||||
});
|
||||
it('Rejects invalid client id',function(done) {
|
||||
var getClient = sinon.stub(Clients,"get",function(client) {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
|
||||
try {
|
||||
@@ -305,7 +304,7 @@ describe("api/auth/strategies", function() {
|
||||
var userAuthentication;
|
||||
it('Blocks after 5 failures',function(done) {
|
||||
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
for (var z=0; z<5; z++) {
|
||||
strategies.passwordTokenExchange({},"user","badpassword","scope",function(err,token) {
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -35,7 +34,7 @@ describe("api/auth/tokens", function() {
|
||||
it('returns a valid token', function(done) {
|
||||
Tokens.init({},{
|
||||
getSessions:function() {
|
||||
return when.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||
return Promise.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||
}
|
||||
}).then(function() {
|
||||
Tokens.get("1234").then(function(token) {
|
||||
@@ -52,7 +51,7 @@ describe("api/auth/tokens", function() {
|
||||
it('returns null for an invalid token', function(done) {
|
||||
Tokens.init({},{
|
||||
getSessions:function() {
|
||||
return when.resolve({});
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}).then(function() {
|
||||
Tokens.get("1234").then(function(token) {
|
||||
@@ -66,11 +65,11 @@ describe("api/auth/tokens", function() {
|
||||
});
|
||||
});
|
||||
it('returns null for an expired token', function(done) {
|
||||
var saveSessions = sinon.stub().returns(when.resolve());
|
||||
var saveSessions = sinon.stub().returns(Promise.resolve());
|
||||
var expiryTime = Date.now()+50;
|
||||
Tokens.init({},{
|
||||
getSessions:function() {
|
||||
return when.resolve({"1234":{"user":"fred","expires":expiryTime}});
|
||||
return Promise.resolve({"1234":{"user":"fred","expires":expiryTime}});
|
||||
},
|
||||
saveSessions: saveSessions
|
||||
}).then(function() {
|
||||
@@ -100,10 +99,10 @@ describe("api/auth/tokens", function() {
|
||||
tokens: [{
|
||||
token: "1234",
|
||||
user: "fred",
|
||||
}]
|
||||
}]
|
||||
},{
|
||||
getSessions:function() {
|
||||
return when.resolve({});
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}).then(function() {
|
||||
Tokens.get("1234").then(function(token) {
|
||||
@@ -124,11 +123,11 @@ describe("api/auth/tokens", function() {
|
||||
var savedSession;
|
||||
Tokens.init({sessionExpiryTime: 10},{
|
||||
getSessions:function() {
|
||||
return when.resolve({});
|
||||
return Promise.resolve({});
|
||||
},
|
||||
saveSessions:function(sess) {
|
||||
savedSession = sess;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
var expectedExpiryTime = Date.now()+10000;
|
||||
@@ -159,11 +158,11 @@ describe("api/auth/tokens", function() {
|
||||
var savedSession;
|
||||
Tokens.init({},{
|
||||
getSessions:function() {
|
||||
return when.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||
return Promise.resolve({"1234":{"user":"fred","expires":Date.now()+1000}});
|
||||
},
|
||||
saveSessions:function(sess) {
|
||||
savedSession = sess;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
}).then(function() {
|
||||
Tokens.revoke("1234").then(function() {
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require('when');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -144,12 +143,12 @@ describe("api/auth/users", function() {
|
||||
Users.init({
|
||||
type:"credentials",
|
||||
users:function(username) {
|
||||
return when.resolve({'username':'dave','permissions':'read'});
|
||||
return Promise.resolve({'username':'dave','permissions':'read'});
|
||||
},
|
||||
authenticate: function(username,password) {
|
||||
authUsername = username;
|
||||
authPassword = password;
|
||||
return when.resolve({'username':'pete','permissions':'write'});
|
||||
return Promise.resolve({'username':'pete','permissions':'write'});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@@ -18,7 +18,6 @@ var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
const stoppable = require('stoppable');
|
||||
|
||||
var when = require("when");
|
||||
var http = require('http');
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
@@ -59,7 +58,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -165,7 +164,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -203,7 +202,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -241,7 +240,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -279,7 +278,7 @@ describe("api/editor/comms", function() {
|
||||
var url;
|
||||
var port;
|
||||
before(function(done) {
|
||||
sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
@@ -345,28 +344,28 @@ describe("api/editor/comms", function() {
|
||||
var getToken;
|
||||
var getUserToken;
|
||||
before(function(done) {
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve(null);});
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve(null);});
|
||||
getUser = sinon.stub(Users,"get", function(username) {
|
||||
if (username == "fred") {
|
||||
return when.resolve({permissions:"read"});
|
||||
return Promise.resolve({permissions:"read"});
|
||||
} else {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
getUserToken = sinon.stub(Users,"tokens", function(token) {
|
||||
if (token == "abcde") {
|
||||
return when.resolve({user:"wilma", permissions:"*"})
|
||||
return Promise.resolve({user:"wilma", permissions:"*"})
|
||||
} else {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
getToken = sinon.stub(Tokens,"get",function(token) {
|
||||
if (token == "1234") {
|
||||
return when.resolve({user:"fred",scope:["*"]});
|
||||
return Promise.resolve({user:"fred",scope:["*"]});
|
||||
} else if (token == "5678") {
|
||||
return when.resolve({user:"barney",scope:["*"]});
|
||||
return Promise.resolve({user:"barney",scope:["*"]});
|
||||
} else {
|
||||
return when.resolve(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -484,7 +483,7 @@ describe("api/editor/comms", function() {
|
||||
var port;
|
||||
var getDefaultUser;
|
||||
before(function(done) {
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return when.resolve({permissions:"read"});});
|
||||
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve({permissions:"read"});});
|
||||
server = stoppable(http.createServer(function(req,res){app(req,res)}));
|
||||
comms.init(server, {adminAuth:{}}, {comms: mockComms});
|
||||
server.listen(listenPort, address);
|
||||
|
@@ -18,7 +18,6 @@ var should = require("should");
|
||||
var request = require('supertest');
|
||||
var express = require('express');
|
||||
var sinon = require('sinon');
|
||||
var when = require('when');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
|
@@ -28,10 +28,6 @@ var auth = NR_TEST_UTILS.require("@node-red/editor-api/lib/auth");
|
||||
|
||||
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
||||
|
||||
|
||||
var when = require("when");
|
||||
|
||||
|
||||
describe("api/editor/index", function() {
|
||||
var app;
|
||||
describe("disabled the editor", function() {
|
||||
|
@@ -17,7 +17,6 @@
|
||||
var should = require("should");
|
||||
var express = require('express');
|
||||
var sinon = require('sinon');
|
||||
var when = require('when');
|
||||
var fs = require("fs");
|
||||
|
||||
var app = express();
|
||||
|
@@ -18,7 +18,6 @@ var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var request = require("supertest");
|
||||
var express = require("express");
|
||||
var when = require("when");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var when = require("when");
|
||||
var fs = require("fs");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -51,7 +50,7 @@ describe('red/registry/index', function() {
|
||||
describe('#addModule', function() {
|
||||
it('loads the module and returns its info', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
@@ -63,7 +62,7 @@ describe('red/registry/index', function() {
|
||||
});
|
||||
it('rejects if loader rejects', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.reject("error");
|
||||
return Promise.reject("error");
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
@@ -80,7 +79,7 @@ describe('red/registry/index', function() {
|
||||
describe('#enableNode',function() {
|
||||
it('enables a node set',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||
return {id:"node-set",loaded:true};
|
||||
@@ -104,14 +103,14 @@ describe('red/registry/index', function() {
|
||||
|
||||
it('triggers a node load',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
return Promise.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(loader,"loadNodeSet",function(){return Promise.resolve();}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
|
||||
|
||||
registry.enableNode("node-set").then(function(ns) {
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require('fs-extra');
|
||||
var EventEmitter = require('events');
|
||||
@@ -26,6 +25,7 @@ var NR_TEST_UTILS = require("nr-test-utils");
|
||||
var installer = NR_TEST_UTILS.require("@node-red/registry/lib/installer");
|
||||
var registry = NR_TEST_UTILS.require("@node-red/registry/lib/index");
|
||||
var typeRegistry = NR_TEST_UTILS.require("@node-red/registry/lib/registry");
|
||||
const { events, exec, log } = NR_TEST_UTILS.require("@node-red/util");
|
||||
|
||||
describe('nodes/registry/installer', function() {
|
||||
|
||||
@@ -39,21 +39,15 @@ describe('nodes/registry/installer', function() {
|
||||
_: function(msg) { return msg }
|
||||
}
|
||||
|
||||
var execResponse;
|
||||
|
||||
beforeEach(function() {
|
||||
installer.init({log:mockLog, settings:{}, events: new EventEmitter(), exec: {
|
||||
run: function() {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
}});
|
||||
sinon.stub(exec,"run", () => execResponse || Promise.resolve(""))
|
||||
installer.init({})
|
||||
});
|
||||
function initInstaller(execResult) {
|
||||
installer.init({log:mockLog, settings:{}, events: new EventEmitter(), exec: {
|
||||
run: function() {
|
||||
return execResult;
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
||||
afterEach(function() {
|
||||
execResponse = null;
|
||||
if (registry.addModule.restore) {
|
||||
registry.addModule.restore();
|
||||
}
|
||||
@@ -73,7 +67,7 @@ describe('nodes/registry/installer', function() {
|
||||
if (fs.statSync.restore) {
|
||||
fs.statSync.restore();
|
||||
}
|
||||
|
||||
exec.run.restore();
|
||||
});
|
||||
|
||||
describe("installs module", function() {
|
||||
@@ -109,7 +103,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
installer.installModule("this_wont_exist").catch(function(err) {
|
||||
err.should.have.property("code",404);
|
||||
done();
|
||||
@@ -123,7 +117,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
sinon.stub(typeRegistry,"getModuleInfo", function() {
|
||||
return {
|
||||
version: "0.1.1"
|
||||
@@ -164,7 +158,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
installer.installModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
}).catch(err => {
|
||||
@@ -182,10 +176,10 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist").then(function(info) {
|
||||
@@ -216,7 +210,7 @@ describe('nodes/registry/installer', function() {
|
||||
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);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||
|
||||
@@ -227,7 +221,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
installer.installModule(resourcesDir).then(function(info) {
|
||||
info.should.eql(nodeInfo);
|
||||
done();
|
||||
@@ -243,10 +237,10 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist",null,"https://example/foo-0.1.1.tgz").then(function(info) {
|
||||
@@ -259,19 +253,20 @@ describe('nodes/registry/installer', function() {
|
||||
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");
|
||||
var rejectedCount = 0;
|
||||
|
||||
promises.push(installer.uninstallModule("this_wont_exist ").catch(() => {rejectedCount++}));
|
||||
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont").catch(() => {rejectedCount++}));
|
||||
Promise.all(promises).then(function() {
|
||||
rejectedCount.should.eql(2);
|
||||
done();
|
||||
});
|
||||
}).catch(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);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
var res = {
|
||||
code: 1,
|
||||
@@ -280,7 +275,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.reject(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
|
||||
installer.uninstallModule("this_wont_exist").then(function() {
|
||||
done(new Error("Unexpected success"));
|
||||
@@ -304,7 +299,7 @@ describe('nodes/registry/installer', function() {
|
||||
}
|
||||
var p = Promise.resolve(res);
|
||||
p.catch((err)=>{});
|
||||
initInstaller(p)
|
||||
execResponse = p;
|
||||
|
||||
sinon.stub(fs,"statSync", function(fn) { return {}; });
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var fs = require("fs-extra");
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
@@ -54,7 +53,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
}
|
||||
describe("#getNodeFiles",function() {
|
||||
it("Finds all the node files in the resources tree",function(done) {
|
||||
localfilesystem.init({settings:{coreNodesDir:resourcesDir}});
|
||||
localfilesystem.init({coreNodesDir:resourcesDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -69,7 +68,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
done();
|
||||
});
|
||||
it("Includes node files from settings",function(done) {
|
||||
localfilesystem.init({settings:{nodesIncludes:['TestNode1.js'],coreNodesDir:resourcesDir}});
|
||||
localfilesystem.init({nodesIncludes:['TestNode1.js'],coreNodesDir:resourcesDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -79,7 +78,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
done();
|
||||
});
|
||||
it("Excludes node files from settings",function(done) {
|
||||
localfilesystem.init({settings:{nodesExcludes:['TestNode1.js'],coreNodesDir:resourcesDir}});
|
||||
localfilesystem.init({nodesExcludes:['TestNode1.js'],coreNodesDir:resourcesDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -89,7 +88,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
done();
|
||||
});
|
||||
it("Finds nodes in userDir/nodes",function(done) {
|
||||
localfilesystem.init({settings:{userDir:userDir}});
|
||||
localfilesystem.init({userDir:userDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -100,7 +99,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
});
|
||||
|
||||
it("Finds nodes in settings.nodesDir (string)",function(done) {
|
||||
localfilesystem.init({settings:{nodesDir:userDir}});
|
||||
localfilesystem.init({nodesDir:userDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -111,7 +110,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
});
|
||||
it("Finds nodes in settings.nodesDir (string,relative path)",function(done) {
|
||||
var relativeUserDir = path.join("test","unit","@node-red","registry","lib","resources","userDir");
|
||||
localfilesystem.init({settings:{nodesDir:relativeUserDir}});
|
||||
localfilesystem.init({nodesDir:relativeUserDir});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -121,7 +120,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
done();
|
||||
});
|
||||
it("Finds nodes in settings.nodesDir (array)",function(done) {
|
||||
localfilesystem.init({settings:{nodesDir:[userDir]}});
|
||||
localfilesystem.init({nodesDir:[userDir]});
|
||||
var nodeList = localfilesystem.getNodeFiles(true);
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -140,7 +139,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({settings:{coreNodesDir:moduleDir}});
|
||||
localfilesystem.init({coreNodesDir:moduleDir});
|
||||
var nodeList = localfilesystem.getNodeFiles();
|
||||
nodeList.should.have.a.property("node-red");
|
||||
var nm = nodeList['node-red'];
|
||||
@@ -176,18 +175,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
it("scans icon files in the resources tree",function(done) {
|
||||
var count = 0;
|
||||
localfilesystem.init({
|
||||
|
||||
// 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}
|
||||
coreNodesDir: resourcesDir
|
||||
});
|
||||
var list = localfilesystem.getNodeFiles(true);
|
||||
list.should.have.property("node-red");
|
||||
@@ -202,22 +190,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
it("scans icons dir in library",function(done) {
|
||||
var count = 0;
|
||||
localfilesystem.init({
|
||||
//
|
||||
// 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}
|
||||
userDir: userDir
|
||||
});
|
||||
var list = localfilesystem.getNodeFiles(true);
|
||||
list.should.have.property("node-red");
|
||||
@@ -241,7 +214,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({settings:{coreNodesDir:moduleDir}});
|
||||
localfilesystem.init({coreNodesDir:moduleDir});
|
||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||
nodeModule.should.have.a.property('TestNodeModule');
|
||||
nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule');
|
||||
@@ -267,7 +240,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
}
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({settings:{coreNodesDir:moduleDir}});
|
||||
localfilesystem.init({coreNodesDir:moduleDir});
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
localfilesystem.getModuleFiles('WontExistModule');
|
||||
@@ -287,14 +260,7 @@ describe("red/nodes/registry/localfilesystem",function() {
|
||||
return _join.apply(null,arguments);
|
||||
}));
|
||||
localfilesystem.init({
|
||||
|
||||
// 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}
|
||||
coreNodesDir: moduleDir
|
||||
});
|
||||
var nodeModule = localfilesystem.getModuleFiles('TestNodeModule');
|
||||
nodeModule.should.have.property("TestNodeModule");
|
||||
|
@@ -15,16 +15,13 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var typeRegistry = NR_TEST_UTILS.require("@node-red/registry/lib/registry");
|
||||
var EventEmitter = require('events');
|
||||
|
||||
var events = new EventEmitter();
|
||||
const { events } = NR_TEST_UTILS.require("@node-red/util");
|
||||
|
||||
describe("red/nodes/registry/registry",function() {
|
||||
|
||||
@@ -34,7 +31,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
function stubSettings(s,available,initialConfig) {
|
||||
s.available = function() {return available;};
|
||||
s.set = sinon.spy(function(s,v) { return when.resolve();});
|
||||
s.set = sinon.spy(function(s,v) { return Promise.resolve();});
|
||||
s.get = function(s) { return initialConfig;};
|
||||
return s;
|
||||
}
|
||||
@@ -85,7 +82,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
describe('#init/load', function() {
|
||||
it('loads initial config', function(done) {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null,events);
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.load();
|
||||
typeRegistry.getNodeList().should.have.lengthOf(1);
|
||||
@@ -95,7 +92,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
it('migrates legacy format', function(done) {
|
||||
var legacySettings = {
|
||||
available: function() { return true; },
|
||||
set: sinon.stub().returns(when.resolve()),
|
||||
set: sinon.stub().returns(Promise.resolve()),
|
||||
get: function() { return {
|
||||
"123": {
|
||||
"name": "72-sentiment.js",
|
||||
@@ -122,7 +119,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
}}
|
||||
};
|
||||
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,null,events);
|
||||
typeRegistry.init(legacySettings,null);
|
||||
typeRegistry.load();
|
||||
legacySettings.set.calledOnce.should.be.true();
|
||||
legacySettings.set.args[0][1].should.eql(expected);
|
||||
@@ -134,7 +131,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
describe.skip('#addNodeSet', function() {
|
||||
it('adds a node set for an unknown module', function() {
|
||||
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
@@ -163,7 +160,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
it('adds a node set to an existing module', function() {
|
||||
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
@@ -192,7 +189,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
|
||||
it('doesnt add node set types if node set has an error', function() {
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
@@ -208,7 +205,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
|
||||
it('doesnt add node set if type already exists', function() {
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
typeRegistry.getNodeList().should.have.lengthOf(0);
|
||||
typeRegistry.getModuleList().should.eql({});
|
||||
|
||||
@@ -242,7 +239,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
describe("#enableNodeSet", function() {
|
||||
it('throws error if settings unavailable', function() {
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.enableNodeSet("test-module/test-name");
|
||||
@@ -250,7 +247,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
|
||||
it('throws error if module unknown', function() {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null,events);
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.enableNodeSet("test-module/unknown");
|
||||
@@ -261,7 +258,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
describe("#disableNodeSet", function() {
|
||||
it('throws error if settings unavailable', function() {
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.disableNodeSet("test-module/test-name");
|
||||
@@ -269,7 +266,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
|
||||
it('throws error if module unknown', function() {
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null,events);
|
||||
typeRegistry.init(settingsWithStorageAndInitialConfig,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.disableNodeSet("test-module/unknown");
|
||||
@@ -280,7 +277,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
describe('#getNodeConfig', function() {
|
||||
it('returns nothing for an unregistered type config', function(done) {
|
||||
typeRegistry.init(settings,null,events);
|
||||
typeRegistry.init(settings,null);
|
||||
var config = typeRegistry.getNodeConfig("imaginary-shark");
|
||||
(config === null).should.be.true();
|
||||
done();
|
||||
@@ -289,7 +286,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
describe('#saveNodeList',function() {
|
||||
it('rejects when settings unavailable',function(done) {
|
||||
typeRegistry.init(stubSettings({},false,{}),null,events);
|
||||
typeRegistry.init(stubSettings({},false,{}),null);
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {"test-name":{module:"test-module",name:"test-name",types:[]}}});
|
||||
typeRegistry.saveNodeList().catch(function(err) {
|
||||
done();
|
||||
@@ -297,7 +294,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
it('saves the list',function(done) {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s,null,events);
|
||||
typeRegistry.init(s,null);
|
||||
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":testNodeSet1,
|
||||
@@ -326,7 +323,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
describe('#removeModule',function() {
|
||||
it('throws error for unknown module', function() {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s,null,events);
|
||||
typeRegistry.init(s,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.removeModule("test-module/unknown");
|
||||
@@ -334,7 +331,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
it('throws error for unavaiable settings', function() {
|
||||
var s = stubSettings({},false,{});
|
||||
typeRegistry.init(s,null,events);
|
||||
typeRegistry.init(s,null);
|
||||
/*jshint immed: false */
|
||||
(function(){
|
||||
typeRegistry.removeModule("test-module/unknown");
|
||||
@@ -342,7 +339,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
it('removes a known module', function() {
|
||||
var s = stubSettings({},true,{});
|
||||
typeRegistry.init(s,null,events);
|
||||
typeRegistry.init(s,null);
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":testNodeSet1
|
||||
}});
|
||||
@@ -361,7 +358,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
it('returns node config', function() {
|
||||
typeRegistry.init(settings,{
|
||||
getNodeHelp: function(config) { return "HE"+config.name+"LP" }
|
||||
},events);
|
||||
});
|
||||
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
@@ -390,7 +387,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
describe('#getModuleInfo', function() {
|
||||
it('returns module info', function() {
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
@@ -414,7 +411,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
describe('#getNodeInfo', function() {
|
||||
it('returns node info', function() {
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
@@ -435,7 +432,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
describe('#getFullNodeInfo', function() {
|
||||
it('returns node info', function() {
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
@@ -460,7 +457,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
});
|
||||
describe('#getNodeList', function() {
|
||||
it("returns a filtered list", function() {
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
@@ -527,7 +524,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
it('returns a registered icon' , function() {
|
||||
var testIcon = path.resolve(__dirname+'/resources/userDir/lib/icons/');
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
@@ -559,7 +556,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
it('returns an icon list of registered node module', function() {
|
||||
var testIcon = path.resolve(__dirname+'/resources/userDir/lib/icons/');
|
||||
typeRegistry.init(settings,{},events);
|
||||
typeRegistry.init(settings,{});
|
||||
typeRegistry.addModule({name: "test-module",version:"0.0.1",nodes: {
|
||||
"test-name":{
|
||||
id: "test-module/test-name",
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// 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) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-2",TestNode);
|
||||
resolve();
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// 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) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
reject("fail");
|
||||
});
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ var sinon = require("sinon");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
var comms = NR_TEST_UTILS.require("@node-red/runtime/lib/api/comms");
|
||||
var events = NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
|
||||
describe("runtime-api/comms", function() {
|
||||
describe("listens for events", function() {
|
||||
@@ -30,21 +31,19 @@ describe("runtime-api/comms", function() {
|
||||
}
|
||||
var eventHandlers = {};
|
||||
before(function(done) {
|
||||
sinon.stub(events,"removeListener", function() {})
|
||||
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler })
|
||||
comms.init({
|
||||
log: {
|
||||
trace: function(){}
|
||||
},
|
||||
events: {
|
||||
removeListener: function() {},
|
||||
on: function(evt,handler) {
|
||||
eventHandlers[evt] = handler;
|
||||
}
|
||||
}
|
||||
})
|
||||
comms.addConnection({client: clientConnection}).then(done);
|
||||
})
|
||||
after(function(done) {
|
||||
comms.removeConnection({client: clientConnection}).then(done);
|
||||
events.removeListener.restore();
|
||||
events.on.restore();
|
||||
})
|
||||
afterEach(function() {
|
||||
messages = [];
|
||||
@@ -98,18 +97,18 @@ describe("runtime-api/comms", function() {
|
||||
}
|
||||
}
|
||||
before(function() {
|
||||
sinon.stub(events,"removeListener", function() {})
|
||||
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler })
|
||||
comms.init({
|
||||
log: {
|
||||
trace: function(){}
|
||||
},
|
||||
events: {
|
||||
removeListener: function() {},
|
||||
on: function(evt,handler) {
|
||||
eventHandlers[evt] = handler;
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
after(function() {
|
||||
events.removeListener.restore();
|
||||
events.on.restore();
|
||||
})
|
||||
afterEach(function(done) {
|
||||
comms.removeConnection({client: clientConnection1}).then(function() {
|
||||
comms.removeConnection({client: clientConnection2}).then(done);
|
||||
@@ -178,18 +177,18 @@ describe("runtime-api/comms", function() {
|
||||
}
|
||||
var eventHandlers = {};
|
||||
before(function() {
|
||||
sinon.stub(events,"removeListener", function() {})
|
||||
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler })
|
||||
comms.init({
|
||||
log: {
|
||||
trace: function(){}
|
||||
},
|
||||
events: {
|
||||
removeListener: function() {},
|
||||
on: function(evt,handler) {
|
||||
eventHandlers[evt] = handler;
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
after(function() {
|
||||
events.removeListener.restore();
|
||||
events.on.restore();
|
||||
})
|
||||
afterEach(function(done) {
|
||||
messages = [];
|
||||
comms.removeConnection({client: clientConnection}).then(done);
|
||||
|
@@ -185,7 +185,6 @@ var request = require('supertest');
|
||||
var express = require('express');
|
||||
var bodyParser = require('body-parser');
|
||||
var sinon = require('sinon');
|
||||
var when = require('when');
|
||||
|
||||
var nodes = require("../../../../red/api/admin/nodes");
|
||||
var apiUtil = require("../../../../red/api/util");
|
||||
@@ -418,7 +417,7 @@ describe("api/admin/nodes", function() {
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null; },
|
||||
installModule: function() {
|
||||
return when.resolve({
|
||||
return Promise.resolve({
|
||||
name:"foo",
|
||||
nodes:[{id:"123"}]
|
||||
});
|
||||
@@ -446,7 +445,7 @@ describe("api/admin/nodes", function() {
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:{id:"123"}}; },
|
||||
installModule: function() {
|
||||
return when.resolve({id:"123"});
|
||||
return Promise.resolve({id:"123"});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -468,7 +467,7 @@ describe("api/admin/nodes", function() {
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return null },
|
||||
installModule: function() {
|
||||
return when.reject(new Error("test error"));
|
||||
return Promise.reject(new Error("test error"));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -492,7 +491,7 @@ describe("api/admin/nodes", function() {
|
||||
installModule: function() {
|
||||
var err = new Error("test error");
|
||||
err.code = 404;
|
||||
return when.reject(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -533,7 +532,7 @@ describe("api/admin/nodes", function() {
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||
getNodeInfo: function() { return null },
|
||||
uninstallModule: function() { return when.resolve({id:"123"});}
|
||||
uninstallModule: function() { return Promise.resolve({id:"123"});}
|
||||
}
|
||||
});
|
||||
request(app)
|
||||
@@ -572,7 +571,7 @@ describe("api/admin/nodes", function() {
|
||||
nodes:{
|
||||
getModuleInfo: function(id) { return {nodes:[{id:"123"}]} },
|
||||
getNodeInfo: function() { return null },
|
||||
uninstallModule: function() { return when.reject(new Error("test error"));}
|
||||
uninstallModule: function() { return Promise.reject(new Error("test error"));}
|
||||
}
|
||||
});
|
||||
request(app)
|
||||
@@ -686,7 +685,7 @@ describe("api/admin/nodes", function() {
|
||||
settings:{available:function(){return true}},
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: false} },
|
||||
enableNode: function() { return when.resolve({id:"123",enabled: true,types:['a']}); }
|
||||
enableNode: function() { return Promise.resolve({id:"123",enabled: true,types:['a']}); }
|
||||
}
|
||||
});
|
||||
request(app)
|
||||
@@ -709,7 +708,7 @@ describe("api/admin/nodes", function() {
|
||||
settings:{available:function(){return true}},
|
||||
nodes:{
|
||||
getNodeInfo: function() { return {id:"123",enabled: true} },
|
||||
disableNode: function() { return when.resolve({id:"123",enabled: false,types:['a']}); }
|
||||
disableNode: function() { return Promise.resolve({id:"123",enabled: false,types:['a']}); }
|
||||
}
|
||||
});
|
||||
request(app)
|
||||
@@ -729,8 +728,8 @@ describe("api/admin/nodes", function() {
|
||||
|
||||
describe('no-ops if already in the right state', function() {
|
||||
function run(state,done) {
|
||||
var enableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: true,types:['a']}) });
|
||||
var disableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: false,types:['a']}) });
|
||||
var enableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: true,types:['a']}) });
|
||||
var disableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: false,types:['a']}) });
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
@@ -768,8 +767,8 @@ describe("api/admin/nodes", function() {
|
||||
|
||||
describe('does not no-op if err on node', function() {
|
||||
function run(state,done) {
|
||||
var enableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: true,types:['a']}) });
|
||||
var disableNode = sinon.spy(function() { return when.resolve({id:"123",enabled: false,types:['a']}) });
|
||||
var enableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: true,types:['a']}) });
|
||||
var disableNode = sinon.spy(function() { return Promise.resolve({id:"123",enabled: false,types:['a']}) });
|
||||
|
||||
initNodes({
|
||||
settings:{available:function(){return true}},
|
||||
@@ -811,11 +810,11 @@ describe("api/admin/nodes", function() {
|
||||
var enableNode = sinon.stub();
|
||||
enableNode.onFirstCall().returns((function() {
|
||||
n1.enabled = true;
|
||||
return when.resolve(n1);
|
||||
return Promise.resolve(n1);
|
||||
})());
|
||||
enableNode.onSecondCall().returns((function() {
|
||||
n2.enabled = true;
|
||||
return when.resolve(n2);
|
||||
return Promise.resolve(n2);
|
||||
})());
|
||||
enableNode.returns(null);
|
||||
initNodes({
|
||||
@@ -849,11 +848,11 @@ describe("api/admin/nodes", function() {
|
||||
var disableNode = sinon.stub();
|
||||
disableNode.onFirstCall().returns((function() {
|
||||
n1.enabled = false;
|
||||
return when.resolve(n1);
|
||||
return Promise.resolve(n1);
|
||||
})());
|
||||
disableNode.onSecondCall().returns((function() {
|
||||
n2.enabled = false;
|
||||
return when.resolve(n2);
|
||||
return Promise.resolve(n2);
|
||||
})());
|
||||
disableNode.returns(null);
|
||||
initNodes({
|
||||
@@ -886,11 +885,11 @@ describe("api/admin/nodes", function() {
|
||||
var node = {id:"123",enabled:state,types:['a']};
|
||||
var enableNode = sinon.spy(function(id) {
|
||||
node.enabled = true;
|
||||
return when.resolve(node);
|
||||
return Promise.resolve(node);
|
||||
});
|
||||
var disableNode = sinon.spy(function(id) {
|
||||
node.enabled = false;
|
||||
return when.resolve(node);
|
||||
return Promise.resolve(node);
|
||||
});
|
||||
|
||||
initNodes({
|
||||
@@ -933,11 +932,11 @@ describe("api/admin/nodes", function() {
|
||||
var node = {id:"123",enabled:state,types:['a'],err:"foo"};
|
||||
var enableNode = sinon.spy(function(id) {
|
||||
node.enabled = true;
|
||||
return when.resolve(node);
|
||||
return Promise.resolve(node);
|
||||
});
|
||||
var disableNode = sinon.spy(function(id) {
|
||||
node.enabled = false;
|
||||
return when.resolve(node);
|
||||
return Promise.resolve(node);
|
||||
});
|
||||
|
||||
initNodes({
|
||||
|
@@ -48,7 +48,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {}
|
||||
@@ -79,7 +79,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {}
|
||||
@@ -115,7 +115,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {
|
||||
@@ -166,7 +166,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {
|
||||
@@ -207,7 +207,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {
|
||||
@@ -252,7 +252,7 @@ describe("runtime-api/settings", function() {
|
||||
},
|
||||
nodes: {
|
||||
listContextStores: () => { return {stores:["file","memory"], default: "file"} },
|
||||
paletteEditorEnabled: () => false,
|
||||
installerEnabled: () => false,
|
||||
getCredentialKeyType: () => "test-key-type"
|
||||
},
|
||||
storage: {
|
||||
@@ -588,7 +588,6 @@ var comms = require("../../../../red/api/editor/comms");
|
||||
var info = require("../../../../red/api/editor/settings");
|
||||
var auth = require("../../../../red/api/auth");
|
||||
var sshkeys = require("../../../../red/api/editor/sshkeys");
|
||||
var when = require("when");
|
||||
var bodyParser = require("body-parser");
|
||||
var fs = require("fs-extra");
|
||||
var fspath = require("path");
|
||||
@@ -611,11 +610,11 @@ describe("api/editor/sshkeys", function() {
|
||||
exportNodeSettings:function(){},
|
||||
storage: {
|
||||
getSessions: function(){
|
||||
return when.resolve(session_data);
|
||||
return Promise.resolve(session_data);
|
||||
},
|
||||
setSessions: function(_session) {
|
||||
session_data = _session;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -633,7 +632,7 @@ describe("api/editor/sshkeys", function() {
|
||||
},
|
||||
events:{on:function(){},removeListener:function(){}},
|
||||
isStarted: function() { return isStarted; },
|
||||
nodes: {paletteEditorEnabled: function() { return false }}
|
||||
nodes: {installerEnabled: function() { return false }}
|
||||
};
|
||||
|
||||
before(function() {
|
||||
|
@@ -16,14 +16,13 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var clone = require("clone");
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var flows = NR_TEST_UTILS.require("@node-red/runtime/lib/flows");
|
||||
var RedNode = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes/Node");
|
||||
var RED = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes");
|
||||
var events = NR_TEST_UTILS.require("@node-red/runtime/lib/events");
|
||||
var events = NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
var credentials = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes/credentials");
|
||||
var typeRegistry = NR_TEST_UTILS.require("@node-red/registry")
|
||||
var Flow = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/Flow");
|
||||
@@ -65,13 +64,13 @@ describe('flows/index', function() {
|
||||
conf.forEach(function(n) {
|
||||
delete n.credentials;
|
||||
});
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
});
|
||||
credentialsLoad = sinon.stub(credentials,"load",function(creds) {
|
||||
if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") {
|
||||
return when.reject("creds error");
|
||||
return Promise.reject("creds error");
|
||||
}
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
});
|
||||
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) {
|
||||
var id;
|
||||
@@ -101,7 +100,7 @@ describe('flows/index', function() {
|
||||
storage = {
|
||||
saveFlows: function(conf) {
|
||||
storage.conf = conf;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -145,10 +144,10 @@ describe('flows/index', function() {
|
||||
var loadStorage = {
|
||||
saveFlows: function(conf) {
|
||||
loadStorage.conf = conf;
|
||||
return when.resolve(456);
|
||||
return Promise.resolve(456);
|
||||
},
|
||||
getFlows: function() {
|
||||
return when.resolve({flows:originalConfig,rev:123})
|
||||
return Promise.resolve({flows:originalConfig,rev:123})
|
||||
}
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:loadStorage});
|
||||
@@ -207,7 +206,7 @@ describe('flows/index', function() {
|
||||
newConfig.push({id:"t2",type:"tab"});
|
||||
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
events.once('flows:started',function() {
|
||||
flows.setFlows(newConfig,"nodes").then(function() {
|
||||
@@ -235,7 +234,7 @@ describe('flows/index', function() {
|
||||
newConfig.push({id:"t2",type:"tab"});
|
||||
newConfig.push({id:"t2-1",x:10,y:10,z:"t2",type:"test",wires:[]});
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
|
||||
events.once('flows:started',function() {
|
||||
@@ -277,7 +276,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.load().then(function() {
|
||||
@@ -297,7 +296,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
|
||||
events.once('flows:started',function() {
|
||||
@@ -317,7 +316,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
@@ -336,7 +335,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.load().then(function() {
|
||||
@@ -370,7 +369,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.load().then(function() {
|
||||
@@ -394,7 +393,7 @@ describe('flows/index', function() {
|
||||
// {id:"t1",type:"tab"}
|
||||
// ];
|
||||
// storage.getFlows = function() {
|
||||
// return when.resolve({flows:originalConfig});
|
||||
// return Promise.resolve({flows:originalConfig});
|
||||
// }
|
||||
//
|
||||
// events.once('flows:started',function() {
|
||||
@@ -419,7 +418,7 @@ describe('flows/index', function() {
|
||||
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
||||
// ];
|
||||
// storage.getFlows = function() {
|
||||
// return when.resolve({flows:originalConfig});
|
||||
// return Promise.resolve({flows:originalConfig});
|
||||
// }
|
||||
//
|
||||
// events.once('flows:started',function() {
|
||||
@@ -447,7 +446,7 @@ describe('flows/index', function() {
|
||||
// {id:"t1",type:"tab"}
|
||||
// ];
|
||||
// storage.getFlows = function() {
|
||||
// return when.resolve({flows:originalConfig});
|
||||
// return Promise.resolve({flows:originalConfig});
|
||||
// }
|
||||
//
|
||||
// events.once('flows:started',function() {
|
||||
@@ -473,7 +472,7 @@ describe('flows/index', function() {
|
||||
// {id:"t3-1",x:10,y:10,z:"t3",type:"test",config:"configNode",wires:[]}
|
||||
// ];
|
||||
// storage.getFlows = function() {
|
||||
// return when.resolve({flows:originalConfig});
|
||||
// return Promise.resolve({flows:originalConfig});
|
||||
// }
|
||||
//
|
||||
// events.once('flows:started',function() {
|
||||
@@ -548,7 +547,7 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.load().then(function() {
|
||||
@@ -572,10 +571,10 @@ describe('flows/index', function() {
|
||||
{id:"t1",type:"tab"}
|
||||
];
|
||||
storage.getFlows = function() {
|
||||
return when.resolve({flows:originalConfig});
|
||||
return Promise.resolve({flows:originalConfig});
|
||||
}
|
||||
storage.setFlows = function() {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
flows.init({log:mockLog, settings:{},storage:storage});
|
||||
flows.load().then(function() {
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var clone = require("clone");
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
var flowUtil = NR_TEST_UTILS.require("@node-red/runtime/lib/flows/util");
|
||||
|
@@ -28,6 +28,7 @@ var settings = NR_TEST_UTILS.require("@node-red/runtime/lib/settings");
|
||||
var util = NR_TEST_UTILS.require("@node-red/util");
|
||||
|
||||
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
||||
var i18n = NR_TEST_UTILS.require("@node-red/util").i18n;
|
||||
|
||||
describe("runtime", function() {
|
||||
afterEach(function() {
|
||||
@@ -43,43 +44,45 @@ describe("runtime", function() {
|
||||
delete process.env.NODE_RED_HOME;
|
||||
});
|
||||
function mockUtil(metrics) {
|
||||
|
||||
return {
|
||||
log:{
|
||||
log: sinon.stub(),
|
||||
warn: sinon.stub(),
|
||||
info: sinon.stub(),
|
||||
trace: sinon.stub(),
|
||||
metric: sinon.stub().returns(!!metrics),
|
||||
_: function() { return "abc"}
|
||||
},
|
||||
i18n: {
|
||||
registerMessageCatalog: function(){
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
sinon.stub(log,"log",function(){})
|
||||
sinon.stub(log,"warn",function(){})
|
||||
sinon.stub(log,"info",function(){})
|
||||
sinon.stub(log,"trace",function(){})
|
||||
sinon.stub(log,"metric",function(){ return !!metrics })
|
||||
sinon.stub(log,"_",function(){ return "abc"})
|
||||
sinon.stub(i18n,"registerMessageCatalog",function(){ return Promise.resolve()})
|
||||
}
|
||||
function unmockUtil() {
|
||||
log.log.restore && log.log.restore();
|
||||
log.warn.restore && log.warn.restore();
|
||||
log.info.restore && log.info.restore();
|
||||
log.trace.restore && log.trace.restore();
|
||||
log.metric.restore && log.metric.restore();
|
||||
log._.restore && log._.restore();
|
||||
i18n.registerMessageCatalog.restore && i18n.registerMessageCatalog.restore();
|
||||
}
|
||||
describe("init", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(log,"init",function() {});
|
||||
sinon.stub(settings,"init",function() {});
|
||||
sinon.stub(redNodes,"init",function() {})
|
||||
mockUtil();
|
||||
});
|
||||
afterEach(function() {
|
||||
log.init.restore();
|
||||
settings.init.restore();
|
||||
redNodes.init.restore();
|
||||
unmockUtil();
|
||||
})
|
||||
|
||||
it("initialises components", function() {
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/"},mockUtil());
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/"});
|
||||
settings.init.called.should.be.true();
|
||||
redNodes.init.called.should.be.true();
|
||||
});
|
||||
|
||||
it("returns version", function() {
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/"},mockUtil());
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/"});
|
||||
return runtime.version().then(version => {
|
||||
/^\d+\.\d+\.\d+(-.*)?$/.test(version).should.be.true();
|
||||
});
|
||||
@@ -98,7 +101,6 @@ describe("runtime", function() {
|
||||
var redNodesLoadFlows;
|
||||
var redNodesStartFlows;
|
||||
var redNodesLoadContextsPlugin;
|
||||
var i18nRegisterMessageCatalog;
|
||||
|
||||
beforeEach(function() {
|
||||
storageInit = sinon.stub(storage,"init",function(settings) {return Promise.resolve();});
|
||||
@@ -108,7 +110,7 @@ describe("runtime", function() {
|
||||
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return Promise.resolve()});
|
||||
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
|
||||
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {return Promise.resolve()});
|
||||
i18nRegisterMessageCatalog = sinon.stub(util.i18n,"registerMessageCatalog",function() {return Promise.resolve()});
|
||||
mockUtil();
|
||||
});
|
||||
afterEach(function() {
|
||||
storageInit.restore();
|
||||
@@ -119,7 +121,7 @@ describe("runtime", function() {
|
||||
redNodesLoadFlows.restore();
|
||||
redNodesStartFlows.restore();
|
||||
redNodesLoadContextsPlugin.restore();
|
||||
i18nRegisterMessageCatalog.restore();
|
||||
unmockUtil();
|
||||
});
|
||||
it("reports errored/missing modules",function(done) {
|
||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||
@@ -128,8 +130,7 @@ describe("runtime", function() {
|
||||
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing
|
||||
].filter(cb);
|
||||
});
|
||||
var util = mockUtil();
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/", load:function() { return Promise.resolve();}},util);
|
||||
runtime.init({testSettings: true, httpAdminRoot:"/", load:function() { return Promise.resolve();}});
|
||||
// sinon.stub(console,"log");
|
||||
runtime.start().then(function() {
|
||||
// console.log.restore();
|
||||
@@ -139,9 +140,9 @@ describe("runtime", function() {
|
||||
redNodesLoad.calledOnce.should.be.true();
|
||||
redNodesLoadFlows.calledOnce.should.be.true();
|
||||
|
||||
util.log.warn.calledWithMatch("Failed to register 1 node type");
|
||||
util.log.warn.calledWithMatch("Missing node modules");
|
||||
util.log.warn.calledWithMatch(" - module: typeA, typeB");
|
||||
log.warn.calledWithMatch("Failed to register 1 node type");
|
||||
log.warn.calledWithMatch("Missing node modules");
|
||||
log.warn.calledWithMatch(" - module: typeA, typeB");
|
||||
redNodesCleanModuleList.calledOnce.should.be.true();
|
||||
done();
|
||||
} catch(err) {
|
||||
@@ -159,16 +160,15 @@ describe("runtime", function() {
|
||||
].filter(cb);
|
||||
});
|
||||
var serverInstallModule = sinon.stub(redNodes,"installModule",function(name) { return Promise.resolve({nodes:[]});});
|
||||
var util = mockUtil();
|
||||
runtime.init({testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}},util);
|
||||
runtime.init({testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}});
|
||||
sinon.stub(console,"log");
|
||||
runtime.start().then(function() {
|
||||
console.log.restore();
|
||||
try {
|
||||
util.log.warn.calledWithMatch("Failed to register 2 node types");
|
||||
util.log.warn.calledWithMatch("Missing node modules");
|
||||
util.log.warn.calledWithMatch(" - module: typeA, typeB");
|
||||
util.log.warn.calledWithMatch(" - node-red: typeC, typeD");
|
||||
log.warn.calledWithMatch("Failed to register 2 node types");
|
||||
log.warn.calledWithMatch("Missing node modules");
|
||||
log.warn.calledWithMatch(" - module: typeA, typeB");
|
||||
log.warn.calledWithMatch(" - node-red: typeC, typeD");
|
||||
redNodesCleanModuleList.calledOnce.should.be.false();
|
||||
serverInstallModule.calledOnce.should.be.true();
|
||||
serverInstallModule.calledWithMatch("module");
|
||||
@@ -186,14 +186,13 @@ describe("runtime", function() {
|
||||
{ err:"errored",name:"errName" } // error
|
||||
].filter(cb);
|
||||
});
|
||||
var util = mockUtil();
|
||||
runtime.init({testSettings: true, verbose:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}},util);
|
||||
runtime.init({testSettings: true, verbose:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}});
|
||||
sinon.stub(console,"log");
|
||||
runtime.start().then(function() {
|
||||
console.log.restore();
|
||||
try {
|
||||
util.log.warn.neverCalledWithMatch("Failed to register 1 node type");
|
||||
util.log.warn.calledWithMatch("[errName] errored");
|
||||
log.warn.neverCalledWithMatch("Failed to register 1 node type");
|
||||
log.warn.calledWithMatch("[errName] errored");
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
@@ -204,21 +203,21 @@ describe("runtime", function() {
|
||||
it("reports runtime metrics",function(done) {
|
||||
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} );
|
||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {return []});
|
||||
var util = mockUtil(true);
|
||||
unmockUtil();
|
||||
mockUtil(true);
|
||||
runtime.init(
|
||||
{testSettings: true, runtimeMetricInterval:200, httpAdminRoot:"/", load:function() { return Promise.resolve();}},
|
||||
{},
|
||||
undefined,
|
||||
util);
|
||||
undefined);
|
||||
// sinon.stub(console,"log");
|
||||
runtime.start().then(function() {
|
||||
// console.log.restore();
|
||||
setTimeout(function() {
|
||||
try {
|
||||
util.log.log.args.should.have.lengthOf(3);
|
||||
util.log.log.args[0][0].should.have.property("event","runtime.memory.rss");
|
||||
util.log.log.args[1][0].should.have.property("event","runtime.memory.heapTotal");
|
||||
util.log.log.args[2][0].should.have.property("event","runtime.memory.heapUsed");
|
||||
log.log.args.should.have.lengthOf(3);
|
||||
log.log.args[0][0].should.have.property("event","runtime.memory.rss");
|
||||
log.log.args[1][0].should.have.property("event","runtime.memory.heapTotal");
|
||||
log.log.args[2][0].should.have.property("event","runtime.memory.heapUsed");
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var util = require("util");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -228,11 +227,11 @@ describe('red/runtime/nodes/credentials', function() {
|
||||
},
|
||||
set: function(key,value) {
|
||||
settings[key] = value;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
},
|
||||
delete: function(key) {
|
||||
delete settings[key];
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@
|
||||
var should = require("should");
|
||||
var fs = require('fs-extra');
|
||||
var path = require('path');
|
||||
var when = require("when");
|
||||
var sinon = require('sinon');
|
||||
var inherits = require("util").inherits;
|
||||
|
||||
@@ -47,11 +46,11 @@ describe("red/nodes/index", function() {
|
||||
var testCredentials = {"tab1":{"b":1, "c":"2", "d":"$(foo)"}};
|
||||
var storage = {
|
||||
getFlows: function() {
|
||||
return when({red:123,flows:testFlows,credentials:testCredentials});
|
||||
return Promise.resolve({red:123,flows:testFlows,credentials:testCredentials});
|
||||
},
|
||||
saveFlows: function(conf) {
|
||||
should.deepEqual(testFlows, conf.flows);
|
||||
return when.resolve(123);
|
||||
return Promise.resolve(123);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,12 +181,12 @@ describe("red/nodes/index", function() {
|
||||
fs.remove(userDir,function(err) {
|
||||
fs.mkdir(userDir,function() {
|
||||
sinon.stub(index, 'load', function() {
|
||||
return when.promise(function(resolve,reject){
|
||||
return new Promise(function(resolve,reject){
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
sinon.stub(localfilesystem, 'getCredentials', function() {
|
||||
return when.promise(function(resolve,reject) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
resolve({"tab1":{"b":1,"c":2}});
|
||||
});
|
||||
}) ;
|
||||
@@ -282,7 +281,7 @@ describe("red/nodes/index", function() {
|
||||
}
|
||||
});
|
||||
sinon.stub(registry,"disableNode",function(id) {
|
||||
return when.resolve(randomNodeInfo);
|
||||
return Promise.resolve(randomNodeInfo);
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
|
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
var when = require("when");
|
||||
var should = require("should");
|
||||
var paff = require('path');
|
||||
|
||||
@@ -79,16 +78,16 @@ describe("red/storage/index", function() {
|
||||
},
|
||||
getFlows : function() {
|
||||
calledFlagGetFlows = true;
|
||||
return when.resolve([]);
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
saveFlows : function (flows) {
|
||||
flows.should.be.an.Array();
|
||||
flows.should.have.lengthOf(0);
|
||||
return when.resolve("");
|
||||
return Promise.resolve("");
|
||||
},
|
||||
getCredentials : function() {
|
||||
calledFlagGetCredentials = true;
|
||||
return when.resolve({});
|
||||
return Promise.resolve({});
|
||||
},
|
||||
saveCredentials : function(credentials) {
|
||||
credentials.should.be.true();
|
||||
@@ -147,7 +146,7 @@ describe("red/storage/index", function() {
|
||||
storage.getLibraryEntry(true, "name");
|
||||
storage.saveLibraryEntry(true, "name", true, true);
|
||||
|
||||
when.settle(promises).then(function() {
|
||||
Promise.all(promises).then(function() {
|
||||
try {
|
||||
calledInit.should.be.true();
|
||||
calledFlagGetFlows.should.be.true();
|
||||
@@ -174,11 +173,11 @@ describe("red/storage/index", function() {
|
||||
getLibraryEntry : function(type, path) {
|
||||
if (type === "flows") {
|
||||
if (path === "/" || path === "\\") {
|
||||
return when.resolve(["a",{fn:"test.json"}]);
|
||||
return Promise.resolve(["a",{fn:"test.json"}]);
|
||||
} else if (path == "/a" || path == "\\a") {
|
||||
return when.resolve([{fn:"test2.json"}]);
|
||||
return Promise.resolve([{fn:"test2.json"}]);
|
||||
} else if (path == paff.join("","a","test2.json")) {
|
||||
return when.resolve("test content");
|
||||
return Promise.resolve("test content");
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -187,7 +186,7 @@ describe("red/storage/index", function() {
|
||||
savePath = path;
|
||||
saveContent = body;
|
||||
saveMeta = meta;
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -17,9 +17,9 @@ var should = require("should");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
describe("runtime/events", function() {
|
||||
describe("@node-red/util/events", function() {
|
||||
it('can be required without errors', function() {
|
||||
NR_TEST_UTILS.require("@node-red/runtime/lib/events");
|
||||
NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
});
|
||||
it.skip('more tests needed', function(){})
|
||||
});
|
@@ -16,30 +16,31 @@
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var events = require("events");
|
||||
var EventEmitter = require("events").EventEmitter;
|
||||
|
||||
|
||||
var child_process = require('child_process');
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
|
||||
var exec = NR_TEST_UTILS.require("@node-red/runtime/lib/exec");
|
||||
var events = NR_TEST_UTILS.require("@node-red/util/lib/events");
|
||||
var exec = NR_TEST_UTILS.require("@node-red/util/lib/exec");
|
||||
|
||||
describe("runtime/exec", function() {
|
||||
var logEvents;
|
||||
var mockProcess;
|
||||
const eventLogHandler = function(ev) {
|
||||
logEvents.push(ev);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
var logEventHandler = new events.EventEmitter();
|
||||
logEvents = [];
|
||||
logEventHandler.on('event-log', function(ev) {
|
||||
logEvents.push(ev);
|
||||
});
|
||||
exec.init({events:logEventHandler});
|
||||
|
||||
mockProcess = new events.EventEmitter();
|
||||
mockProcess.stdout = new events.EventEmitter();
|
||||
mockProcess.stderr = new events.EventEmitter();
|
||||
logEvents = [];
|
||||
events.on("event-log", eventLogHandler);
|
||||
|
||||
mockProcess = new EventEmitter();
|
||||
mockProcess.stdout = new EventEmitter();
|
||||
mockProcess.stderr = new EventEmitter();
|
||||
sinon.stub(child_process,'spawn',function(command,args,options) {
|
||||
mockProcess._args = {command,args,options};
|
||||
return mockProcess;
|
||||
@@ -47,6 +48,7 @@ describe("runtime/exec", function() {
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
events.removeListener("event-log", eventLogHandler);
|
||||
if (child_process.spawn.restore) {
|
||||
child_process.spawn.restore();
|
||||
}
|
Reference in New Issue
Block a user