mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge remote-tracking branch 'upstream/0.19' into json-schema
This commit is contained in:
@@ -508,10 +508,37 @@ describe('function node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow accessing node.id', function(done) {
|
||||
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = node.id; return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(functionNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', n1.id);
|
||||
done();
|
||||
});
|
||||
n1.receive({payload:"foo",topicb: "bar"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow accessing node.name', function(done) {
|
||||
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload = node.name; return msg;", "name":"name of node"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(functionNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('payload', n1.name);
|
||||
done();
|
||||
});
|
||||
n1.receive({payload:"foo",topicb: "bar"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should use the same Date object from outside the sandbox', function(done) {
|
||||
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"msg.payload=global.get('typeTest')(new Date());return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(functionNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
|
@@ -428,13 +428,14 @@ describe('trigger node', function() {
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
if (c === 0) {
|
||||
console.log(c,Date.now() - ss,msg);
|
||||
msg.should.have.a.property("payload", "Hello");
|
||||
c += 1;
|
||||
}
|
||||
else {
|
||||
console.log(c,Date.now() - ss,msg);
|
||||
msg.should.have.a.property("payload", "World");
|
||||
//console.log(Date.now() - ss);
|
||||
(Date.now() - ss).should.be.greaterThan(140);
|
||||
(Date.now() - ss).should.be.greaterThan(150);
|
||||
done();
|
||||
}
|
||||
}
|
||||
@@ -444,7 +445,7 @@ describe('trigger node', function() {
|
||||
n1.emit("input", {payload:"Hello"});
|
||||
setTimeout( function() {
|
||||
n1.emit("input", {payload:"Error"});
|
||||
},20);
|
||||
},30);
|
||||
setTimeout( function() {
|
||||
n1.emit("input", {payload:"World"});
|
||||
},150);
|
||||
|
89
test/nodes/core/hardware/36-rpi-gpio_spec.js
Normal file
89
test/nodes/core/hardware/36-rpi-gpio_spec.js
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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 rpi = require("../../../../nodes/core/hardware/36-rpi-gpio.js");
|
||||
var helper = require("node-red-node-test-helper");
|
||||
var fs = require("fs");
|
||||
|
||||
describe('RPI GPIO Node', function() {
|
||||
|
||||
before(function(done) {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
||||
var checkIgnore = function(done) {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
var logEvents = helper.log().args.filter(function(evt) {
|
||||
return ((evt[0].level == 30) && (evt[0].msg.indexOf("rpi-gpio")===0));
|
||||
});
|
||||
logEvents[0][0].should.have.a.property('msg');
|
||||
logEvents[0][0].msg.toString().should.startWith("rpi-gpio : rpi-gpio.errors.ignorenode");
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
},25);
|
||||
}
|
||||
|
||||
it('should load Input node', function(done) {
|
||||
var flow = [{id:"n1", type:"rpi-gpio in", name:"rpi-gpio in" }];
|
||||
helper.load(rpi, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property('name', 'rpi-gpio in');
|
||||
try {
|
||||
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
|
||||
if (cpuinfo.indexOf(": BCM") === 1) {
|
||||
done(); // It's ON a PI ... should really do more tests !
|
||||
} else {
|
||||
checkIgnore(done);
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
checkIgnore(done);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should load Output node', function(done) {
|
||||
var flow = [{id:"n1", type:"rpi-gpio out", name:"rpi-gpio out" }];
|
||||
helper.load(rpi, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property('name', 'rpi-gpio out');
|
||||
try {
|
||||
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
|
||||
if (cpuinfo.indexOf(": BCM") === 1) {
|
||||
done(); // It's ON a PI ... should really do more tests !
|
||||
} else {
|
||||
checkIgnore(done);
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
checkIgnore(done);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -796,6 +796,25 @@ describe('HTTP Request Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should prevent following redirect when msg.followRedirects is false', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"txt",url:getTestURL('/redirectToText')},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('statusCode',302);
|
||||
msg.should.have.property('responseUrl', getTestURL('/redirectToText'));
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({payload:"foo",followRedirects:false});
|
||||
});
|
||||
});
|
||||
|
||||
it('shuold output an error when request timeout occurred', function(done) {
|
||||
var flow = [{id:"n1",type:"http request",wires:[["n2"]],method:"GET",ret:"obj",url:getTestURL('/timeout')},
|
||||
{id:"n2", type:"helper"}];
|
||||
@@ -806,7 +825,13 @@ describe('HTTP Request Node', function() {
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('statusCode','ECONNRESET');
|
||||
msg.should.have.property('statusCode','ESOCKETTIMEDOUT');
|
||||
var logEvents = helper.log().args.filter(function(evt) {
|
||||
return evt[0].type == 'http request';
|
||||
});
|
||||
logEvents.should.have.length(1);
|
||||
var tstmp = logEvents[0][0].timestamp;
|
||||
logEvents[0][0].should.eql({level:helper.log().ERROR, id:'n1',type:'http request',msg:'common.notification.errors.no-response', timestamp:tstmp});
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
|
@@ -390,7 +390,7 @@ describe('change Node', function() {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('sets the value of the message property to the current timestamp', function(done) {
|
||||
var flow = [{"id":"changeNode1","type":"change","rules":[{"t":"set","p":"ts","pt":"msg","to":"","tot":"date"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
@@ -409,6 +409,33 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('env var', function() {
|
||||
before(function() {
|
||||
process.env.NR_TEST_A = 'foo';
|
||||
})
|
||||
after(function() {
|
||||
delete process.env.NR_TEST_A;
|
||||
})
|
||||
it('sets the value using env property', function(done) {
|
||||
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","pt":"msg","to":"NR_TEST_A","tot":"env"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(changeNode, flow, function() {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
try {
|
||||
msg.payload.should.equal("foo");
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.receive({payload:"123",topic:"ABC"});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('changes the value using jsonata', function(done) {
|
||||
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$length(payload)","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
@@ -872,6 +899,33 @@ describe('change Node', function() {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
|
||||
describe('env var', function() {
|
||||
before(function() {
|
||||
process.env.NR_TEST_A = 'foo';
|
||||
})
|
||||
after(function() {
|
||||
delete process.env.NR_TEST_A;
|
||||
})
|
||||
it('changes the value using env property', function(done) {
|
||||
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"NR_TEST_A","fromt":"msg","tot":"env"}],"name":"changeNode","wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(changeNode, flow, function() {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
try {
|
||||
msg.payload.should.equal("abcfooabc");
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.receive({payload:"abcABCabc",topic:"ABC"});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("#delete", function() {
|
||||
|
Reference in New Issue
Block a user