Merge pull request #2922 from node-red/update-dependencies

Update dependencies
This commit is contained in:
Nick O'Leary 2021-04-15 14:57:07 +01:00 committed by GitHub
commit c021b4c368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 262 additions and 262 deletions

View File

@ -41,7 +41,7 @@
"denque": "1.5.0", "denque": "1.5.0",
"express": "4.17.1", "express": "4.17.1",
"express-session": "1.17.1", "express-session": "1.17.1",
"fs-extra": "8.1.0", "fs-extra": "9.1.0",
"fs.notify": "0.0.4", "fs.notify": "0.0.4",
"hash-sum": "2.0.0", "hash-sum": "2.0.0",
"https-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.0",
@ -71,14 +71,14 @@
"passport-oauth2-client-password": "0.1.2", "passport-oauth2-client-password": "0.1.2",
"raw-body": "2.4.1", "raw-body": "2.4.1",
"request": "2.88.0", "request": "2.88.0",
"semver": "6.3.0", "semver": "7.3.5",
"tar": "6.1.0", "tar": "6.1.0",
"uglify-js": "3.13.3", "uglify-js": "3.13.3",
"ws": "6.2.1", "ws": "6.2.1",
"xml2js": "0.4.23" "xml2js": "0.4.23"
}, },
"optionalDependencies": { "optionalDependencies": {
"bcrypt": "3.0.8" "bcrypt": "5.0.1"
}, },
"devDependencies": { "devDependencies": {
"dompurify": "2.2.7", "dompurify": "2.2.7",
@ -87,14 +87,14 @@
"grunt-cli": "~1.4.2", "grunt-cli": "~1.4.2",
"grunt-concurrent": "3.0.0", "grunt-concurrent": "3.0.0",
"grunt-contrib-clean": "~2.0.0", "grunt-contrib-clean": "~2.0.0",
"grunt-contrib-compress": "1.6.0", "grunt-contrib-compress": "2.0.0",
"grunt-contrib-concat": "~1.0.1", "grunt-contrib-concat": "~1.0.1",
"grunt-contrib-copy": "~1.0.0", "grunt-contrib-copy": "~1.0.0",
"grunt-contrib-jshint": "~2.1.0", "grunt-contrib-jshint": "3.0.0",
"grunt-contrib-uglify": "~4.0.1", "grunt-contrib-uglify": "5.0.1",
"grunt-contrib-watch": "~1.1.0", "grunt-contrib-watch": "~1.1.0",
"grunt-jsdoc": "2.4.1", "grunt-jsdoc": "2.4.1",
"grunt-jsdoc-to-markdown": "5.0.0", "grunt-jsdoc-to-markdown": "6.0.0",
"grunt-jsonlint": "2.1.3", "grunt-jsonlint": "2.1.3",
"grunt-mkdir": "~1.1.0", "grunt-mkdir": "~1.1.0",
"grunt-npm-command": "~0.1.2", "grunt-npm-command": "~0.1.2",
@ -105,14 +105,14 @@
"jsdoc-nr-template": "github:node-red/jsdoc-nr-template", "jsdoc-nr-template": "github:node-red/jsdoc-nr-template",
"marked": "2.0.1", "marked": "2.0.1",
"minami": "1.2.3", "minami": "1.2.3",
"mocha": "^5.2.0", "mocha": "8.3.2",
"node-red-node-test-helper": "^0.2.7", "node-red-node-test-helper": "^0.2.7",
"node-sass": "^5.0.0", "node-sass": "^5.0.0",
"nodemon": "2.0.7", "nodemon": "2.0.7",
"should": "13.2.3", "should": "13.2.3",
"sinon": "1.17.7", "sinon": "10.0.1",
"stoppable": "^1.1.0", "stoppable": "^1.1.0",
"supertest": "5.0.0" "supertest": "6.1.3"
}, },
"engines": { "engines": {
"node": ">=12" "node": ">=12"

View File

@ -24,7 +24,7 @@
"cors": "2.8.5", "cors": "2.8.5",
"cron": "1.7.2", "cron": "1.7.2",
"denque": "1.5.0", "denque": "1.5.0",
"fs-extra": "8.1.0", "fs-extra": "9.1.0",
"fs.notify": "0.0.4", "fs.notify": "0.0.4",
"hash-sum": "2.0.0", "hash-sum": "2.0.0",
"https-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.0",

View File

@ -17,7 +17,7 @@
], ],
"dependencies": { "dependencies": {
"@node-red/util": "2.0.0-beta.1", "@node-red/util": "2.0.0-beta.1",
"semver": "6.3.0", "semver": "7.3.5",
"tar": "6.1.0", "tar": "6.1.0",
"uglify-js": "3.13.3" "uglify-js": "3.13.3"
} }

View File

@ -21,7 +21,7 @@
"async-mutex": "0.3.1", "async-mutex": "0.3.1",
"clone": "2.1.2", "clone": "2.1.2",
"express": "4.17.1", "express": "4.17.1",
"fs-extra": "8.1.0", "fs-extra": "9.1.0",
"json-stringify-safe": "5.0.1" "json-stringify-safe": "5.0.1"
} }
} }

View File

@ -38,12 +38,12 @@
"basic-auth": "2.0.1", "basic-auth": "2.0.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"express": "4.17.1", "express": "4.17.1",
"fs-extra": "8.1.0", "fs-extra": "9.1.0",
"node-red-admin": "^0.2.6", "node-red-admin": "^0.2.6",
"node-red-node-rbe": "^0.5.0", "node-red-node-rbe": "^0.5.0",
"node-red-node-tail": "^0.3.0", "node-red-node-tail": "^0.3.0",
"nopt": "5.0.0", "nopt": "5.0.0",
"semver": "6.3.0" "semver": "7.3.5"
}, },
"optionalDependencies": { "optionalDependencies": {
"bcrypt": "3.0.6" "bcrypt": "3.0.6"

View File

@ -483,7 +483,7 @@ describe('trigger node', function() {
}); });
it('should be able to return things from flow and global context variables', function(done) { it('should be able to return things from flow and global context variables', function(done) {
var spy = sinon.stub(RED.util, 'evaluateNodeProperty', var spy = sinon.stub(RED.util, 'evaluateNodeProperty').callsFake(
function(arg1, arg2, arg3, arg4, arg5) { if (arg5) { arg5(null, arg1) } else { return arg1; } } function(arg1, arg2, arg3, arg4, arg5) { if (arg5) { arg5(null, arg1) } else { return arg1; } }
); );
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"flow", op2:"bar", op2type:"global", duration:"20", wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"flow", op2:"bar", op2type:"global", duration:"20", wires:[["n2"]] },
@ -742,7 +742,7 @@ describe('trigger node', function() {
it('should be able to extend the delay', function(done) { it('should be able to extend the delay', function(done) {
this.timeout(5000); // add extra time for flake this.timeout(5000); // add extra time for flake
var spy = sinon.stub(RED.util, 'evaluateNodeProperty', var spy = sinon.stub(RED.util, 'evaluateNodeProperty').callsFake(
function(arg1, arg2, arg3, arg4, arg5) { if (arg5) { arg5(null, arg1) } else { return arg1; } } function(arg1, arg2, arg3, arg4, arg5) { if (arg5) { arg5(null, arg1) } else { return arg1; } }
); );
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"flow", op1:"foo", op2:"bar", op2type:"global", duration:"100", wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", extend:"true", op1type:"flow", op1:"foo", op2:"bar", op2type:"global", duration:"100", wires:[["n2"]] },

View File

@ -53,7 +53,7 @@ describe('exec node', function() {
it('should exec a simple command', function(done) { it('should exec a simple command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:false, append:"", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:false, append:"", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
arg3(null,arg1,arg1.toUpperCase()); arg3(null,arg1,arg1.toUpperCase());
@ -137,7 +137,7 @@ describe('exec node', function() {
it('should exec a simple command with extra parameters', function(done) { it('should exec a simple command with extra parameters', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:"payload", append:"more", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:"payload", append:"more", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
//console.log(arg1); //console.log(arg1);
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
@ -193,7 +193,7 @@ describe('exec node', function() {
it('should be able to return a binary buffer', function(done) { it('should be able to return a binary buffer', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:true, append:"more", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:true, append:"more", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
//console.log(arg1); //console.log(arg1);
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
@ -325,7 +325,7 @@ describe('exec node', function() {
it('should return the rc for a failing command', function(done) { it('should return the rc for a failing command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:"", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:"", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
//console.log(arg1); //console.log(arg1);
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
@ -388,7 +388,7 @@ describe('exec node', function() {
it('should preserve existing properties on msg object', function(done) { it('should preserve existing properties on msg object', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:false, append:"", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"echo", addpay:false, append:"", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
arg3(null,arg1,arg1.toUpperCase()); arg3(null,arg1,arg1.toUpperCase());
@ -455,7 +455,7 @@ describe('exec node', function() {
it('should preserve existing properties on msg object for a failing command', function(done) { it('should preserve existing properties on msg object for a failing command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:"", oldrc:"false"}, var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:"", oldrc:"false"},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}]; {id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec', var spy = sinon.stub(child_process, 'exec').callsFake(
function(arg1, arg2, arg3, arg4) { function(arg1, arg2, arg3, arg4) {
// arg3(error,stdout,stderr); // arg3(error,stdout,stderr);
arg3({code: 1},arg1,arg1.toUpperCase()); arg3({code: 1},arg1,arg1.toUpperCase());

View File

@ -391,7 +391,7 @@ describe('file Nodes', function() {
it('should fail to write to a ro file', function(done) { it('should fail to write to a ro file', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var spy = sinon.stub(fs, 'createWriteStream', function(arg1,arg2) { var spy = sinon.stub(fs, 'createWriteStream').callsFake(function(arg1,arg2) {
var ws = {}; var ws = {};
ws.on = function(e,d) { throw("Stub error message"); } ws.on = function(e,d) { throw("Stub error message"); }
ws.write = function(e,d) { } ws.write = function(e,d) { }
@ -421,7 +421,7 @@ describe('file Nodes', function() {
it('should fail to append to a ro file', function(done) { it('should fail to append to a ro file', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var spy = sinon.stub(fs, 'createWriteStream', function(arg1,arg2) { var spy = sinon.stub(fs, 'createWriteStream').callsFake(function(arg1,arg2) {
var ws = {}; var ws = {};
ws.on = function(e,d) { throw("Stub error message"); } ws.on = function(e,d) { throw("Stub error message"); }
ws.write = function(e,d) { } ws.write = function(e,d) { }
@ -451,7 +451,7 @@ describe('file Nodes', function() {
it('should cope with failing to delete a file', function(done) { it('should cope with failing to delete a file', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var spy = sinon.stub(fs, 'unlink', function(arg,arg2) { arg2(new Error("Stub error message")); }); var spy = sinon.stub(fs, 'unlink').callsFake(function(arg,arg2) { arg2(new Error("Stub error message")); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":"delete"}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest, "appendNewline":true, "overwriteFile":"delete"}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
@ -477,7 +477,7 @@ describe('file Nodes', function() {
it('should fail to create a new directory if not asked to do so (append)', function(done) { it('should fail to create a new directory if not asked to do so (append)', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt"); var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt");
//var spy = sinon.stub(fs, 'appendFile', function(arg,arg2,arg3,arg4){ arg4(new Error("Stub error message")); }); //var spy = sinon.stub(fs, 'appendFile').callsFake(function(arg,arg2,arg3,arg4){ arg4(new Error("Stub error message")); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":false}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":false}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
@ -508,7 +508,7 @@ describe('file Nodes', function() {
} }
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt"); var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt");
var spy = sinon.stub(fs, "ensureDir", function(arg1,arg2,arg3,arg4) { arg2(null); }); var spy = sinon.stub(fs, "ensureDir").callsFake(function(arg1,arg2,arg3,arg4) { arg2(null); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":false, "createDir":true}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":false, "createDir":true}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
var n1 = helper.getNode("fileNode1"); var n1 = helper.getNode("fileNode1");
@ -531,7 +531,7 @@ describe('file Nodes', function() {
it('should fail to create a new directory if not asked to do so (overwrite)', function(done) { it('should fail to create a new directory if not asked to do so (overwrite)', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt"); var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt");
//var spy = sinon.stub(fs, 'appendFile', function(arg,arg2,arg3,arg4){ arg4(new Error("Stub error message")); }); //var spy = sinon.stub(fs, 'appendFile').callsFake(function(arg,arg2,arg3,arg4){ arg4(new Error("Stub error message")); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":false, "overwriteFile":true}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":false, "overwriteFile":true}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {
@ -557,7 +557,7 @@ describe('file Nodes', function() {
it('should try to create a new directory if asked to do so (overwrite)', function(done) { it('should try to create a new directory if asked to do so (overwrite)', function(done) {
// Stub file write so we can make writes fail // Stub file write so we can make writes fail
var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt"); var fileToTest2 = path.join(resourcesDir,"file-out-node","50-file-test-file.txt");
var spy = sinon.stub(fs, "ensureDir", function(arg1,arg2,arg3,arg4) { arg2(null); }); var spy = sinon.stub(fs, "ensureDir").callsFake(function(arg1,arg2,arg3,arg4) { arg2(null); });
var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":true, "createDir":true}]; var flow = [{id:"fileNode1", type:"file", name: "fileNode", "filename":fileToTest2, "appendNewline":true, "overwriteFile":true, "createDir":true}];
helper.load(fileNode, flow, function() { helper.load(fileNode, flow, function() {

View File

@ -45,35 +45,35 @@ describe("api/admin/index", function() {
}; };
before(function() { before(function() {
mockList.forEach(function(m) { mockList.forEach(function(m) {
sinon.stub(m,"init",function(){}); sinon.stub(m,"init").callsFake(function(){});
}); });
sinon.stub(auth,"needsPermission", function(permission) { sinon.stub(auth,"needsPermission").callsFake(function(permission) {
return function(req,res,next) { return function(req,res,next) {
permissionChecks[permission] = (permissionChecks[permission]||0)+1; permissionChecks[permission] = (permissionChecks[permission]||0)+1;
next(); next();
}; };
}); });
sinon.stub(flows,"get",stubApp); sinon.stub(flows,"get").callsFake(stubApp);
sinon.stub(flows,"post",stubApp); sinon.stub(flows,"post").callsFake(stubApp);
sinon.stub(flow,"get",stubApp); sinon.stub(flow,"get").callsFake(stubApp);
sinon.stub(flow,"post",stubApp); sinon.stub(flow,"post").callsFake(stubApp);
sinon.stub(flow,"delete",stubApp); sinon.stub(flow,"delete").callsFake(stubApp);
sinon.stub(flow,"put",stubApp); sinon.stub(flow,"put").callsFake(stubApp);
sinon.stub(nodes,"getAll",stubApp); sinon.stub(nodes,"getAll").callsFake(stubApp);
sinon.stub(nodes,"post",stubApp); sinon.stub(nodes,"post").callsFake(stubApp);
sinon.stub(nodes,"getModule",stubApp); sinon.stub(nodes,"getModule").callsFake(stubApp);
sinon.stub(nodes,"putModule",stubApp); sinon.stub(nodes,"putModule").callsFake(stubApp);
sinon.stub(nodes,"delete",stubApp); sinon.stub(nodes,"delete").callsFake(stubApp);
sinon.stub(nodes,"getSet",stubApp); sinon.stub(nodes,"getSet").callsFake(stubApp);
sinon.stub(nodes,"putSet",stubApp); sinon.stub(nodes,"putSet").callsFake(stubApp);
sinon.stub(nodes,"getModuleCatalog",stubApp); sinon.stub(nodes,"getModuleCatalog").callsFake(stubApp);
sinon.stub(nodes,"getModuleCatalogs",stubApp); sinon.stub(nodes,"getModuleCatalogs").callsFake(stubApp);
sinon.stub(context,"get",stubApp); sinon.stub(context,"get").callsFake(stubApp);
sinon.stub(context,"delete",stubApp); sinon.stub(context,"delete").callsFake(stubApp);
}); });
after(function() { after(function() {
mockList.forEach(function(m) { mockList.forEach(function(m) {

View File

@ -41,7 +41,7 @@ describe("api/admin/nodes", function() {
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet); app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet);
app.get("/getIcons",nodes.getIcons); app.get("/getIcons",nodes.getIcons);
app.delete(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.delete); app.delete(/\/nodes\/((@[^\/]+\/)?[^\/]+)$/,nodes.delete);
sinon.stub(apiUtil,"determineLangFromHeaders", function() { sinon.stub(apiUtil,"determineLangFromHeaders").callsFake(function() {
return "en-US"; return "en-US";
}); });
}); });

View File

@ -29,7 +29,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
describe("api/editor/settings", function() { describe("api/editor/settings", function() {
before(function() { before(function() {
sinon.stub(theme,"settings",function() { return { existing: 123, test: 456 };}); sinon.stub(theme,"settings").callsFake(function() { return { existing: 123, test: 456 };});
app = express(); app = express();
app.use(bodyParser.json()); app.use(bodyParser.json());
app.get("/settings",info.runtimeSettings); app.get("/settings",info.runtimeSettings);

View File

@ -58,7 +58,7 @@ describe("api/auth/index",function() {
describe("revoke", function() { describe("revoke", function() {
it("revokes a token", function(done) { it("revokes a token", function(done) {
var revokeToken = sinon.stub(Tokens,"revoke",function() { var revokeToken = sinon.stub(Tokens,"revoke").callsFake(function() {
return Promise.resolve(); return Promise.resolve();
}); });
@ -79,8 +79,8 @@ describe("api/auth/index",function() {
describe("login", function() { describe("login", function() {
beforeEach(function() { beforeEach(function() {
sinon.stub(Tokens,"init",function(){}); sinon.stub(Tokens,"init").callsFake(function(){});
sinon.stub(Users,"init",function(){}); sinon.stub(Users,"init").callsFake(function(){});
}); });
afterEach(function() { afterEach(function() {
Tokens.init.restore(); Tokens.init.restore();
@ -119,8 +119,8 @@ describe("api/auth/index",function() {
}); });
describe("needsPermission", function() { describe("needsPermission", function() {
beforeEach(function() { beforeEach(function() {
sinon.stub(Tokens,"init",function(){}); sinon.stub(Tokens,"init").callsFake(function(){});
sinon.stub(Users,"init",function(){}); sinon.stub(Users,"init").callsFake(function(){});
}); });
afterEach(function() { afterEach(function() {
Tokens.init.restore(); Tokens.init.restore();
@ -135,7 +135,7 @@ describe("api/auth/index",function() {
it('no-ops if adminAuth not set', function(done) { it('no-ops if adminAuth not set', function(done) {
sinon.stub(passport,"authenticate",function(scopes,opts) { sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
return function(req,res,next) { return function(req,res,next) {
} }
}); });
@ -147,12 +147,12 @@ describe("api/auth/index",function() {
}) })
}); });
it('skips auth if req.user undefined', function(done) { it('skips auth if req.user undefined', function(done) {
sinon.stub(passport,"authenticate",function(scopes,opts) { sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
return function(req,res,next) { return function(req,res,next) {
next(); next();
} }
}); });
sinon.stub(Permissions,"hasPermission",function(perm) { return true }); sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return true });
auth.init({adminAuth:{}}); auth.init({adminAuth:{}});
var func = auth.needsPermission("foo"); var func = auth.needsPermission("foo");
func({user:null},{},function() { func({user:null},{},function() {
@ -167,12 +167,12 @@ describe("api/auth/index",function() {
}); });
it('passes for valid user permission', function(done) { it('passes for valid user permission', function(done) {
sinon.stub(passport,"authenticate",function(scopes,opts) { sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
return function(req,res,next) { return function(req,res,next) {
next(); next();
} }
}); });
sinon.stub(Permissions,"hasPermission",function(perm) { return true }); sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return true });
auth.init({adminAuth:{}}); auth.init({adminAuth:{}});
var func = auth.needsPermission("foo"); var func = auth.needsPermission("foo");
func({user:true,authInfo: { scope: "read"}},{},function() { func({user:true,authInfo: { scope: "read"}},{},function() {
@ -189,12 +189,12 @@ describe("api/auth/index",function() {
}); });
it('rejects for invalid user permission', function(done) { it('rejects for invalid user permission', function(done) {
sinon.stub(passport,"authenticate",function(scopes,opts) { sinon.stub(passport,"authenticate").callsFake(function(scopes,opts) {
return function(req,res,next) { return function(req,res,next) {
next(); next();
} }
}); });
sinon.stub(Permissions,"hasPermission",function(perm) { return false }); sinon.stub(Permissions,"hasPermission").callsFake(function(perm) { return false });
auth.init({adminAuth:{}}); auth.init({adminAuth:{}});
var func = auth.needsPermission("foo"); var func = auth.needsPermission("foo");
func({user:true,authInfo: { scope: "read"}},{ func({user:true,authInfo: { scope: "read"}},{

View File

@ -35,7 +35,7 @@ describe("api/auth/strategies", function() {
}); });
it('Handles authentication failure',function(done) { it('Handles authentication failure',function(done) {
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) { userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
return Promise.resolve(null); return Promise.resolve(null);
}); });
@ -51,7 +51,7 @@ describe("api/auth/strategies", function() {
}); });
it('Handles scope overreach',function(done) { it('Handles scope overreach',function(done) {
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) { userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
return Promise.resolve({username:"user",permissions:"read"}); return Promise.resolve({username:"user",permissions:"read"});
}); });
@ -67,11 +67,11 @@ describe("api/auth/strategies", function() {
}); });
it('Creates new token on authentication success',function(done) { it('Creates new token on authentication success',function(done) {
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) { userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
return Promise.resolve({username:"user",permissions:"*"}); return Promise.resolve({username:"user",permissions:"*"});
}); });
var tokenDetails = {}; var tokenDetails = {};
var tokenCreate = sinon.stub(Tokens,"create",function(username,client,scope) { var tokenCreate = sinon.stub(Tokens,"create").callsFake(function(username,client,scope) {
tokenDetails.username = username; tokenDetails.username = username;
tokenDetails.client = client; tokenDetails.client = client;
tokenDetails.scope = scope; tokenDetails.scope = scope;
@ -98,7 +98,7 @@ describe("api/auth/strategies", function() {
describe("Anonymous Strategy", function() { describe("Anonymous Strategy", function() {
it('Succeeds if anon user enabled',function(done) { it('Succeeds if anon user enabled',function(done) {
var userDefault = sinon.stub(Users,"default",function() { var userDefault = sinon.stub(Users,"default").callsFake(function() {
return Promise.resolve("anon"); return Promise.resolve("anon");
}); });
strategies.anonymousStrategy._success = strategies.anonymousStrategy.success; strategies.anonymousStrategy._success = strategies.anonymousStrategy.success;
@ -111,7 +111,7 @@ describe("api/auth/strategies", function() {
strategies.anonymousStrategy.authenticate({}); strategies.anonymousStrategy.authenticate({});
}); });
it('Fails if anon user not enabled',function(done) { it('Fails if anon user not enabled',function(done) {
var userDefault = sinon.stub(Users,"default",function() { var userDefault = sinon.stub(Users,"default").callsFake(function() {
return Promise.resolve(null); return Promise.resolve(null);
}); });
strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail; strategies.anonymousStrategy._fail = strategies.anonymousStrategy.fail;
@ -130,10 +130,10 @@ describe("api/auth/strategies", function() {
describe("Tokens Strategy", function() { describe("Tokens Strategy", function() {
it('Succeeds if tokens user enabled custom header',function(done) { it('Succeeds if tokens user enabled custom header',function(done) {
var userTokens = sinon.stub(Users,"tokens",function(token) { var userTokens = sinon.stub(Users,"tokens").callsFake(function(token) {
return Promise.resolve("tokens-"+token); return Promise.resolve("tokens-"+token);
}); });
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) { var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
return "x-test-token"; return "x-test-token";
}); });
strategies.tokensStrategy._success = strategies.tokensStrategy.success; strategies.tokensStrategy._success = strategies.tokensStrategy.success;
@ -146,10 +146,10 @@ describe("api/auth/strategies", function() {
strategies.tokensStrategy.authenticate({headers:{"x-test-token":"1234"}}); strategies.tokensStrategy.authenticate({headers:{"x-test-token":"1234"}});
}); });
it('Succeeds if tokens user enabled default header',function(done) { it('Succeeds if tokens user enabled default header',function(done) {
var userTokens = sinon.stub(Users,"tokens",function(token) { var userTokens = sinon.stub(Users,"tokens").callsFake(function(token) {
return Promise.resolve("tokens-"+token); return Promise.resolve("tokens-"+token);
}); });
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) { var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
return "authorization"; return "authorization";
}); });
strategies.tokensStrategy._success = strategies.tokensStrategy.success; strategies.tokensStrategy._success = strategies.tokensStrategy.success;
@ -162,10 +162,10 @@ describe("api/auth/strategies", function() {
strategies.tokensStrategy.authenticate({headers:{"authorization":"Bearer 1234"}}); strategies.tokensStrategy.authenticate({headers:{"authorization":"Bearer 1234"}});
}); });
it('Fails if tokens user not enabled',function(done) { it('Fails if tokens user not enabled',function(done) {
var userTokens = sinon.stub(Users,"tokens",function() { var userTokens = sinon.stub(Users,"tokens").callsFake(function() {
return Promise.resolve(null); return Promise.resolve(null);
}); });
var userTokenHeader = sinon.stub(Users,"tokenHeader",function(token) { var userTokenHeader = sinon.stub(Users,"tokenHeader").callsFake(function(token) {
return "authorization"; return "authorization";
}); });
strategies.tokensStrategy._fail = strategies.tokensStrategy.fail; strategies.tokensStrategy._fail = strategies.tokensStrategy.fail;
@ -185,7 +185,7 @@ describe("api/auth/strategies", function() {
describe("Bearer Strategy", function() { describe("Bearer Strategy", function() {
it('Rejects invalid token',function(done) { it('Rejects invalid token',function(done) {
var getToken = sinon.stub(Tokens,"get",function(token) { var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
return Promise.resolve(null); return Promise.resolve(null);
}); });
@ -202,10 +202,10 @@ describe("api/auth/strategies", function() {
}); });
}); });
it('Accepts valid token',function(done) { it('Accepts valid token',function(done) {
var getToken = sinon.stub(Tokens,"get",function(token) { var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
return Promise.resolve({user:"user",scope:"scope"}); return Promise.resolve({user:"user",scope:"scope"});
}); });
var getUser = sinon.stub(Users,"get",function(username) { var getUser = sinon.stub(Users,"get").callsFake(function(username) {
return Promise.resolve("aUser"); return Promise.resolve("aUser");
}); });
@ -224,10 +224,10 @@ describe("api/auth/strategies", function() {
}); });
}); });
it('Fail if no user for token',function(done) { it('Fail if no user for token',function(done) {
var getToken = sinon.stub(Tokens,"get",function(token) { var getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
return Promise.resolve({user:"user",scope:"scope"}); return Promise.resolve({user:"user",scope:"scope"});
}); });
var getUser = sinon.stub(Users,"get",function(username) { var getUser = sinon.stub(Users,"get").callsFake(function(username) {
return Promise.resolve(null); return Promise.resolve(null);
}); });
@ -250,7 +250,7 @@ describe("api/auth/strategies", function() {
describe("Client Password Strategy", function() { describe("Client Password Strategy", function() {
it('Accepts valid client',function(done) { it('Accepts valid client',function(done) {
var testClient = {id:"node-red-editor",secret:"not_available"}; var testClient = {id:"node-red-editor",secret:"not_available"};
var getClient = sinon.stub(Clients,"get",function(client) { var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
return Promise.resolve(testClient); return Promise.resolve(testClient);
}); });
@ -268,7 +268,7 @@ describe("api/auth/strategies", function() {
}); });
it('Rejects invalid client secret',function(done) { it('Rejects invalid client secret',function(done) {
var testClient = {id:"node-red-editor",secret:"not_available"}; var testClient = {id:"node-red-editor",secret:"not_available"};
var getClient = sinon.stub(Clients,"get",function(client) { var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
return Promise.resolve(testClient); return Promise.resolve(testClient);
}); });
@ -285,7 +285,7 @@ describe("api/auth/strategies", function() {
}); });
}); });
it('Rejects invalid client id',function(done) { it('Rejects invalid client id',function(done) {
var getClient = sinon.stub(Clients,"get",function(client) { var getClient = sinon.stub(Clients,"get").callsFake(function(client) {
return Promise.resolve(null); return Promise.resolve(null);
}); });
strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) { strategies.clientPasswordStrategy("invalid_id","invalid_secret",function(err,client) {
@ -303,7 +303,7 @@ describe("api/auth/strategies", function() {
var userAuthentication; var userAuthentication;
it('Blocks after 5 failures',function(done) { it('Blocks after 5 failures',function(done) {
userAuthentication = sinon.stub(Users,"authenticate",function(username,password) { userAuthentication = sinon.stub(Users,"authenticate").callsFake(function(username,password) {
return Promise.resolve(null); return Promise.resolve(null);
}); });
for (var z=0; z<5; z++) { for (var z=0; z<5; z++) {

View File

@ -58,7 +58,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {}, {comms: mockComms}); comms.init(server, {}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -126,7 +126,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {disableEditor:true}, {comms: mockComms}); comms.init(server, {disableEditor:true}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -164,7 +164,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms}); comms.init(server, {httpAdminRoot:"/adminPath"}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -202,7 +202,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms}); comms.init(server, {httpAdminRoot:"/adminPath/"}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -240,7 +240,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms}); comms.init(server, {httpAdminRoot:"adminPath"}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -278,7 +278,7 @@ describe("api/editor/comms", function() {
var url; var url;
var port; var port;
before(function(done) { before(function(done) {
sinon.stub(Users,"default",function() { return Promise.resolve(null);}); sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms}); comms.init(server, {webSocketKeepAliveTime: 100}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);
@ -344,22 +344,22 @@ describe("api/editor/comms", function() {
var getToken; var getToken;
var getUserToken; var getUserToken;
before(function(done) { before(function(done) {
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve(null);}); getDefaultUser = sinon.stub(Users,"default").callsFake(function() { return Promise.resolve(null);});
getUser = sinon.stub(Users,"get", function(username) { getUser = sinon.stub(Users,"get").callsFake(function(username) {
if (username == "fred") { if (username == "fred") {
return Promise.resolve({permissions:"read"}); return Promise.resolve({permissions:"read"});
} else { } else {
return Promise.resolve(null); return Promise.resolve(null);
} }
}); });
getUserToken = sinon.stub(Users,"tokens", function(token) { getUserToken = sinon.stub(Users,"tokens").callsFake(function(token) {
if (token == "abcde") { if (token == "abcde") {
return Promise.resolve({user:"wilma", permissions:"*"}) return Promise.resolve({user:"wilma", permissions:"*"})
} else { } else {
return Promise.resolve(null); return Promise.resolve(null);
} }
}); });
getToken = sinon.stub(Tokens,"get",function(token) { getToken = sinon.stub(Tokens,"get").callsFake(function(token) {
if (token == "1234") { if (token == "1234") {
return Promise.resolve({user:"fred",scope:["*"]}); return Promise.resolve({user:"fred",scope:["*"]});
} else if (token == "5678") { } else if (token == "5678") {
@ -483,7 +483,7 @@ describe("api/editor/comms", function() {
var port; var port;
var getDefaultUser; var getDefaultUser;
before(function(done) { before(function(done) {
getDefaultUser = sinon.stub(Users,"default",function() { return Promise.resolve({permissions:"read"});}); getDefaultUser = sinon.stub(Users,"default").callsFake(function() { return Promise.resolve({permissions:"read"});});
server = stoppable(http.createServer(function(req,res){app(req,res)})); server = stoppable(http.createServer(function(req,res){app(req,res)}));
comms.init(server, {adminAuth:{}}, {comms: mockComms}); comms.init(server, {adminAuth:{}}, {comms: mockComms});
server.listen(listenPort, address); server.listen(listenPort, address);

View File

@ -32,8 +32,8 @@ describe("api/editor/index", function() {
var app; var app;
describe("disabled the editor", function() { describe("disabled the editor", function() {
beforeEach(function() { beforeEach(function() {
sinon.stub(comms,'init', function(){}); sinon.stub(comms,'init').callsFake(function(){});
sinon.stub(info,'init', function(){}); sinon.stub(info,'init').callsFake(function(){});
}); });
afterEach(function() { afterEach(function() {
comms.init.restore(); comms.init.restore();
@ -54,13 +54,13 @@ describe("api/editor/index", function() {
var errors = []; var errors = [];
var session_data = {}; var session_data = {};
before(function() { before(function() {
sinon.stub(auth,'needsPermission',function(permission) { sinon.stub(auth,'needsPermission').callsFake(function(permission) {
return function(req,res,next) { next(); } return function(req,res,next) { next(); }
}); });
mockList.forEach(function(m) { mockList.forEach(function(m) {
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/"+m),"init",function(){}); sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/"+m),"init").callsFake(function(){});
}); });
sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme"),"app",function(){ return express()}); sinon.stub(NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme"),"app").callsFake(function(){ return express()});
}); });
after(function() { after(function() {
mockList.forEach(function(m) { mockList.forEach(function(m) {
@ -72,7 +72,7 @@ describe("api/editor/index", function() {
}); });
before(function() { before(function() {
sinon.stub(log,"error",function(err) { errors.push(err)}) sinon.stub(log,"error").callsFake(function(err) { errors.push(err)})
app = editorApi.init({},{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}},{ app = editorApi.init({},{httpNodeRoot:true, httpAdminRoot: true,disableEditor:false,exportNodeSettings:function(){}},{
isStarted: () => Promise.resolve(isStarted) isStarted: () => Promise.resolve(isStarted)
}); });

View File

@ -50,9 +50,9 @@ describe("api/editor/locales", function() {
locales.init({}); locales.init({});
// bit of a mess of internal workings // bit of a mess of internal workings
sinon.stub(i18n.i,'changeLanguage',function(lang,callback) { if (callback) {callback();}}); sinon.stub(i18n.i,'changeLanguage').callsFake(function(lang,callback) { if (callback) {callback();}});
if (i18n.i.getResourceBundle) { if (i18n.i.getResourceBundle) {
sinon.stub(i18n.i,'getResourceBundle',function(lang, namespace) {return {namespace:namespace, lang:lang};}); sinon.stub(i18n.i,'getResourceBundle').callsFake(function(lang, namespace) {return {namespace:namespace, lang:lang};});
} else { } else {
// If i18n.init has not been called, then getResourceBundle isn't // If i18n.init has not been called, then getResourceBundle isn't
// defined - so hardcode a stub // defined - so hardcode a stub
@ -121,7 +121,7 @@ describe("api/editor/locales", function() {
// var app; // var app;
// before(function() { // before(function() {
// // bit of a mess of internal workings // // bit of a mess of internal workings
// sinon.stub(i18n,'catalog',function(namespace, lang) { // sinon.stub(i18n,'catalog').callsFake(function(namespace, lang) {
// return { // return {
// "node-red": "should not return", // "node-red": "should not return",
// "test-module-a-id": "test-module-a-catalog", // "test-module-a-id": "test-module-a-catalog",

View File

@ -29,7 +29,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
describe("api/editor/settings", function() { describe("api/editor/settings", function() {
before(function() { before(function() {
sinon.stub(theme,"settings",function() { return { existing: 123, test: 456 };}); sinon.stub(theme,"settings").callsFake(function() { return { existing: 123, test: 456 };});
app = express(); app = express();
app.use(bodyParser.json()); app.use(bodyParser.json());
app.get("/settings/user",function(req,res,next) {req.user = "fred"; next()}, info.userSettings); app.get("/settings/user",function(req,res,next) {req.user = "fred"; next()}, info.userSettings);

View File

@ -27,7 +27,7 @@ var theme = NR_TEST_UTILS.require("@node-red/editor-api/lib/editor/theme");
describe("api/editor/theme", function () { describe("api/editor/theme", function () {
beforeEach(function () { beforeEach(function () {
sinon.stub(fs, "statSync", function () { return true; }); sinon.stub(fs, "statSync").callsFake(function () { return true; });
}); });
afterEach(function () { afterEach(function () {
theme.init({settings: {}}); theme.init({settings: {}});

View File

@ -31,18 +31,18 @@ var apiAdmin = NR_TEST_UTILS.require("@node-red/editor-api/lib/admin");
describe("api/index", function() { describe("api/index", function() {
var beforeEach = function() { var beforeEach = function() {
sinon.stub(apiAuth,"init",function(){}); sinon.stub(apiAuth,"init").callsFake(function(){});
sinon.stub(apiEditor,"init",function(){ sinon.stub(apiEditor,"init").callsFake(function(){
var app = express(); var app = express();
app.get("/editor",function(req,res) { res.status(200).end(); }); app.get("/editor",function(req,res) { res.status(200).end(); });
return app; return app;
}); });
sinon.stub(apiAdmin,"init",function(){ sinon.stub(apiAdmin,"init").callsFake(function(){
var app = express(); var app = express();
app.get("/admin",function(req,res) { res.status(200).end(); }); app.get("/admin",function(req,res) { res.status(200).end(); });
return app; return app;
}); });
sinon.stub(apiAuth,"login",function(req,res){ sinon.stub(apiAuth,"login").callsFake(function(req,res){
res.status(200).end(); res.status(200).end();
}); });
}; };
@ -115,7 +115,7 @@ describe("api/index", function() {
describe('initialises api with authentication enabled', function(done) { describe('initialises api with authentication enabled', function(done) {
it('enables an oauth/openID based authentication mechanism',function(done) { it('enables an oauth/openID based authentication mechanism',function(done) {
const stub = sinon.stub(apiAuth, 'genericStrategy', function(){}); const stub = sinon.stub(apiAuth, 'genericStrategy').callsFake(function(){});
const adminAuth = { type: 'strategy', strategy: {} } const adminAuth = { type: 'strategy', strategy: {} }
api.init({ httpAdminRoot: true, adminAuth },{},{},{}); api.init({ httpAdminRoot: true, adminAuth },{},{},{});
should(stub.called).be.ok(); should(stub.called).be.ok();
@ -159,7 +159,7 @@ describe("api/index", function() {
describe('editor start', function (done) { describe('editor start', function (done) {
it('cannot be started when editor is disabled', function (done) { it('cannot be started when editor is disabled', function (done) {
const stub = sinon.stub(apiEditor, 'start', function () { const stub = sinon.stub(apiEditor, 'start').callsFake(function () {
return Promise.resolve(true); return Promise.resolve(true);
}); });
api.init({ httpAdminRoot: true, disableEditor: true }, {}, {}, {}); api.init({ httpAdminRoot: true, disableEditor: true }, {}, {}, {});

View File

@ -33,8 +33,8 @@ describe("api/util", function() {
var app; var app;
before(function() { before(function() {
app = express(); app = express();
sinon.stub(log,'error',function(msg) {loggedError = msg;}); sinon.stub(log,'error').callsFake(function(msg) {loggedError = msg;});
sinon.stub(log,'audit',function(event) {loggedEvent = event;}); sinon.stub(log,'audit').callsFake(function(event) {loggedEvent = event;});
app.get("/tooLarge", function(req,res) { app.get("/tooLarge", function(req,res) {
var err = new Error(); var err = new Error();
err.message = "request entity too large"; err.message = "request entity too large";

View File

@ -44,7 +44,7 @@ describe("externalModules api", function() {
}) })
describe("checkFlowDependencies", function() { describe("checkFlowDependencies", function() {
beforeEach(function() { beforeEach(function() {
sinon.stub(exec,"run", async function(cmd, args, options) { sinon.stub(exec,"run").callsFake(async function(cmd, args, options) {
let error; let error;
if (args[1] === "moduleNotFound") { if (args[1] === "moduleNotFound") {
error = new Error(); error = new Error();

View File

@ -49,10 +49,10 @@ describe('red/registry/index', function() {
describe('#addModule', function() { describe('#addModule', function() {
it('loads the module and returns its info', function(done) { it('loads the module and returns its info', function(done) {
stubs.push(sinon.stub(loader,"addModule",function(module) { stubs.push(sinon.stub(loader,"addModule").callsFake(function(module) {
return Promise.resolve(); return Promise.resolve();
})); }));
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) { stubs.push(sinon.stub(typeRegistry,"getModuleInfo").callsFake(function(module) {
return "info"; return "info";
})); }));
registry.addModule("foo").then(function(info) { registry.addModule("foo").then(function(info) {
@ -61,10 +61,10 @@ describe('red/registry/index', function() {
}).catch(function(err) { done(err); }); }).catch(function(err) { done(err); });
}); });
it('rejects if loader rejects', function(done) { it('rejects if loader rejects', function(done) {
stubs.push(sinon.stub(loader,"addModule",function(module) { stubs.push(sinon.stub(loader,"addModule").callsFake(function(module) {
return Promise.reject("error"); return Promise.reject("error");
})); }));
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) { stubs.push(sinon.stub(typeRegistry,"getModuleInfo").callsFake(function(module) {
return "info"; return "info";
})); }));
registry.addModule("foo").then(function(info) { registry.addModule("foo").then(function(info) {
@ -78,10 +78,10 @@ describe('red/registry/index', function() {
describe('#enableNode',function() { describe('#enableNode',function() {
it('enables a node set',function(done) { it('enables a node set',function(done) {
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() { stubs.push(sinon.stub(typeRegistry,"enableNodeSet").callsFake(function() {
return Promise.resolve(); return Promise.resolve();
})); }));
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() { stubs.push(sinon.stub(typeRegistry,"getNodeInfo").callsFake(function() {
return {id:"node-set",loaded:true}; return {id:"node-set",loaded:true};
})); }));
registry.enableNode("node-set").then(function(ns) { registry.enableNode("node-set").then(function(ns) {
@ -92,7 +92,7 @@ describe('red/registry/index', function() {
}); });
it('rejects if node unknown',function() { it('rejects if node unknown',function() {
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() { stubs.push(sinon.stub(typeRegistry,"enableNodeSet").callsFake(function() {
throw new Error('failure'); throw new Error('failure');
})); }));
/*jshint immed: false */ /*jshint immed: false */
@ -102,15 +102,15 @@ describe('red/registry/index', function() {
}); });
it('triggers a node load',function(done) { it('triggers a node load',function(done) {
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() { stubs.push(sinon.stub(typeRegistry,"enableNodeSet").callsFake(function() {
return Promise.resolve(); return Promise.resolve();
})); }));
var calls = 0; var calls = 0;
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() { stubs.push(sinon.stub(typeRegistry,"getNodeInfo").callsFake(function() {
// loaded=false on first call, true on subsequent // loaded=false on first call, true on subsequent
return {id:"node-set",loaded:(calls++>0)}; return {id:"node-set",loaded:(calls++>0)};
})); }));
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return Promise.resolve();})); stubs.push(sinon.stub(loader,"loadNodeSet").callsFake(function(){return Promise.resolve();}));
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo")); stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
registry.enableNode("node-set").then(function(ns) { registry.enableNode("node-set").then(function(ns) {

View File

@ -42,7 +42,7 @@ describe('nodes/registry/installer', function() {
var execResponse; var execResponse;
beforeEach(function() { beforeEach(function() {
sinon.stub(exec,"run", () => execResponse || Promise.resolve("")) sinon.stub(exec,"run").callsFake(() => execResponse || Promise.resolve(""))
installer.init({}) installer.init({})
}); });
@ -118,7 +118,7 @@ describe('nodes/registry/installer', function() {
var p = Promise.reject(res); var p = Promise.reject(res);
p.catch((err)=>{}); p.catch((err)=>{});
execResponse = p; execResponse = p;
sinon.stub(typeRegistry,"getModuleInfo", function() { sinon.stub(typeRegistry,"getModuleInfo").callsFake(function() {
return { return {
version: "0.1.1" version: "0.1.1"
} }
@ -129,7 +129,7 @@ describe('nodes/registry/installer', function() {
}).catch(done); }).catch(done);
}); });
it("rejects when update requested to existing version", function(done) { it("rejects when update requested to existing version", function(done) {
sinon.stub(typeRegistry,"getModuleInfo", function() { sinon.stub(typeRegistry,"getModuleInfo").callsFake(function() {
return { return {
user: true, user: true,
version: "0.1.1" version: "0.1.1"
@ -141,7 +141,7 @@ describe('nodes/registry/installer', function() {
}).catch(done); }).catch(done);
}); });
it("rejects when update requested to existing version and url", function(done) { it("rejects when update requested to existing version and url", function(done) {
sinon.stub(typeRegistry,"getModuleInfo", function() { sinon.stub(typeRegistry,"getModuleInfo").callsFake(function() {
return { return {
user: true, user: true,
version: "0.1.1" version: "0.1.1"
@ -180,7 +180,7 @@ describe('nodes/registry/installer', function() {
p.catch((err)=>{}); p.catch((err)=>{});
execResponse = p; execResponse = p;
var addModule = sinon.stub(registry,"addModule",function(md) { var addModule = sinon.stub(registry,"addModule").callsFake(function(md) {
return Promise.resolve(nodeInfo); return Promise.resolve(nodeInfo);
}); });
@ -211,7 +211,7 @@ describe('nodes/registry/installer', function() {
}); });
it("succeeds when path is valid node-red module", function(done) { it("succeeds when path is valid node-red module", function(done) {
var nodeInfo = {nodes:{module:"foo",types:["a"]}}; var nodeInfo = {nodes:{module:"foo",types:["a"]}};
var addModule = sinon.stub(registry,"addModule",function(md) { var addModule = sinon.stub(registry,"addModule").callsFake(function(md) {
return Promise.resolve(nodeInfo); return Promise.resolve(nodeInfo);
}); });
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule")); var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
@ -241,7 +241,7 @@ describe('nodes/registry/installer', function() {
p.catch((err)=>{}); p.catch((err)=>{});
execResponse = p; execResponse = p;
var addModule = sinon.stub(registry,"addModule",function(md) { var addModule = sinon.stub(registry,"addModule").callsFake(function(md) {
return Promise.resolve(nodeInfo); return Promise.resolve(nodeInfo);
}); });
@ -267,7 +267,7 @@ describe('nodes/registry/installer', function() {
it("rejects with generic error", function(done) { it("rejects with generic error", function(done) {
var nodeInfo = [{module:"foo",types:["a"]}]; var nodeInfo = [{module:"foo",types:["a"]}];
var removeModule = sinon.stub(registry,"removeModule",function(md) { var removeModule = sinon.stub(registry,"removeModule").callsFake(function(md) {
return Promise.resolve(nodeInfo); return Promise.resolve(nodeInfo);
}); });
var res = { var res = {
@ -288,10 +288,10 @@ describe('nodes/registry/installer', function() {
}); });
it("succeeds when module is found", function(done) { it("succeeds when module is found", function(done) {
var nodeInfo = [{module:"foo",types:["a"]}]; var nodeInfo = [{module:"foo",types:["a"]}];
var removeModule = sinon.stub(typeRegistry,"removeModule",function(md) { var removeModule = sinon.stub(typeRegistry,"removeModule").callsFake(function(md) {
return nodeInfo; return nodeInfo;
}); });
var getModuleInfo = sinon.stub(registry,"getModuleInfo",function(md) { var getModuleInfo = sinon.stub(registry,"getModuleInfo").callsFake(function(md) {
return {nodes:[]}; return {nodes:[]};
}); });
var res = { var res = {
@ -303,7 +303,7 @@ describe('nodes/registry/installer', function() {
p.catch((err)=>{}); p.catch((err)=>{});
execResponse = p; execResponse = p;
sinon.stub(fs,"statSync", function(fn) { return {}; }); sinon.stub(fs,"statSync").callsFake(function(fn) { return {}; });
installer.uninstallModule("this_wont_exist").then(function(info) { installer.uninstallModule("this_wont_exist").then(function(info) {
info.should.eql(nodeInfo); info.should.eql(nodeInfo);

View File

@ -46,8 +46,8 @@ describe("red/nodes/registry/loader",function() {
describe("#load",function() { describe("#load",function() {
it("load empty set without settings available", function(done) { it("load empty set without settings available", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};})); stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){ return {};}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return {};}));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return false;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return false;}}});
loader.load(true).then(function() { loader.load(true).then(function() {
localfilesystem.getNodeFiles.called.should.be.true(); localfilesystem.getNodeFiles.called.should.be.true();
@ -57,8 +57,8 @@ describe("red/nodes/registry/loader",function() {
}) })
}); });
it("load empty set with settings available triggers registery save", function(done) { it("load empty set with settings available triggers registery save", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};})); stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){ return {};}));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return {};}));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load(true).then(function() { loader.load(true).then(function() {
registry.saveNodeList.called.should.be.true(); registry.saveNodeList.called.should.be.true();
@ -69,7 +69,7 @@ describe("red/nodes/registry/loader",function() {
}); });
it("load core node files scanned by lfs - single node single file", function(done) { it("load core node files scanned by lfs - single node single file", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -85,10 +85,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -126,7 +126,7 @@ describe("red/nodes/registry/loader",function() {
}); });
it("load core node files scanned by lfs - ignore html if disableEditor true", function(done) { it("load core node files scanned by lfs - ignore html if disableEditor true", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -142,10 +142,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{disableEditor: true, available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{disableEditor: true, available:function(){return true;}}});
@ -190,7 +190,7 @@ describe("red/nodes/registry/loader",function() {
}); });
it("load core node files scanned by lfs - multiple nodes single file", function(done) { it("load core node files scanned by lfs - multiple nodes single file", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -206,10 +206,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.load().then(function(result) { loader.load().then(function(result) {
@ -250,7 +250,7 @@ describe("red/nodes/registry/loader",function() {
it("load core node files scanned by lfs - node with promise", function(done) { it("load core node files scanned by lfs - node with promise", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -266,10 +266,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -308,7 +308,7 @@ describe("red/nodes/registry/loader",function() {
it("load core node files scanned by lfs - node with rejecting promise", function(done) { it("load core node files scanned by lfs - node with rejecting promise", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -324,10 +324,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -362,7 +362,7 @@ describe("red/nodes/registry/loader",function() {
}); });
it("load core node files scanned by lfs - missing file", function(done) { it("load core node files scanned by lfs - missing file", function(done) {
stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
var result = {}; var result = {};
result["node-red"] = { result["node-red"] = {
"name": "node-red", "name": "node-red",
@ -378,10 +378,10 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -416,7 +416,7 @@ describe("red/nodes/registry/loader",function() {
// it("load core node files scanned by lfs - missing html file", function(done) { // it("load core node files scanned by lfs - missing html file", function(done) {
// // This is now an okay situation // // This is now an okay situation
// stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ // stubs.push(sinon.stub(localfilesystem,"getNodeFiles").callsFake(function(){
// var result = {}; // var result = {};
// result["node-red"] = { // result["node-red"] = {
// "name": "node-red", // "name": "node-red",
@ -432,10 +432,10 @@ describe("red/nodes/registry/loader",function() {
// return result; // return result;
// })); // }));
// //
// stubs.push(sinon.stub(registry,"saveNodeList", function(){ return })); // stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return }));
// stubs.push(sinon.stub(registry,"addModule", function(){ return })); // stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
// // This module isn't already loaded // // This module isn't already loaded
// stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); // stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
// //
// stubs.push(sinon.stub(nodes,"registerType")); // stubs.push(sinon.stub(nodes,"registerType"));
// loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); // loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -481,7 +481,7 @@ describe("red/nodes/registry/loader",function() {
}); });
it("returns rejected error if module already loaded", function(done) { it("returns rejected error if module already loaded", function(done) {
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}})); stubs.push(sinon.stub(registry,"getModuleInfo").callsFake(function(){return{}}));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.addModule("test-module").catch(function(err) { loader.addModule("test-module").catch(function(err) {
@ -490,8 +490,8 @@ describe("red/nodes/registry/loader",function() {
}); });
}); });
it("returns rejected error if module not found", function(done) { it("returns rejected error if module not found", function(done) {
stubs.push(sinon.stub(registry,"getModuleInfo",function(){return null})); stubs.push(sinon.stub(registry,"getModuleInfo").callsFake(function(){return null}));
stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() { stubs.push(sinon.stub(localfilesystem,"getModuleFiles").callsFake(function() {
throw new Error("failure"); throw new Error("failure");
})); }));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
@ -504,9 +504,9 @@ describe("red/nodes/registry/loader",function() {
it("loads module by name", function(done) { it("loads module by name", function(done) {
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(registry,"getModuleInfo",function(){ return null; })); stubs.push(sinon.stub(registry,"getModuleInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(localfilesystem,"getModuleFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getModuleFiles").callsFake(function(){
var result = {}; var result = {};
result["TestNodeModule"] = { result["TestNodeModule"] = {
"name": "TestNodeModule", "name": "TestNodeModule",
@ -523,8 +523,8 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return "a node list" }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}}); loader.init({nodes:nodes,log:{info:function(){},_:function(){}},settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) { loader.addModule("TestNodeModule").then(function(result) {
@ -560,9 +560,9 @@ describe("red/nodes/registry/loader",function() {
it("skips module that fails version check", function(done) { it("skips module that fails version check", function(done) {
// This module isn't already loaded // This module isn't already loaded
stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(registry,"getNodeInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(registry,"getModuleInfo",function(){ return null; })); stubs.push(sinon.stub(registry,"getModuleInfo").callsFake(function(){ return null; }));
stubs.push(sinon.stub(localfilesystem,"getModuleFiles", function(){ stubs.push(sinon.stub(localfilesystem,"getModuleFiles").callsFake(function(){
var result = {}; var result = {};
result["TestNodeModule"] = { result["TestNodeModule"] = {
"name": "TestNodeModule", "name": "TestNodeModule",
@ -580,8 +580,8 @@ describe("red/nodes/registry/loader",function() {
return result; return result;
})); }));
stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" })); stubs.push(sinon.stub(registry,"saveNodeList").callsFake(function(){ return "a node list" }));
stubs.push(sinon.stub(registry,"addModule", function(){ return })); stubs.push(sinon.stub(registry,"addModule").callsFake(function(){ return }));
stubs.push(sinon.stub(nodes,"registerType")); stubs.push(sinon.stub(nodes,"registerType"));
loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,version: function() { return "0.12.0"}, settings:{available:function(){return true;}}}); loader.init({log:{"_":function(){},warn:function(){}},nodes:nodes,version: function() { return "0.12.0"}, settings:{available:function(){return true;}}});
loader.addModule("TestNodeModule").then(function(result) { loader.addModule("TestNodeModule").then(function(result) {
@ -643,7 +643,7 @@ describe("red/nodes/registry/loader",function() {
},"en").should.eql("foo"); },"en").should.eql("foo");
}); });
it("loads help, caching result", function() { it("loads help, caching result", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) { stubs.push(sinon.stub(fs,"readFileSync").callsFake(function(path) {
return 'bar'; return 'bar';
})) }))
var node = { var node = {
@ -660,7 +660,7 @@ describe("red/nodes/registry/loader",function() {
fs.readFileSync.calledOnce.should.be.true(); fs.readFileSync.calledOnce.should.be.true();
}); });
it("loads help, defaulting to en-US content", function() { it("loads help, defaulting to en-US content", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) { stubs.push(sinon.stub(fs,"readFileSync").callsFake(function(path) {
throw new Error("not found"); throw new Error("not found");
})) }))
var node = { var node = {
@ -677,7 +677,7 @@ describe("red/nodes/registry/loader",function() {
fs.readFileSync.calledOnce.should.be.true(); fs.readFileSync.calledOnce.should.be.true();
}); });
it("loads help, defaulting to en-US content for extra nodes", function() { it("loads help, defaulting to en-US content for extra nodes", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) { stubs.push(sinon.stub(fs,"readFileSync").callsFake(function(path) {
if (path.indexOf("en-US") >= 0) { if (path.indexOf("en-US") >= 0) {
return 'bar'; return 'bar';
} }
@ -698,7 +698,7 @@ describe("red/nodes/registry/loader",function() {
fs.readFileSync.calledTwice.should.be.true(); fs.readFileSync.calledTwice.should.be.true();
}); });
it("fails to load en-US help content", function() { it("fails to load en-US help content", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) { stubs.push(sinon.stub(fs,"readFileSync").callsFake(function(path) {
throw new Error("not found"); throw new Error("not found");
})); }));
var node = { var node = {

View File

@ -30,7 +30,7 @@ var i18n = NR_TEST_UTILS.require("@node-red/util").i18n;
describe("red/nodes/registry/localfilesystem",function() { describe("red/nodes/registry/localfilesystem",function() {
beforeEach(function() { beforeEach(function() {
stubs.push(sinon.stub(i18n,"registerMessageCatalog", function() { return Promise.resolve(); })); stubs.push(sinon.stub(i18n,"registerMessageCatalog").callsFake(function() { return Promise.resolve(); }));
}) })
var stubs = []; var stubs = [];
@ -131,7 +131,7 @@ describe("red/nodes/registry/localfilesystem",function() {
}); });
it("Finds nodes module path",function(done) { it("Finds nodes module path",function(done) {
var _join = path.join; var _join = path.join;
stubs.push(sinon.stub(path,"join",function() { stubs.push(sinon.stub(path,"join").callsFake(function() {
if (arguments[0] == resourcesDir) { if (arguments[0] == resourcesDir) {
// This stops the module tree scan from going any higher // This stops the module tree scan from going any higher
// up the tree than resourcesDir. // up the tree than resourcesDir.
@ -206,7 +206,7 @@ describe("red/nodes/registry/localfilesystem",function() {
describe("#getModuleFiles",function() { describe("#getModuleFiles",function() {
it("gets a nodes module files",function(done) { it("gets a nodes module files",function(done) {
var _join = path.join; var _join = path.join;
stubs.push(sinon.stub(path,"join",function() { stubs.push(sinon.stub(path,"join").callsFake(function() {
if (arguments[0] == resourcesDir) { if (arguments[0] == resourcesDir) {
// This stops the module tree scan from going any higher // This stops the module tree scan from going any higher
// up the tree than resourcesDir. // up the tree than resourcesDir.
@ -232,7 +232,7 @@ describe("red/nodes/registry/localfilesystem",function() {
}); });
it("throws an error if a node isn't found",function(done) { it("throws an error if a node isn't found",function(done) {
var _join = path.join; var _join = path.join;
stubs.push(sinon.stub(path,"join",function() { stubs.push(sinon.stub(path,"join").callsFake(function() {
if (arguments[0] == resourcesDir) { if (arguments[0] == resourcesDir) {
// This stops the module tree scan from going any higher // This stops the module tree scan from going any higher
// up the tree than resourcesDir. // up the tree than resourcesDir.
@ -251,7 +251,7 @@ describe("red/nodes/registry/localfilesystem",function() {
it.skip("finds icon path directory"); it.skip("finds icon path directory");
it("scans icon files with a module file",function(done) { it("scans icon files with a module file",function(done) {
var _join = path.join; var _join = path.join;
stubs.push(sinon.stub(path,"join",function() { stubs.push(sinon.stub(path,"join").callsFake(function() {
if (arguments[0] == resourcesDir) { if (arguments[0] == resourcesDir) {
// This stops the module tree scan from going any higher // This stops the module tree scan from going any higher
// up the tree than resourcesDir. // up the tree than resourcesDir.

View File

@ -37,8 +37,8 @@ describe("red/nodes/registry/plugins",function() {
} }
} }
events.on("registry:plugin-added",handleEvent); events.on("registry:plugin-added",handleEvent);
sinon.stub(registry,"getModule", moduleId => modules[moduleId]); sinon.stub(registry,"getModule").callsFake(moduleId => modules[moduleId]);
sinon.stub(registry,"getModuleList", () => modules) sinon.stub(registry,"getModuleList").callsFake(() => modules)
}); });
afterEach(function() { afterEach(function() {
events.removeListener("registry:plugin-added",handleEvent); events.removeListener("registry:plugin-added",handleEvent);

View File

@ -31,8 +31,8 @@ describe("runtime-api/comms", function() {
} }
var eventHandlers = {}; var eventHandlers = {};
before(function(done) { before(function(done) {
sinon.stub(events,"removeListener", function() {}) sinon.stub(events,"removeListener").callsFake(function() {})
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler }) sinon.stub(events,"on").callsFake(function(evt,handler) { eventHandlers[evt] = handler })
comms.init({ comms.init({
log: { log: {
trace: function(){} trace: function(){}
@ -97,8 +97,8 @@ describe("runtime-api/comms", function() {
} }
} }
before(function() { before(function() {
sinon.stub(events,"removeListener", function() {}) sinon.stub(events,"removeListener").callsFake(function() {})
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler }) sinon.stub(events,"on").callsFake(function(evt,handler) { eventHandlers[evt] = handler })
comms.init({ comms.init({
log: { log: {
trace: function(){} trace: function(){}
@ -177,8 +177,8 @@ describe("runtime-api/comms", function() {
} }
var eventHandlers = {}; var eventHandlers = {};
before(function() { before(function() {
sinon.stub(events,"removeListener", function() {}) sinon.stub(events,"removeListener").callsFake(function() {})
sinon.stub(events,"on", function(evt,handler) { eventHandlers[evt] = handler }) sinon.stub(events,"on").callsFake(function(evt,handler) { eventHandlers[evt] = handler })
comms.init({ comms.init({
log: { log: {
trace: function(){} trace: function(){}

View File

@ -24,7 +24,7 @@ var index = NR_TEST_UTILS.require("@node-red/runtime/lib/api/index");
describe("runtime-api/index", function() { describe("runtime-api/index", function() {
before(function() { before(function() {
["comms","flows","nodes","settings","library","projects"].forEach(n => { ["comms","flows","nodes","settings","library","projects"].forEach(n => {
sinon.stub(NR_TEST_UTILS.require(`@node-red/runtime/lib/api/${n}`),"init",()=>{}); sinon.stub(NR_TEST_UTILS.require(`@node-red/runtime/lib/api/${n}`),"init").callsFake(()=>{});
}) })
}); });
after(function() { after(function() {

View File

@ -217,7 +217,7 @@ describe("api/admin/nodes", function() {
app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet); app.put(/\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,nodes.putSet);
app.get("/getIcons",nodes.getIcons); app.get("/getIcons",nodes.getIcons);
app.delete("/nodes/:id",nodes.delete); app.delete("/nodes/:id",nodes.delete);
sinon.stub(apiUtil,"determineLangFromHeaders", function() { sinon.stub(apiUtil,"determineLangFromHeaders").callsFake(function() {
return "en-US"; return "en-US";
}); });
}); });

View File

@ -173,7 +173,7 @@ describe('Flow', function() {
util.inherits(TestDoneNode,Node); util.inherits(TestDoneNode,Node);
before(function() { before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) { getType = sinon.stub(typeRegistry,"get").callsFake(function(type) {
if (type=="test") { if (type=="test") {
return TestNode; return TestNode;
} else if (type=="testError"){ } else if (type=="testError"){

View File

@ -202,7 +202,7 @@ describe('Subflow', function() {
util.inherits(TestEnvNode,Node); util.inherits(TestEnvNode,Node);
before(function() { before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) { getType = sinon.stub(typeRegistry,"get").callsFake(function(type) {
if (type=="test") { if (type=="test") {
return TestNode; return TestNode;
} else if (type=="testError"){ } else if (type=="testError"){

View File

@ -51,10 +51,10 @@ describe('flows/index', function() {
before(function() { before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) { getType = sinon.stub(typeRegistry,"get").callsFake(function(type) {
return type.indexOf('missing') === -1; return type.indexOf('missing') === -1;
}); });
checkFlowDependencies = sinon.stub(typeRegistry, "checkFlowDependencies", async function(flow) { checkFlowDependencies = sinon.stub(typeRegistry, "checkFlowDependencies").callsFake(async function(flow) {
if (flow[0].id === "node-with-missing-modules") { if (flow[0].id === "node-with-missing-modules") {
throw new Error("Missing module"); throw new Error("Missing module");
} }
@ -69,20 +69,20 @@ describe('flows/index', function() {
beforeEach(function() { beforeEach(function() {
eventsOn = sinon.spy(events,"on"); eventsOn = sinon.spy(events,"on");
credentialsClean = sinon.stub(credentials,"clean",function(conf) { credentialsClean = sinon.stub(credentials,"clean").callsFake(function(conf) {
conf.forEach(function(n) { conf.forEach(function(n) {
delete n.credentials; delete n.credentials;
}); });
return Promise.resolve(); return Promise.resolve();
}); });
credentialsLoad = sinon.stub(credentials,"load",function(creds) { credentialsLoad = sinon.stub(credentials,"load").callsFake(function(creds) {
if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") { if (creds && creds.hasOwnProperty("$") && creds['$'] === "fail") {
return Promise.reject("creds error"); return Promise.reject("creds error");
} }
return Promise.resolve(); return Promise.resolve();
}); });
credentialsAdd = sinon.stub(credentials,"add", async function(id, conf){}) credentialsAdd = sinon.stub(credentials,"add").callsFake(async function(id, conf){})
flowCreate = sinon.stub(Flow,"create",function(parent, global, flow) { flowCreate = sinon.stub(Flow,"create").callsFake(function(parent, global, flow) {
var id; var id;
if (typeof flow === 'undefined') { if (typeof flow === 'undefined') {
flow = global; flow = global;
@ -551,7 +551,7 @@ describe('flows/index', function() {
describe('#checkTypeInUse', function() { describe('#checkTypeInUse', function() {
before(function() { before(function() {
sinon.stub(typeRegistry,"getNodeInfo",function(id) { sinon.stub(typeRegistry,"getNodeInfo").callsFake(function(id) {
if (id === 'unused-module') { if (id === 'unused-module') {
return {types:['one','two','three']} return {types:['one','two','three']}
} else { } else {

View File

@ -26,7 +26,7 @@ describe('flows/util', function() {
var getType; var getType;
before(function() { before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) { getType = sinon.stub(typeRegistry,"get").callsFake(function(type) {
return type!=='missing'; return type!=='missing';
}); });
}); });

View File

@ -44,13 +44,13 @@ describe("runtime", function() {
delete process.env.NODE_RED_HOME; delete process.env.NODE_RED_HOME;
}); });
function mockUtil(metrics) { function mockUtil(metrics) {
sinon.stub(log,"log",function(){}) sinon.stub(log,"log").callsFake(function(){})
sinon.stub(log,"warn",function(){}) sinon.stub(log,"warn").callsFake(function(){})
sinon.stub(log,"info",function(){}) sinon.stub(log,"info").callsFake(function(){})
sinon.stub(log,"trace",function(){}) sinon.stub(log,"trace").callsFake(function(){})
sinon.stub(log,"metric",function(){ return !!metrics }) sinon.stub(log,"metric").callsFake(function(){ return !!metrics })
sinon.stub(log,"_",function(){ return "abc"}) sinon.stub(log,"_").callsFake(function(){ return "abc"})
sinon.stub(i18n,"registerMessageCatalog",function(){ return Promise.resolve()}) sinon.stub(i18n,"registerMessageCatalog").callsFake(function(){ return Promise.resolve()})
} }
function unmockUtil() { function unmockUtil() {
log.log.restore && log.log.restore(); log.log.restore && log.log.restore();
@ -63,9 +63,9 @@ describe("runtime", function() {
} }
describe("init", function() { describe("init", function() {
beforeEach(function() { beforeEach(function() {
sinon.stub(log,"init",function() {}); sinon.stub(log,"init").callsFake(function() {});
sinon.stub(settings,"init",function() {}); sinon.stub(settings,"init").callsFake(function() {});
sinon.stub(redNodes,"init",function() {}) sinon.stub(redNodes,"init").callsFake(function() {})
mockUtil(); mockUtil();
}); });
afterEach(function() { afterEach(function() {
@ -103,13 +103,13 @@ describe("runtime", function() {
var redNodesLoadContextsPlugin; var redNodesLoadContextsPlugin;
beforeEach(function() { beforeEach(function() {
storageInit = sinon.stub(storage,"init",function(settings) {return Promise.resolve();}); storageInit = sinon.stub(storage,"init").callsFake(function(settings) {return Promise.resolve();});
redNodesInit = sinon.stub(redNodes,"init", function() {}); redNodesInit = sinon.stub(redNodes,"init").callsFake(function() {});
redNodesLoad = sinon.stub(redNodes,"load", function() {return Promise.resolve()}); redNodesLoad = sinon.stub(redNodes,"load").callsFake(function() {return Promise.resolve()});
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList",function(){}); redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList").callsFake(function(){});
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return Promise.resolve()}); redNodesLoadFlows = sinon.stub(redNodes,"loadFlows").callsFake(function() {return Promise.resolve()});
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {}); redNodesStartFlows = sinon.stub(redNodes,"startFlows").callsFake(function() {});
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {return Promise.resolve()}); redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin").callsFake(function() {return Promise.resolve()});
mockUtil(); mockUtil();
}); });
afterEach(function() { afterEach(function() {
@ -124,7 +124,7 @@ describe("runtime", function() {
unmockUtil(); unmockUtil();
}); });
it("reports errored/missing modules",function(done) { it("reports errored/missing modules",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) { redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function(cb) {
return [ return [
{ err:"errored",name:"errName" }, // error { err:"errored",name:"errName" }, // error
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing { module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing
@ -151,7 +151,7 @@ describe("runtime", function() {
}).catch(err=>{done(err)}); }).catch(err=>{done(err)});
}); });
it("initiates load of missing modules",function(done) { it("initiates load of missing modules",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) { redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function(cb) {
return [ return [
{ err:"errored",name:"errName" }, // error { err:"errored",name:"errName" }, // error
{ err:"errored",name:"errName" }, // error { err:"errored",name:"errName" }, // error
@ -159,7 +159,7 @@ describe("runtime", function() {
{ module:"node-red",enabled:true,loaded:false,types:["typeC","typeD"]} // missing { module:"node-red",enabled:true,loaded:false,types:["typeC","typeD"]} // missing
].filter(cb); ].filter(cb);
}); });
var serverInstallModule = sinon.stub(redNodes,"installModule",function(name) { return Promise.resolve({nodes:[]});}); var serverInstallModule = sinon.stub(redNodes,"installModule").callsFake(function(name) { return Promise.resolve({nodes:[]});});
runtime.init({testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}}); runtime.init({testSettings: true, autoInstallModules:true, httpAdminRoot:"/", load:function() { return Promise.resolve();}});
sinon.stub(console,"log"); sinon.stub(console,"log");
runtime.start().then(function() { runtime.start().then(function() {
@ -181,7 +181,7 @@ describe("runtime", function() {
}).catch(err=>{done(err)}); }).catch(err=>{done(err)});
}); });
it("reports errored modules when verbose is enabled",function(done) { it("reports errored modules when verbose is enabled",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) { redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function(cb) {
return [ return [
{ err:"errored",name:"errName" } // error { err:"errored",name:"errName" } // error
].filter(cb); ].filter(cb);
@ -201,8 +201,8 @@ describe("runtime", function() {
}); });
it("reports runtime metrics",function(done) { it("reports runtime metrics",function(done) {
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} ); var stopFlows = sinon.stub(redNodes,"stopFlows").callsFake(function() { return Promise.resolve();} );
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {return []}); redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function() {return []});
unmockUtil(); unmockUtil();
mockUtil(true); mockUtil(true);
runtime.init( runtime.init(
@ -233,8 +233,8 @@ describe("runtime", function() {
}); });
it("stops components", function(done) { it("stops components", function(done) {
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} ); var stopFlows = sinon.stub(redNodes,"stopFlows").callsFake(function() { return Promise.resolve();} );
var closeContextsPlugin = sinon.stub(redNodes,"closeContextsPlugin",function() { return Promise.resolve();} ); var closeContextsPlugin = sinon.stub(redNodes,"closeContextsPlugin").callsFake(function() { return Promise.resolve();} );
runtime.stop().then(function(){ runtime.stop().then(function(){
stopFlows.called.should.be.true(); stopFlows.called.should.be.true();
closeContextsPlugin.called.should.be.true(); closeContextsPlugin.called.should.be.true();

View File

@ -65,7 +65,7 @@ describe("runtime/library/examples", function() {
} }
} }
}); });
sinon.stub(fs,"readFile", function(path,opts,callback) { sinon.stub(fs,"readFile").callsFake(function(path,opts,callback) {
if (path === "/tmp/test-module/abc") { if (path === "/tmp/test-module/abc") {
callback(null,"Example flow result"); callback(null,"Example flow result");
} else if (path === "/tmp/@scope/test-module/abc") { } else if (path === "/tmp/@scope/test-module/abc") {

View File

@ -37,14 +37,14 @@ var mockLog = {
describe("runtime/library", function() { describe("runtime/library", function() {
before(function() { before(function() {
sinon.stub(localLibrary,"getEntry",function(type,path) { sinon.stub(localLibrary,"getEntry").callsFake(function(type,path) {
return Promise.resolve({ return Promise.resolve({
library: "local", library: "local",
type:type, type:type,
path:path path:path
}) })
}); });
sinon.stub(localLibrary,"saveEntry",function(type, path, meta, body) { sinon.stub(localLibrary,"saveEntry").callsFake(function(type, path, meta, body) {
return Promise.resolve({ return Promise.resolve({
library: "local", library: "local",
type:type, type:type,
@ -53,7 +53,7 @@ describe("runtime/library", function() {
body:body body:body
}) })
}); });
sinon.stub(examplesLibrary,"getEntry",function(type,path) { sinon.stub(examplesLibrary,"getEntry").callsFake(function(type,path) {
return Promise.resolve({ return Promise.resolve({
library: "_examples_", library: "_examples_",
type:type, type:type,

View File

@ -151,7 +151,7 @@ describe('Node', function() {
it('handles thrown errors', function(done) { it('handles thrown errors', function(done) {
var n = new RedNode({id:'123',type:'abc'}); var n = new RedNode({id:'123',type:'abc'});
sinon.stub(n,"error",function(err,msg) {}); sinon.stub(n,"error").callsFake(function(err,msg) {});
var message = {payload:"hello world"}; var message = {payload:"hello world"};
n.on('input',function(msg) { n.on('input',function(msg) {
throw new Error("test error"); throw new Error("test error");
@ -271,7 +271,7 @@ describe('Node', function() {
}); });
it('logs error if callback provides error', function(done) { it('logs error if callback provides error', function(done) {
var n = new RedNode({id:'123',type:'abc'}); var n = new RedNode({id:'123',type:'abc'});
sinon.stub(n,"error",function(err,msg) {}); sinon.stub(n,"error").callsFake(function(err,msg) {});
var message = {payload:"hello world"}; var message = {payload:"hello world"};
n.on('input',function(msg, nodeSend, nodeDone) { n.on('input',function(msg, nodeSend, nodeDone) {
@ -723,7 +723,7 @@ describe('Node', function() {
it('produces a metric message', function(done) { it('produces a metric message', function(done) {
var n = new RedNode({id:'123',type:'abc'}); var n = new RedNode({id:'123',type:'abc'});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) { sinon.stub(Log, 'log').callsFake(function(msg) {
loginfo = msg; loginfo = msg;
}); });
var msg = {payload:"foo", _msgid:"987654321"}; var msg = {payload:"foo", _msgid:"987654321"};
@ -739,7 +739,7 @@ describe('Node', function() {
it('returns metric value if eventname undefined', function(done) { it('returns metric value if eventname undefined', function(done) {
var n = new RedNode({id:'123',type:'abc'}); var n = new RedNode({id:'123',type:'abc'});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) { sinon.stub(Log, 'log').callsFake(function(msg) {
loginfo = msg; loginfo = msg;
}); });
var msg = {payload:"foo", _msgid:"987654321"}; var msg = {payload:"foo", _msgid:"987654321"};
@ -751,7 +751,7 @@ describe('Node', function() {
it('returns not defined if eventname defined', function(done) { it('returns not defined if eventname defined', function(done) {
var n = new RedNode({id:'123',type:'abc'}); var n = new RedNode({id:'123',type:'abc'});
var loginfo = {}; var loginfo = {};
sinon.stub(Log, 'log', function(msg) { sinon.stub(Log, 'log').callsFake(function(msg) {
loginfo = msg; loginfo = msg;
}); });
var msg = {payload:"foo", _msgid:"987654321"}; var msg = {payload:"foo", _msgid:"987654321"};

View File

@ -320,7 +320,7 @@ describe('context', function() {
describe('external context storage',function() { describe('external context storage',function() {
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","context")); var resourcesDir = path.resolve(path.join(__dirname,"..","resources","context"));
var sandbox = sinon.sandbox.create(); var sandbox = sinon.createSandbox();
var stubGet = sandbox.stub(); var stubGet = sandbox.stub();
var stubSet = sandbox.stub(); var stubSet = sandbox.stub();
var stubKeys = sandbox.stub(); var stubKeys = sandbox.stub();

View File

@ -177,15 +177,15 @@ describe("red/nodes/index", function() {
var userDir = path.join(__dirname,".testUserHome"); var userDir = path.join(__dirname,".testUserHome");
before(function(done) { before(function(done) {
sinon.stub(log,"log",function(){}); sinon.stub(log,"log").callsFake(function(){});
fs.remove(userDir,function(err) { fs.remove(userDir,function(err) {
fs.mkdir(userDir,function() { fs.mkdir(userDir,function() {
sinon.stub(index, 'load', function() { sinon.stub(index, 'load').callsFake(function() {
return new Promise(function(resolve,reject){ return new Promise(function(resolve,reject){
resolve([]); resolve([]);
}); });
}); });
sinon.stub(localfilesystem, 'getCredentials', function() { sinon.stub(localfilesystem, 'getCredentials').callsFake(function() {
return new Promise(function(resolve,reject) { return new Promise(function(resolve,reject) {
resolve({"tab1":{"b":1,"c":2}}); resolve({"tab1":{"b":1,"c":2}});
}); });
@ -271,7 +271,7 @@ describe("red/nodes/index", function() {
var randomNodeInfo = {id:"5678",types:["random"]}; var randomNodeInfo = {id:"5678",types:["random"]};
beforeEach(function() { beforeEach(function() {
sinon.stub(registry,"getNodeInfo",function(id) { sinon.stub(registry,"getNodeInfo").callsFake(function(id) {
if (id == "test") { if (id == "test") {
return {id:"1234",types:["test"]}; return {id:"1234",types:["test"]};
} else if (id == "doesnotexist") { } else if (id == "doesnotexist") {
@ -280,7 +280,7 @@ describe("red/nodes/index", function() {
return randomNodeInfo; return randomNodeInfo;
} }
}); });
sinon.stub(registry,"disableNode",function(id) { sinon.stub(registry,"disableNode").callsFake(function(id) {
return Promise.resolve(randomNodeInfo); return Promise.resolve(randomNodeInfo);
}); });
}); });
@ -343,7 +343,7 @@ describe("red/nodes/index", function() {
}; };
before(function() { before(function() {
sinon.stub(registry,"getNodeInfo",function(id) { sinon.stub(registry,"getNodeInfo").callsFake(function(id) {
if (id == "node-red/foo") { if (id == "node-red/foo") {
return {id:"1234",types:["test"]}; return {id:"1234",types:["test"]};
} else if (id == "doesnotexist") { } else if (id == "doesnotexist") {
@ -352,7 +352,7 @@ describe("red/nodes/index", function() {
return randomNodeInfo; return randomNodeInfo;
} }
}); });
sinon.stub(registry,"getModuleInfo",function(module) { sinon.stub(registry,"getModuleInfo").callsFake(function(module) {
if (module == "node-red") { if (module == "node-red") {
return {nodes:[{name:"foo"}]}; return {nodes:[{name:"foo"}]};
} else if (module == "doesnotexist") { } else if (module == "doesnotexist") {
@ -361,7 +361,7 @@ describe("red/nodes/index", function() {
return randomModuleInfo; return randomModuleInfo;
} }
}); });
sinon.stub(registry,"removeModule",function(id) { sinon.stub(registry,"removeModule").callsFake(function(id) {
return randomModuleInfo; return randomModuleInfo;
}); });
}); });

View File

@ -313,7 +313,7 @@ describe('storage/localfilesystem', function() {
var flowFile = 'test.json'; var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile); var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({userDir:userDir, flowFile:flowFilePath,getUserSettings: () => {{}}}, mockRuntime).then(function() { localfilesystem.init({userDir:userDir, flowFile:flowFilePath,getUserSettings: () => {{}}}, mockRuntime).then(function() {
sinon.stub(fs,"fsync", function(fd, cb) { sinon.stub(fs,"fsync").callsFake(function(fd, cb) {
cb(new Error()); cb(new Error());
}); });
sinon.spy(log,"warn"); sinon.spy(log,"warn");

View File

@ -34,7 +34,7 @@ describe("localfilesystem/projects/ssh/keygen", function() {
var command; var command;
var args; var args;
var opts; var opts;
sinon.stub(child_process,"spawn", function(_command,_args,_opts) { sinon.stub(child_process,"spawn").callsFake(function(_command,_args,_opts) {
_command = command; _command = command;
_args = args; _args = args;
_opts = opts; _opts = opts;

View File

@ -41,7 +41,7 @@ describe("runtime/exec", function() {
mockProcess = new EventEmitter(); mockProcess = new EventEmitter();
mockProcess.stdout = new EventEmitter(); mockProcess.stdout = new EventEmitter();
mockProcess.stderr = new EventEmitter(); mockProcess.stderr = new EventEmitter();
sinon.stub(child_process,'spawn',function(command,args,options) { sinon.stub(child_process,'spawn').callsFake(function(command,args,options) {
mockProcess._args = {command,args,options}; mockProcess._args = {command,args,options};
return mockProcess; return mockProcess;
}); });

View File

@ -24,7 +24,7 @@ var log = NR_TEST_UTILS.require("@node-red/util").log;
describe("@node-red/util/log", function() { describe("@node-red/util/log", function() {
beforeEach(function () { beforeEach(function () {
var spy = sinon.stub(util, 'log', function(arg){}); var spy = sinon.stub(util, 'log').callsFake(function(arg){});
var settings = {logging: { console: { level: 'metric', metrics: true } } }; var settings = {logging: { console: { level: 'metric', metrics: true } } };
log.init(settings); log.init(settings);
}); });

View File

@ -33,9 +33,9 @@ describe("red/red", function() {
// describe("check build", function() { // describe("check build", function() {
// beforeEach(function() { // beforeEach(function() {
// sinon.stub(runtime,"init",function() {}); // sinon.stub(runtime,"init").callsFake(function() {});
// sinon.stub(api,"init",function() {}); // sinon.stub(api,"init").callsFake(function() {});
// // sinon.stub(RED,"version",function() { return "version";}); // // sinon.stub(RED,"version").callsFake(function() { return "version";});
// }); // });
// afterEach(function() { // afterEach(function() {
// runtime.init.restore(); // runtime.init.restore();
@ -44,7 +44,7 @@ describe("red/red", function() {
// // RED.version.restore(); // // RED.version.restore();
// }); // });
// it.skip('warns if build has not been run',function() { // it.skip('warns if build has not been run',function() {
// sinon.stub(fs,"statSync",function() { throw new Error();}); // sinon.stub(fs,"statSync").callsFake(function() { throw new Error();});
// //
// /*jshint immed: false */ // /*jshint immed: false */
// (function() { // (function() {
@ -52,7 +52,7 @@ describe("red/red", function() {
// }).should.throw("Node-RED not built"); // }).should.throw("Node-RED not built");
// }); // });
// it('passed if build has been run',function() { // it('passed if build has been run',function() {
// sinon.stub(fs,"statSync",function() { }); // sinon.stub(fs,"statSync").callsFake(function() { });
// RED.init({},{}); // RED.init({},{});
// }); // });
// }); // });