Skip to content

Commit 02437be

Browse files
Merge pull request #37 from kazuhitoyokoi/master
2 parents ebdfa64 + f16d5e9 commit 02437be

File tree

13 files changed

+382
-0
lines changed

13 files changed

+382
-0
lines changed

Gruntfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ module.exports = function (grunt) {
44
generate_nodes: {
55
command: [
66
'mkdir nodegen',
7+
'node bin/node-red-nodegen.js samples/handle-clearInterval.js -o ./nodegen',
8+
'node bin/node-red-nodegen.js samples/handle-setInterval.js -o ./nodegen',
9+
'node bin/node-red-nodegen.js samples/handle-setTimeout.js -o ./nodegen',
10+
'node bin/node-red-nodegen.js samples/log-a-Warning-Message.js -o ./nodegen',
11+
'node bin/node-red-nodegen.js samples/log-an-Error-Message.js -o ./nodegen',
12+
'node bin/node-red-nodegen.js samples/log-an-Info-Message.js -o ./nodegen',
713
'node bin/node-red-nodegen.js samples/lower-case.js -o ./nodegen',
814
'node bin/node-red-nodegen.js http://petstore.swagger.io/v2/swagger.json -o ./nodegen'
915
].join(';')

samples/handle-clearInterval.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// name: handle clearInterval
2+
// outputs: 1
3+
var id=setInterval(null,100);
4+
setTimeout(function(){clearInterval(id);node.send(msg);},1000);

samples/handle-setInterval.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// name: handle setInterval
2+
// outputs: 1
3+
setInterval(function(){node.send(msg);},100);

samples/handle-setTimeout.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// name: handle setTimeout
2+
// outputs: 1
3+
setTimeout(function(){node.send(msg);},1000);

samples/log-a-Warning-Message.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// name: log a Warning Message
2+
// outputs: 1
3+
node.warn('test');

samples/log-an-Error-Message.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// name: log an Error Message
2+
// outputs: 1
3+
node.error('test');

samples/log-an-Info-Message.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// name: log an Info Message
2+
// outputs: 1
3+
node.log('test');
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright JS Foundation and other contributors, http://js.foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var helper = require("node-red-node-test-helper");
19+
var functionNode = require("../../../nodegen/node-red-contrib-handle-clear-interval");
20+
21+
describe('node-red-contrib-handle-clear-interval', function () {
22+
23+
before(function (done) {
24+
helper.startServer(done);
25+
});
26+
27+
afterEach(function () {
28+
helper.unload();
29+
});
30+
31+
it('should be loaded', function (done) {
32+
var flow = [{id: "n1", type: "handle-clear-interval", name: "handle-clear-interval" }];
33+
helper.load(functionNode, flow, function () {
34+
var n1 = helper.getNode('n1');
35+
n1.should.have.property('name', 'handle-clear-interval');
36+
done();
37+
});
38+
});
39+
it('should handle clearInterval()', function (done) {
40+
var flow = [{id: "n1", type: "handle-clear-interval", wires: [["n2"]]},
41+
{id:"n2", type:"helper"}];
42+
helper.load(functionNode, flow, function () {
43+
var n1 = helper.getNode("n1");
44+
var n2 = helper.getNode("n2");
45+
n2.on("input", function(msg) {
46+
msg.should.have.property('topic', 'bar');
47+
msg.should.have.property('payload', 'foo');
48+
done();
49+
});
50+
n1.receive({payload:"foo",topic: "bar"});
51+
});
52+
});
53+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright JS Foundation and other contributors, http://js.foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var helper = require("node-red-node-test-helper");
19+
var functionNode = require("../../../nodegen/node-red-contrib-handle-set-interval");
20+
21+
describe('node-red-contrib-handle-set-interval', function () {
22+
23+
before(function (done) {
24+
helper.startServer(done);
25+
});
26+
27+
afterEach(function () {
28+
helper.unload();
29+
});
30+
31+
it('should be loaded', function (done) {
32+
var flow = [{id: "n1", type: "handle-set-interval", name: "handle-set-interval" }];
33+
helper.load(functionNode, flow, function () {
34+
var n1 = helper.getNode('n1');
35+
n1.should.have.property('name', 'handle-set-interval');
36+
done();
37+
});
38+
});
39+
it('should handle setInterval()', function (done) {
40+
var flow = [{id: "n1", type: "handle-set-interval", wires: [["n2"]]},
41+
{id:"n2", type:"helper"}];
42+
helper.load(functionNode, flow, function () {
43+
var n1 = helper.getNode("n1");
44+
var n2 = helper.getNode("n2");
45+
var count = 0;
46+
n2.on("input", function(msg) {
47+
msg.should.have.property('topic', 'bar');
48+
msg.should.have.property('payload', 'foo');
49+
count++;
50+
if (count > 2) {
51+
done();
52+
}
53+
});
54+
n1.receive({payload:"foo",topic: "bar"});
55+
});
56+
});
57+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright JS Foundation and other contributors, http://js.foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var helper = require("node-red-node-test-helper");
19+
var functionNode = require("../../../nodegen/node-red-contrib-handle-set-timeout");
20+
21+
describe('node-red-contrib-handle-set-timeout', function () {
22+
23+
before(function (done) {
24+
helper.startServer(done);
25+
});
26+
27+
afterEach(function () {
28+
helper.unload();
29+
});
30+
31+
it('should be loaded', function (done) {
32+
var flow = [{id: "n1", type: "handle-set-timeout", name: "handle-set-timeout" }];
33+
helper.load(functionNode, flow, function () {
34+
var n1 = helper.getNode('n1');
35+
n1.should.have.property('name', 'handle-set-timeout');
36+
done();
37+
});
38+
});
39+
it('should handle setTimeout()', function (done) {
40+
var flow = [{id: "n1", type: "handle-set-timeout", wires: [["n2"]]},
41+
{id:"n2", type:"helper"}];
42+
helper.load(functionNode, flow, function () {
43+
var n1 = helper.getNode("n1");
44+
var n2 = helper.getNode("n2");
45+
n2.on("input", function(msg) {
46+
var endTime = process.hrtime(startTime);
47+
var nanoTime = endTime[0] * 1000000000 + endTime[1];
48+
msg.should.have.property('topic', 'bar');
49+
msg.should.have.property('payload', 'foo');
50+
if (900000000 < nanoTime && nanoTime < 1100000000) {
51+
done();
52+
} else {
53+
try {
54+
should.fail(null, null, "Delayed time was not between 900 and 1100 ms");
55+
} catch (err) {
56+
done(err);
57+
}
58+
}
59+
});
60+
var startTime = process.hrtime();
61+
n1.receive({payload:"foo",topic: "bar"});
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)