mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Restore expended env var tests
This commit is contained in:
parent
51a0b68d8e
commit
8db2972288
@ -3,7 +3,7 @@ var config = require("nr-test-utils").require("@node-red/nodes/core/common/91-gl
|
|||||||
var inject = require("nr-test-utils").require("@node-red/nodes/core/common/20-inject.js");
|
var inject = require("nr-test-utils").require("@node-red/nodes/core/common/20-inject.js");
|
||||||
var helper = require("node-red-node-test-helper");
|
var helper = require("node-red-node-test-helper");
|
||||||
|
|
||||||
describe('unknown Node', function() {
|
describe('Global Config Node', function() {
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
helper.unload();
|
helper.unload();
|
||||||
@ -44,4 +44,30 @@ describe('unknown Node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should evaluate a global environment variable that is a JSONata value', function (done) {
|
||||||
|
const flow = [{
|
||||||
|
id: "n1", type: "global-config", name: "XYZ",
|
||||||
|
env: [
|
||||||
|
{ name: "now-var", type: "jsonata", value: "$millis()" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ id: "n2", type: "inject", topic: "t1", payload: "now-var", payloadType: "env", wires: [["n3"]], z: "flow" },
|
||||||
|
{ id: "n3", type: "helper" }
|
||||||
|
];
|
||||||
|
helper.load([config, inject], flow, function () {
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
var n3 = helper.getNode("n3");
|
||||||
|
n3.on("input", (msg) => {
|
||||||
|
try {
|
||||||
|
const now = Date.now();
|
||||||
|
msg.should.have.property("payload").and.be.approximately(now, 1000);
|
||||||
|
done();
|
||||||
|
} catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
n2.receive({});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -686,7 +686,7 @@ describe('Flow', function() {
|
|||||||
},50);
|
},50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only("passes a status event to the group scoped status node",function(done) {
|
it("passes a status event to the group scoped status node",function(done) {
|
||||||
var config = flowUtils.parseConfig([
|
var config = flowUtils.parseConfig([
|
||||||
{id:"t1",type:"tab"},
|
{id:"t1",type:"tab"},
|
||||||
{id: "g1", type: "group", g: "g3" },
|
{id: "g1", type: "group", g: "g3" },
|
||||||
@ -1311,33 +1311,42 @@ describe('Flow', function() {
|
|||||||
})
|
})
|
||||||
process.env.V0 = "gv0";
|
process.env.V0 = "gv0";
|
||||||
process.env.V1 = "gv1";
|
process.env.V1 = "gv1";
|
||||||
|
process.env.V3 = "gv3";
|
||||||
var config = flowUtils.parseConfig([
|
var config = flowUtils.parseConfig([
|
||||||
{id:"t1",type:"tab",env:[
|
{id:"t1",type:"tab",env:[
|
||||||
{"name": "V0", value: "v0", type: "str"}
|
{"name": "V0", value: "t1v0", type: "str"},
|
||||||
|
{"name": "V2", value: "t1v2", type: "str"}
|
||||||
]},
|
]},
|
||||||
{id:"g1",type:"group",z:"t1",env:[
|
{id:"g1",type:"group",z:"t1",env:[
|
||||||
{"name": "V0", value: "v1", type: "str"},
|
{"name": "V0", value: "g1v0", type: "str"},
|
||||||
{"name": "V1", value: "v2", type: "str"}
|
{"name": "V1", value: "g1v1", type: "str"}
|
||||||
]},
|
]},
|
||||||
{id:"g2",type:"group",z:"t1",g:"g1",env:[
|
{id:"g2",type:"group",z:"t1",g:"g1",env:[
|
||||||
{"name": "V1", value: "v3", type: "str"}
|
{"name": "V1", value: "g2v1", type: "str"}
|
||||||
]},
|
]},
|
||||||
{id:"1",x:10,y:10,z:"t1",type:"test",foo:"$(V0)",wires:[]},
|
{id:"t1__V0",x:10,y:10,z:"t1",type:"test",foo:"${V0}",wires:[]}, // V0 will come from tab env V0
|
||||||
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V0)",wires:[]},
|
{id:"t1g1V0",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${V0}",wires:[]}, // V0 will come from group 1 env V0
|
||||||
{id:"3",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V1)",wires:[]},
|
{id:"t1g1V1",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"${V1}",wires:[]}, // V1 will come from group 1 env V1
|
||||||
{id:"4",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"$(V1)",wires:[]},
|
{id:"t1g2V0",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V0}",wires:[]}, // V0 will come from group 1 env V0
|
||||||
{id:"5",x:10,y:10,z:"t1",type:"test",foo:"$(V1)",wires:[]},
|
{id:"t1g2V1",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V1}",wires:[]}, // V1 will come from group 2 env V1
|
||||||
|
{id:"t1g2V2",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V2}",wires:[]}, // V2 will come from tab 1 env V2
|
||||||
|
{id:"t1g2V3",x:10,y:10,z:"t1",g:"g2",type:"test",foo:"${V3}",wires:[]}, // V3 will come from process env V3
|
||||||
|
|
||||||
|
{id:"t1__V1",x:10,y:10,z:"t1",type:"test",foo:"${V1}",wires:[]},
|
||||||
]);
|
]);
|
||||||
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
||||||
flow.start();
|
flow.start();
|
||||||
|
|
||||||
var activeNodes = flow.getActiveNodes();
|
var activeNodes = flow.getActiveNodes();
|
||||||
|
|
||||||
activeNodes["1"].foo.should.equal("v0");
|
activeNodes.t1__V0.foo.should.equal("t1v0"); // node in tab 1, get tab 1 env V0
|
||||||
activeNodes["2"].foo.should.equal("v1");
|
activeNodes.t1__V1.foo.should.equal("gv1"); // node in tab 1, get V1, (tab 1 no V1) --> parent (global has V1)
|
||||||
activeNodes["3"].foo.should.equal("v2");
|
activeNodes.t1g1V0.foo.should.equal("g1v0"); // node in group 1, get V0, (group 1 has V0)
|
||||||
activeNodes["4"].foo.should.equal("v3");
|
activeNodes.t1g1V1.foo.should.equal("g1v1"); // node in group 1, get V1, (group 1 has V1)
|
||||||
activeNodes["5"].foo.should.equal("gv1");
|
activeNodes.t1g2V0.foo.should.equal("g1v0"); // node in group 2, get V0, (group 2 no V0) --> parent (group 1 has V0)
|
||||||
|
activeNodes.t1g2V1.foo.should.equal("g2v1"); // node in group 2, get V1, (group 2 has V1)
|
||||||
|
activeNodes.t1g2V2.foo.should.equal("t1v2"); // node in group 2, get V2, (group 2 no V2) --> parent (tab 1 has V2)
|
||||||
|
activeNodes.t1g2V3.foo.should.equal("gv3"); // node in group 2, get V3, (group 2 no V3) --> parent (tab 1 no V2) --> parent (global has V3)
|
||||||
|
|
||||||
flow.stop().then(function() {
|
flow.stop().then(function() {
|
||||||
done();
|
done();
|
||||||
@ -1347,7 +1356,6 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
it("can access environment variable property using $parent", function (done) {
|
it("can access environment variable property using $parent", function (done) {
|
||||||
try {
|
try {
|
||||||
@ -1393,7 +1401,6 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can define environment variable using JSONata", function (done) {
|
it("can define environment variable using JSONata", function (done) {
|
||||||
@ -1427,9 +1434,40 @@ describe('Flow', function() {
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can access global environment variables defined as JSONata values", function (done) {
|
||||||
|
try {
|
||||||
|
after(function() {
|
||||||
|
delete process.env.V0;
|
||||||
|
})
|
||||||
|
var config = flowUtils.parseConfig([
|
||||||
|
{id:"t1",type:"tab",env:[
|
||||||
|
{"name": "V0", value: "1+2", type: "jsonata"}
|
||||||
|
]},
|
||||||
|
{id:"g1",type:"group",z:"t1",env:[
|
||||||
|
{"name": "V1", value: "2+3", type: "jsonata"},
|
||||||
|
]},
|
||||||
|
{id:"1",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V0)",wires:[]},
|
||||||
|
{id:"2",x:10,y:10,z:"t1",g:"g1",type:"test",foo:"$(V1)",wires:[]},
|
||||||
|
]);
|
||||||
|
var flow = Flow.create({getSetting:v=>process.env[v]},config,config.flows["t1"]);
|
||||||
|
flow.start();
|
||||||
|
|
||||||
|
var activeNodes = flow.getActiveNodes();
|
||||||
|
|
||||||
|
activeNodes["1"].foo.should.equal(3);
|
||||||
|
activeNodes["2"].foo.should.equal(5);
|
||||||
|
|
||||||
|
flow.stop().then(function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log(e.stack);
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -489,7 +489,7 @@ describe('storage/localfilesystem', function() {
|
|||||||
var rootdir = path.win32.resolve(userDir+'/some');
|
var rootdir = path.win32.resolve(userDir+'/some');
|
||||||
// make it into a local UNC path
|
// make it into a local UNC path
|
||||||
flowFile = flowFile.replace('C:\\', '\\\\localhost\\c$\\');
|
flowFile = flowFile.replace('C:\\', '\\\\localhost\\c$\\');
|
||||||
localfilesystem.init({userDir:userDir, flowFile:flowFile}, mockRuntime).then(function() {
|
localfilesystem.init({userDir:userDir, flowFile:flowFile, getUserSettings: () => {{}}}, mockRuntime).then(function() {
|
||||||
fs.existsSync(flowFile).should.be.false();
|
fs.existsSync(flowFile).should.be.false();
|
||||||
localfilesystem.saveFlows(testFlow).then(function() {
|
localfilesystem.saveFlows(testFlow).then(function() {
|
||||||
fs.existsSync(flowFile).should.be.true();
|
fs.existsSync(flowFile).should.be.true();
|
||||||
|
Loading…
Reference in New Issue
Block a user