diff --git a/Gruntfile.js b/Gruntfile.js index 711b5c3..5505514 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,9 @@ module.exports = function (grunt) { grunt.initConfig({ shell: { + generateNode_getKeysInFlowContext: { + command: 'node bin/node-red-nodegen.js samples/get-keys-in-flow-context.js -o ./nodegen' + }, generateNode_handleClearInterval: { command: 'node bin/node-red-nodegen.js samples/handle-clearInterval.js -o ./nodegen' }, diff --git a/samples/get-keys-in-flow-context.js b/samples/get-keys-in-flow-context.js new file mode 100644 index 0000000..75f2dcd --- /dev/null +++ b/samples/get-keys-in-flow-context.js @@ -0,0 +1,4 @@ +// name: get keys in flow context +// outputs: 1 +msg.payload=flow.keys(); +return msg; \ No newline at end of file diff --git a/test/nodegen/node-red-contrib-get-keys-in-flow-context/node_spec.js b/test/nodegen/node-red-contrib-get-keys-in-flow-context/node_spec.js new file mode 100755 index 0000000..933dfb3 --- /dev/null +++ b/test/nodegen/node-red-contrib-get-keys-in-flow-context/node_spec.js @@ -0,0 +1,58 @@ +/** + * Copyright JS Foundation and other contributors, http://js.foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var should = require("should"); +var helper = require("node-red-node-test-helper"); +var functionNode = require("../../../nodegen/node-red-contrib-get-keys-in-flow-context"); + +describe('node-red-contrib-get-keys-in-flow-context', function () { + + before(function (done) { + helper.startServer(done); + }); + + after(function (done) { + helper.stopServer(done); + }); + + afterEach(function () { + helper.unload(); + }); + + it('should be loaded', function (done) { + var flow = [{id: "n1", type: "get-keys-in-flow-context", z: "flowA", name: "get-keys-in-flow-context" }]; + helper.load(functionNode, flow, function () { + var n1 = helper.getNode('n1'); + n1.should.have.property('name', 'get-keys-in-flow-context'); + done(); + }); + }); + it('should get keys in flow context()', function (done) { + var flow = [{id: "n1", type: "get-keys-in-flow-context", z: "flowA", wires: [["n2"]]}, + {id: "n2", type: "helper", z: "flowA"}]; + helper.load(functionNode, flow, function () { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n1.context().flow.set("count", "0"); + n2.on("input", function (msg) { + msg.should.have.property('topic', 'bar'); + msg.should.have.property('payload', ['count']); + done(); + }); + n1.receive({payload: "foo", topic: "bar"}); + }); + }); +});