1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Pass Date into the Function node sandbox to fix instanceof tests

This commit is contained in:
Nick O'Leary 2018-05-25 10:50:58 +01:00
parent 40f4167894
commit 252df81f59
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 17 additions and 0 deletions

View File

@ -80,6 +80,7 @@ module.exports = function(RED) {
console:console,
util:util,
Buffer:Buffer,
Date: Date,
RED: {
util: RED.util
},

View File

@ -508,6 +508,22 @@ describe('function node', function() {
});
});
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"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n1.context().global.set("typeTest",function(d) { return d instanceof Date });
n2.on("input", function(msg) {
msg.should.have.property('payload', true);
done();
});
n1.receive({payload:"foo",topic: "bar"});
});
});
describe('Logger', function () {
it('should log an Info Message', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "node.log('test');"}];