From 252df81f5963a76ea11619496a9aa38a1ebb0978 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 25 May 2018 10:50:58 +0100 Subject: [PATCH] Pass Date into the Function node sandbox to fix instanceof tests --- nodes/core/core/80-function.js | 1 + test/nodes/core/core/80-function_spec.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index 8aa95e4fc..0a7448ccd 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -80,6 +80,7 @@ module.exports = function(RED) { console:console, util:util, Buffer:Buffer, + Date: Date, RED: { util: RED.util }, diff --git a/test/nodes/core/core/80-function_spec.js b/test/nodes/core/core/80-function_spec.js index b96588b5b..f19e933dc 100644 --- a/test/nodes/core/core/80-function_spec.js +++ b/test/nodes/core/core/80-function_spec.js @@ -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');"}];