mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
merge to latest
This commit is contained in:
@@ -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() {
|
||||
|
@@ -35,10 +35,17 @@ describe('flows/util', function() {
|
||||
});
|
||||
|
||||
describe('#mapEnvVarProperties',function() {
|
||||
it('handles ENV substitutions in an object', function() {
|
||||
before(function() {
|
||||
process.env.foo1 = "bar1";
|
||||
process.env.foo2 = "bar2";
|
||||
process.env.foo3 = "bar3";
|
||||
})
|
||||
after(function() {
|
||||
delete process.env.foo1;
|
||||
delete process.env.foo2;
|
||||
delete process.env.foo3;
|
||||
})
|
||||
it('handles ENV substitutions in an object - $()', function() {
|
||||
var foo = {a:"$(foo1)",b:"$(foo2)",c:{d:"$(foo3)"}};
|
||||
for (var p in foo) {
|
||||
if (foo.hasOwnProperty(p)) {
|
||||
@@ -47,6 +54,15 @@ describe('flows/util', function() {
|
||||
}
|
||||
foo.should.eql({ a: 'bar1', b: 'bar2', c: { d: 'bar3' } } );
|
||||
});
|
||||
it('handles ENV substitutions in an object - ${}', function() {
|
||||
var foo = {a:"${foo1}",b:"${foo2}",c:{d:"${foo3}"}};
|
||||
for (var p in foo) {
|
||||
if (foo.hasOwnProperty(p)) {
|
||||
flowUtil.mapEnvVarProperties(foo,p);
|
||||
}
|
||||
}
|
||||
foo.should.eql({ a: 'bar1', b: 'bar2', c: { d: 'bar3' } } );
|
||||
});
|
||||
});
|
||||
|
||||
describe('#diffNodes',function() {
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 393 B |
3
test/red/runtime/nodes/resources/local/TestNodeModule/node_modules/TestNodeModule/icons/arrow-in.png
generated
vendored
Normal file
3
test/red/runtime/nodes/resources/local/TestNodeModule/node_modules/TestNodeModule/icons/arrow-in.png
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
This file exists just to ensure the 'icons' directory is in the repository.
|
||||
TODO: a future test needs to ensure the right icon files are loaded - this
|
||||
directory can be used for that
|
@@ -307,6 +307,38 @@ describe("red/util", function() {
|
||||
},{});
|
||||
result.should.eql("123");
|
||||
});
|
||||
describe('environment variable', function() {
|
||||
before(function() {
|
||||
process.env.NR_TEST_A = "foo";
|
||||
process.env.NR_TEST_B = "${NR_TEST_A}";
|
||||
})
|
||||
after(function() {
|
||||
delete process.env.NR_TEST_A;
|
||||
delete process.env.NR_TEST_B;
|
||||
})
|
||||
|
||||
it('returns an environment variable - NR_TEST_A', function() {
|
||||
var result = util.evaluateNodeProperty('NR_TEST_A','env');
|
||||
result.should.eql('foo');
|
||||
});
|
||||
it('returns an environment variable - ${NR_TEST_A}', function() {
|
||||
var result = util.evaluateNodeProperty('${NR_TEST_A}','env');
|
||||
result.should.eql('foo');
|
||||
});
|
||||
it('returns an environment variable - ${NR_TEST_A', function() {
|
||||
var result = util.evaluateNodeProperty('${NR_TEST_A','env');
|
||||
result.should.eql('');
|
||||
});
|
||||
it('returns an environment variable - foo${NR_TEST_A}bar', function() {
|
||||
var result = util.evaluateNodeProperty('123${NR_TEST_A}456','env');
|
||||
result.should.eql('123foo456');
|
||||
});
|
||||
it('returns an environment variable - foo${NR_TEST_B}bar', function() {
|
||||
var result = util.evaluateNodeProperty('123${NR_TEST_B}456','env');
|
||||
result.should.eql('123${NR_TEST_A}456');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalisePropertyExpression', function() {
|
||||
|
Reference in New Issue
Block a user