mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Use native Promise instead of when.js
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require('sinon');
|
||||
var when = require("when")
|
||||
var rewire = require("rewire");
|
||||
var Context = require("../../../../../red/runtime/nodes/context/index");
|
||||
|
||||
@@ -169,20 +168,20 @@ describe('context', function() {
|
||||
|
||||
describe('external context storage',function() {
|
||||
var sandbox = sinon.sandbox.create();
|
||||
var stubGetAsync = sandbox.stub().returns(when.resolve());
|
||||
var stubSetAsync = sandbox.stub().returns(when.resolve());
|
||||
var stubKeysAsync = sandbox.stub().returns(when.resolve());
|
||||
var stubDelete = sandbox.stub().returns(when.resolve());
|
||||
var stubClean = sandbox.stub().returns(when.resolve());
|
||||
var stubOpen = sandbox.stub().returns(when.resolve());
|
||||
var stubClose = sandbox.stub().returns(when.resolve());
|
||||
var stubGetAsync2 = sandbox.stub().returns(when.resolve());
|
||||
var stubSetAsync2 = sandbox.stub().returns(when.resolve());
|
||||
var stubKeysAsync2 = sandbox.stub().returns(when.resolve());
|
||||
var stubDelete2 = sandbox.stub().returns(when.resolve());
|
||||
var stubClean2 = sandbox.stub().returns(when.resolve());
|
||||
var stubOpen2 = sandbox.stub().returns(when.resolve());
|
||||
var stubClose2 = sandbox.stub().returns(when.resolve());
|
||||
var stubGetAsync = sandbox.stub().returns(Promise.resolve());
|
||||
var stubSetAsync = sandbox.stub().returns(Promise.resolve());
|
||||
var stubKeysAsync = sandbox.stub().returns(Promise.resolve());
|
||||
var stubDelete = sandbox.stub().returns(Promise.resolve());
|
||||
var stubClean = sandbox.stub().returns(Promise.resolve());
|
||||
var stubOpen = sandbox.stub().returns(Promise.resolve());
|
||||
var stubClose = sandbox.stub().returns(Promise.resolve());
|
||||
var stubGetAsync2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubSetAsync2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubKeysAsync2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubDelete2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubClean2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubOpen2 = sandbox.stub().returns(Promise.resolve());
|
||||
var stubClose2 = sandbox.stub().returns(Promise.resolve());
|
||||
var testPlugin = function(config){
|
||||
function Test(){}
|
||||
Test.prototype.getAsync = stubGetAsync;
|
||||
@@ -262,7 +261,7 @@ describe('context', function() {
|
||||
});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("##%&.sign","sign1").then(function(){
|
||||
return context.getAsync("##%&.sign").should.finally.equal("sign1");
|
||||
}),
|
||||
@@ -279,7 +278,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:{_:{module:testPlugin}}});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#_.foo","bar"),
|
||||
context.getAsync("#_.foo"),
|
||||
context.keysAsync("#_")
|
||||
@@ -333,7 +332,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#test.foo","test"),
|
||||
context.getAsync("#test.foo"),
|
||||
context.keysAsync("#test")
|
||||
@@ -348,7 +347,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.flow.setAsync("#test.foo","test"),
|
||||
context.flow.getAsync("#test.foo"),
|
||||
context.flow.keysAsync("#test")
|
||||
@@ -363,7 +362,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.global.setAsync("#test.foo","test"),
|
||||
context.global.getAsync("#test.foo"),
|
||||
context.global.keysAsync("#test")
|
||||
@@ -378,7 +377,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextDefaultStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#nonexist.foo","test"),
|
||||
context.getAsync("#nonexist.foo"),
|
||||
context.keysAsync("#nonexist")
|
||||
@@ -396,7 +395,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextDefaultStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#default.foo","default"),
|
||||
context.getAsync("#default.foo"),
|
||||
context.keysAsync("#default")
|
||||
@@ -414,7 +413,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextDefaultStorage});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#.foo","alias"),
|
||||
context.getAsync("#.foo"),
|
||||
context.keysAsync("#")
|
||||
@@ -432,7 +431,7 @@ describe('context', function() {
|
||||
Context.init({contextStorage:contextAlias});
|
||||
return Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#.foo","alias"),
|
||||
context.getAsync("#.foo"),
|
||||
context.keysAsync("#")
|
||||
@@ -510,7 +509,7 @@ describe('context', function() {
|
||||
return Context.close();
|
||||
});
|
||||
it('should work correctly with the valid key name',function() {
|
||||
return when.all([
|
||||
return Promise.all([
|
||||
context.setAsync("#memory.azAZ09#_","valid"),
|
||||
context.setAsync("#memory.a.b","ab")
|
||||
]).then(function(){
|
||||
|
@@ -17,7 +17,6 @@
|
||||
var should = require('should');
|
||||
var fs = require('fs-extra');
|
||||
var path = require("path");
|
||||
var when = require("when");
|
||||
var LocalFileSystem = require('../../../../../red/runtime/nodes/context/localfilesystem');
|
||||
|
||||
var resourcesDir = path.resolve(path.join(__dirname,"..","resources","context"));
|
||||
@@ -76,14 +75,14 @@ describe('localfilesystem',function() {
|
||||
});
|
||||
|
||||
it('should not shared context with other scope', function() {
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
]).then(function(){
|
||||
return when.all([context.setAsync("nodeX","foo","testX"),
|
||||
context.setAsync("nodeY","foo","testY")])
|
||||
return Promise.all([context.setAsync("nodeX","foo","testX"),
|
||||
context.setAsync("nodeY","foo","testY")])
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.equal("testX"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("testY")]);
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("testX"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("testY")]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -234,19 +233,19 @@ describe('localfilesystem',function() {
|
||||
});
|
||||
|
||||
it('should enumerate context keys in each scopes', function() {
|
||||
return when.all([context.keysAsync("nodeX"),
|
||||
context.keysAsync("nodeY")
|
||||
return Promise.all([context.keysAsync("nodeX"),
|
||||
context.keysAsync("nodeY")
|
||||
]).then(function(results){
|
||||
results[0].should.be.an.Array();
|
||||
results[0].should.be.empty();
|
||||
results[1].should.be.an.Array();
|
||||
results[1].should.be.empty();
|
||||
}).then(function(){
|
||||
return when.all([context.setAsync("nodeX","foo","bar"),
|
||||
context.setAsync("nodeY","hoge","piyo")]);
|
||||
return Promise.all([context.setAsync("nodeX","foo","bar"),
|
||||
context.setAsync("nodeY","hoge","piyo")]);
|
||||
}).then(function(){
|
||||
return when.all([context.keysAsync("nodeX"),
|
||||
context.keysAsync("nodeY")]);
|
||||
return Promise.all([context.keysAsync("nodeX"),
|
||||
context.keysAsync("nodeY")]);
|
||||
}).then(function(results){
|
||||
results[0].should.have.length(1);
|
||||
results[0][0].should.equal("foo");
|
||||
@@ -258,55 +257,55 @@ describe('localfilesystem',function() {
|
||||
|
||||
describe('#delete',function() {
|
||||
it('should delete context',function() {
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
]).then(function(){
|
||||
return when.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
return Promise.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
}).then(function(){
|
||||
return context.delete("nodeX");
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]);
|
||||
});
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clean',function() {
|
||||
it('should clean unnecessary context',function() {
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
]).then(function(values){
|
||||
return when.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
]).then(function(){
|
||||
return Promise.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
}).then(function(){
|
||||
return context.clean([]);
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()]);
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not clean active context',function() {
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()
|
||||
]).then(function(){
|
||||
return when.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
return Promise.all([context.setAsync("nodeX","foo","abc"),
|
||||
context.setAsync("nodeY","foo","abc")]);
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.equal("abc")])
|
||||
}).then(function(){
|
||||
return context.clean(["nodeX"]);
|
||||
}).then(function(){
|
||||
return when.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()]);
|
||||
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"),
|
||||
context.getAsync("nodeY","foo").should.be.finally.undefined()]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user