mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Fully remove when.js dependency
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var when = require("when");
|
||||
var fs = require("fs");
|
||||
|
||||
var NR_TEST_UTILS = require("nr-test-utils");
|
||||
@@ -51,7 +50,7 @@ describe('red/registry/index', function() {
|
||||
describe('#addModule', function() {
|
||||
it('loads the module and returns its info', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
@@ -63,7 +62,7 @@ describe('red/registry/index', function() {
|
||||
});
|
||||
it('rejects if loader rejects', function(done) {
|
||||
stubs.push(sinon.stub(loader,"addModule",function(module) {
|
||||
return when.reject("error");
|
||||
return Promise.reject("error");
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getModuleInfo", function(module) {
|
||||
return "info";
|
||||
@@ -80,7 +79,7 @@ describe('red/registry/index', function() {
|
||||
describe('#enableNode',function() {
|
||||
it('enables a node set',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||
return {id:"node-set",loaded:true};
|
||||
@@ -104,14 +103,14 @@ describe('red/registry/index', function() {
|
||||
|
||||
it('triggers a node load',function(done) {
|
||||
stubs.push(sinon.stub(typeRegistry,"enableNodeSet",function() {
|
||||
return when.resolve();
|
||||
return Promise.resolve();
|
||||
}));
|
||||
var calls = 0;
|
||||
stubs.push(sinon.stub(typeRegistry,"getNodeInfo", function() {
|
||||
// loaded=false on first call, true on subsequent
|
||||
return {id:"node-set",loaded:(calls++>0)};
|
||||
}));
|
||||
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return when.resolve();}));
|
||||
stubs.push(sinon.stub(loader,"loadNodeSet",function(){return Promise.resolve();}));
|
||||
stubs.push(sinon.stub(typeRegistry,"getFullNodeInfo"));
|
||||
|
||||
registry.enableNode("node-set").then(function(ns) {
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require('fs-extra');
|
||||
var EventEmitter = require('events');
|
||||
@@ -185,7 +184,7 @@ describe('nodes/registry/installer', function() {
|
||||
initInstaller(p)
|
||||
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist").then(function(info) {
|
||||
@@ -216,7 +215,7 @@ describe('nodes/registry/installer', function() {
|
||||
it("succeeds when path is valid node-red module", function(done) {
|
||||
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"resources","local","TestNodeModule","node_modules","TestNodeModule"));
|
||||
|
||||
@@ -246,7 +245,7 @@ describe('nodes/registry/installer', function() {
|
||||
initInstaller(p)
|
||||
|
||||
var addModule = sinon.stub(registry,"addModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
|
||||
installer.installModule("this_wont_exist",null,"https://example/foo-0.1.1.tgz").then(function(info) {
|
||||
@@ -259,19 +258,20 @@ describe('nodes/registry/installer', function() {
|
||||
describe("uninstalls module", function() {
|
||||
it("rejects invalid module names", function(done) {
|
||||
var promises = [];
|
||||
promises.push(installer.uninstallModule("this_wont_exist "));
|
||||
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont"));
|
||||
when.settle(promises).then(function(results) {
|
||||
results[0].state.should.be.eql("rejected");
|
||||
results[1].state.should.be.eql("rejected");
|
||||
var rejectedCount = 0;
|
||||
|
||||
promises.push(installer.uninstallModule("this_wont_exist ").catch(() => {rejectedCount++}));
|
||||
promises.push(installer.uninstallModule("this_wont_exist;no_it_really_wont").catch(() => {rejectedCount++}));
|
||||
Promise.all(promises).then(function() {
|
||||
rejectedCount.should.eql(2);
|
||||
done();
|
||||
});
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("rejects with generic error", function(done) {
|
||||
var nodeInfo = [{module:"foo",types:["a"]}];
|
||||
var removeModule = sinon.stub(registry,"removeModule",function(md) {
|
||||
return when.resolve(nodeInfo);
|
||||
return Promise.resolve(nodeInfo);
|
||||
});
|
||||
var res = {
|
||||
code: 1,
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var fs = require("fs-extra");
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var when = require("when");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
|
||||
@@ -34,7 +33,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
|
||||
function stubSettings(s,available,initialConfig) {
|
||||
s.available = function() {return available;};
|
||||
s.set = sinon.spy(function(s,v) { return when.resolve();});
|
||||
s.set = sinon.spy(function(s,v) { return Promise.resolve();});
|
||||
s.get = function(s) { return initialConfig;};
|
||||
return s;
|
||||
}
|
||||
@@ -95,7 +94,7 @@ describe("red/nodes/registry/registry",function() {
|
||||
it('migrates legacy format', function(done) {
|
||||
var legacySettings = {
|
||||
available: function() { return true; },
|
||||
set: sinon.stub().returns(when.resolve()),
|
||||
set: sinon.stub().returns(Promise.resolve()),
|
||||
get: function() { return {
|
||||
"123": {
|
||||
"name": "72-sentiment.js",
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// A test node that exports a function which returns a resolving promise
|
||||
|
||||
var when = require("when");
|
||||
module.exports = function(RED) {
|
||||
return when.promise(function(resolve,reject) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
function TestNode(n) {}
|
||||
RED.nodes.registerType("test-node-2",TestNode);
|
||||
resolve();
|
||||
|
@@ -1,8 +1,7 @@
|
||||
// A test node that exports a function which returns a rejecting promise
|
||||
|
||||
var when = require("when");
|
||||
module.exports = function(RED) {
|
||||
return when.promise(function(resolve,reject) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
reject("fail");
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user