mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #1803 from kazuhitoyokoi/0.19-addtestcases
Add test cases of persistable context for trigger node
This commit is contained in:
commit
24505ee4f5
@ -21,8 +21,7 @@ var helper = require("node-red-node-test-helper");
|
|||||||
|
|
||||||
describe('inject node', function() {
|
describe('inject node', function() {
|
||||||
|
|
||||||
before(function(done) {
|
beforeEach(function(done) {
|
||||||
helper.startServer(done);
|
|
||||||
Context.init({
|
Context.init({
|
||||||
contextStorage: {
|
contextStorage: {
|
||||||
memory: {
|
memory: {
|
||||||
@ -30,17 +29,19 @@ describe('inject node', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Context.load();
|
Context.load().then(function () {
|
||||||
|
helper.startServer(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function(done) {
|
afterEach(function(done) {
|
||||||
helper.stopServer(done);
|
helper.unload().then(function () {
|
||||||
});
|
return Context.clean({allNodes: {}});
|
||||||
|
}).then(function () {
|
||||||
afterEach(function() {
|
return Context.close();
|
||||||
helper.unload();
|
}).then(function () {
|
||||||
Context.clean({allNodes: {}});
|
helper.stopServer(done);
|
||||||
Context.close();
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets the value of flow context property', function (done) {
|
it('sets the value of flow context property', function (done) {
|
||||||
|
@ -18,16 +18,30 @@ var should = require("should");
|
|||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var helper = require("node-red-node-test-helper");
|
var helper = require("node-red-node-test-helper");
|
||||||
var triggerNode = require("../../../../nodes/core/core/89-trigger.js");
|
var triggerNode = require("../../../../nodes/core/core/89-trigger.js");
|
||||||
|
var Context = require("../../../../red/runtime/nodes/context");
|
||||||
var RED = require("../../../../red/red.js");
|
var RED = require("../../../../red/red.js");
|
||||||
|
|
||||||
describe('trigger node', function() {
|
describe('trigger node', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helper.startServer(done);
|
Context.init({
|
||||||
|
contextStorage: {
|
||||||
|
memory: {
|
||||||
|
module: "memory"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Context.load().then(function () {
|
||||||
|
helper.startServer(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
helper.unload().then(function() {
|
helper.unload().then(function () {
|
||||||
|
return Context.clean({allNodes: {}});
|
||||||
|
}).then(function () {
|
||||||
|
return Context.close();
|
||||||
|
}).then(function () {
|
||||||
helper.stopServer(done);
|
helper.stopServer(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -312,7 +326,33 @@ describe('trigger node', function() {
|
|||||||
});
|
});
|
||||||
n1.emit("input", {payload:null});
|
n1.emit("input", {payload:null});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to return things from persistable flow and global context variables', function (done) {
|
||||||
|
var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory)::foo", "op1type": "flow",
|
||||||
|
"op2": "#:(memory)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" },
|
||||||
|
{"id": "n2", "type": "helper"}];
|
||||||
|
helper.load(triggerNode, flow, function () {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
var c = 0;
|
||||||
|
n2.on("input", function (msg) {
|
||||||
|
try {
|
||||||
|
if (c === 0) {
|
||||||
|
msg.should.have.a.property("payload", "foo");
|
||||||
|
c += 1;
|
||||||
|
} else {
|
||||||
|
msg.should.have.a.property("payload", "bar");
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n1.context().flow.set("foo", "foo");
|
||||||
|
n1.context().global.set("bar", "bar");
|
||||||
|
n1.emit("input", { payload: null });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to not output anything on first trigger', function(done) {
|
it('should be able to not output anything on first trigger', function(done) {
|
||||||
|
@ -24,7 +24,6 @@ var helper = require("node-red-node-test-helper");
|
|||||||
describe('change Node', function() {
|
describe('change Node', function() {
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helper.startServer(done);
|
|
||||||
Context.init({
|
Context.init({
|
||||||
contextStorage: {
|
contextStorage: {
|
||||||
memory: {
|
memory: {
|
||||||
@ -32,14 +31,19 @@ describe('change Node', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Context.load();
|
Context.load().then(function () {
|
||||||
|
helper.startServer(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
helper.unload();
|
helper.unload().then(function () {
|
||||||
helper.stopServer(done);
|
return Context.clean({allNodes: {}});
|
||||||
Context.clean({allNodes:{}});
|
}).then(function () {
|
||||||
Context.close();
|
return Context.close();
|
||||||
|
}).then(function () {
|
||||||
|
helper.stopServer(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load node with defaults', function(done) {
|
it('should load node with defaults', function(done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user