Update to latest sinon

This commit is contained in:
Nick O'Leary
2021-04-09 11:22:57 +01:00
parent 9882582903
commit 877c463494
40 changed files with 254 additions and 254 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -44,13 +44,13 @@ describe("runtime", function() {
delete process.env.NODE_RED_HOME;
});
function mockUtil(metrics) {
sinon.stub(log,"log",function(){})
sinon.stub(log,"warn",function(){})
sinon.stub(log,"info",function(){})
sinon.stub(log,"trace",function(){})
sinon.stub(log,"metric",function(){ return !!metrics })
sinon.stub(log,"_",function(){ return "abc"})
sinon.stub(i18n,"registerMessageCatalog",function(){ return Promise.resolve()})
sinon.stub(log,"log").callsFake(function(){})
sinon.stub(log,"warn").callsFake(function(){})
sinon.stub(log,"info").callsFake(function(){})
sinon.stub(log,"trace").callsFake(function(){})
sinon.stub(log,"metric").callsFake(function(){ return !!metrics })
sinon.stub(log,"_").callsFake(function(){ return "abc"})
sinon.stub(i18n,"registerMessageCatalog").callsFake(function(){ return Promise.resolve()})
}
function unmockUtil() {
log.log.restore && log.log.restore();
@@ -63,9 +63,9 @@ describe("runtime", function() {
}
describe("init", function() {
beforeEach(function() {
sinon.stub(log,"init",function() {});
sinon.stub(settings,"init",function() {});
sinon.stub(redNodes,"init",function() {})
sinon.stub(log,"init").callsFake(function() {});
sinon.stub(settings,"init").callsFake(function() {});
sinon.stub(redNodes,"init").callsFake(function() {})
mockUtil();
});
afterEach(function() {
@@ -103,13 +103,13 @@ describe("runtime", function() {
var redNodesLoadContextsPlugin;
beforeEach(function() {
storageInit = sinon.stub(storage,"init",function(settings) {return Promise.resolve();});
redNodesInit = sinon.stub(redNodes,"init", function() {});
redNodesLoad = sinon.stub(redNodes,"load", function() {return Promise.resolve()});
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList",function(){});
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return Promise.resolve()});
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {return Promise.resolve()});
storageInit = sinon.stub(storage,"init").callsFake(function(settings) {return Promise.resolve();});
redNodesInit = sinon.stub(redNodes,"init").callsFake(function() {});
redNodesLoad = sinon.stub(redNodes,"load").callsFake(function() {return Promise.resolve()});
redNodesCleanModuleList = sinon.stub(redNodes,"cleanModuleList").callsFake(function(){});
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows").callsFake(function() {return Promise.resolve()});
redNodesStartFlows = sinon.stub(redNodes,"startFlows").callsFake(function() {});
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin").callsFake(function() {return Promise.resolve()});
mockUtil();
});
afterEach(function() {
@@ -124,7 +124,7 @@ describe("runtime", function() {
unmockUtil();
});
it("reports errored/missing modules",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function(cb) {
return [
{ err:"errored",name:"errName" }, // error
{ module:"module",enabled:true,loaded:false,types:["typeA","typeB"]} // missing
@@ -151,7 +151,7 @@ describe("runtime", function() {
}).catch(err=>{done(err)});
});
it("initiates load of missing modules",function(done) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function(cb) {
return [
{ 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
].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();}});
sinon.stub(console,"log");
runtime.start().then(function() {
@@ -181,7 +181,7 @@ describe("runtime", function() {
}).catch(err=>{done(err)});
});
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 [
{ err:"errored",name:"errName" } // error
].filter(cb);
@@ -201,8 +201,8 @@ describe("runtime", function() {
});
it("reports runtime metrics",function(done) {
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} );
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {return []});
var stopFlows = sinon.stub(redNodes,"stopFlows").callsFake(function() { return Promise.resolve();} );
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList").callsFake(function() {return []});
unmockUtil();
mockUtil(true);
runtime.init(
@@ -233,8 +233,8 @@ describe("runtime", function() {
});
it("stops components", function(done) {
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} );
var closeContextsPlugin = sinon.stub(redNodes,"closeContextsPlugin",function() { return Promise.resolve();} );
var stopFlows = sinon.stub(redNodes,"stopFlows").callsFake(function() { return Promise.resolve();} );
var closeContextsPlugin = sinon.stub(redNodes,"closeContextsPlugin").callsFake(function() { return Promise.resolve();} );
runtime.stop().then(function(){
stopFlows.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") {
callback(null,"Example flow result");
} else if (path === "/tmp/@scope/test-module/abc") {

View File

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

View File

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

View File

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

View File

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

View File

@@ -313,7 +313,7 @@ describe('storage/localfilesystem', function() {
var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile);
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());
});
sinon.spy(log,"warn");

View File

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