mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'dev' into debug-node-with-jsonata
This commit is contained in:
@@ -1,178 +0,0 @@
|
||||
/**
|
||||
* 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 sentimentNode = require("nr-test-utils").require("@node-red/nodes/core/analysis/72-sentiment.js");
|
||||
var helper = require("node-red-node-test-helper");
|
||||
|
||||
describe('sentiment Node', function() {
|
||||
|
||||
before(function(done) {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
||||
it('should be loaded', function(done) {
|
||||
var flow = [{id:"sentimentNode1", type:"sentiment", name: "sentimentNode" }];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var sentimentNode1 = helper.getNode("sentimentNode1");
|
||||
sentimentNode1.should.have.property('name', 'sentimentNode');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass on msg if no payload', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.not.have.property('sentiment');
|
||||
msg.topic.should.equal("pass on");
|
||||
done();
|
||||
});
|
||||
var testString = 'good, great, best, brilliant';
|
||||
jn1.receive({topic:"pass on"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a positive score for good words', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.above(10);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
var testString = 'good, great, best, brilliant';
|
||||
jn1.receive({payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a positive score for good words - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.above(10);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
var testString = 'good, great, best, brilliant';
|
||||
jn1.receive({foo:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a negative score for bad words', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.below(-10);
|
||||
done();
|
||||
});
|
||||
var testString = 'bad, horrible, negative, awful';
|
||||
jn1.receive({payload:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a negative score for bad words - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.below(-10);
|
||||
done();
|
||||
});
|
||||
var testString = 'bad, horrible, negative, awful';
|
||||
jn1.receive({foo:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow you to override word scoring', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.equal(20);
|
||||
done();
|
||||
});
|
||||
var testString = 'sick, wicked';
|
||||
var overrides = {'sick': 10, 'wicked': 10 };
|
||||
jn1.receive({payload:testString,overrides:overrides});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow you to override word scoring - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.equal(20);
|
||||
done();
|
||||
});
|
||||
var testString = 'sick, wicked';
|
||||
var overrides = {'sick': 10, 'wicked': 10 };
|
||||
jn1.receive({foo:testString,overrides:overrides});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -52,30 +52,30 @@ describe('inject node', function() {
|
||||
});
|
||||
|
||||
function basicTest(type, val, rval) {
|
||||
it('inject value ('+type+')', function (done) {
|
||||
it('inject value ('+type+')', function (done) {
|
||||
var flow = [{id: "n1", type: "inject", topic: "t1", payload: val, payloadType: type, wires: [["n2"]], z: "flow"},
|
||||
{id: "n2", type: "helper"}];
|
||||
{id: "n2", type: "helper"}];
|
||||
helper.load(injectNode, flow, function () {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function (msg) {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function (msg) {
|
||||
try {
|
||||
msg.should.have.property("topic", "t1");
|
||||
if (rval) {
|
||||
msg.should.have.property("payload");
|
||||
should.deepEqual(msg.payload, rval);
|
||||
}
|
||||
else {
|
||||
msg.should.have.property("payload", val);
|
||||
}
|
||||
done();
|
||||
msg.should.have.property("topic", "t1");
|
||||
if (rval) {
|
||||
msg.should.have.property("payload");
|
||||
should.deepEqual(msg.payload, rval);
|
||||
}
|
||||
else {
|
||||
msg.should.have.property("payload", val);
|
||||
}
|
||||
done();
|
||||
} catch (err) {
|
||||
done(err);
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
n1.receive({});
|
||||
});
|
||||
n1.receive({});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
basicTest("num", 10);
|
||||
@@ -503,16 +503,21 @@ describe('inject node', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
helper.request()
|
||||
try {
|
||||
helper.request()
|
||||
.post('/inject/n1')
|
||||
.expect(200).end(function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return helper.clearFlows()
|
||||
.then(function () {
|
||||
done(err);
|
||||
});
|
||||
.then(function () {
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -207,6 +207,12 @@ describe('HTTP Request Node', function() {
|
||||
res.cookie('redirectToDifferentDomain','different1');
|
||||
res.redirect(getDifferentTestURL('/redirectReturn'));
|
||||
});
|
||||
testApp.get('/redirectMultipleTimes', function(req, res) {
|
||||
var key = req.headers.host + req.url;
|
||||
receivedCookies[key] = req.cookies;
|
||||
res.cookie('redirectMultipleTimes','multiple1');
|
||||
res.redirect(getTestURL('/redirectToDifferentDomain'));
|
||||
});
|
||||
testApp.get('/redirectReturn', function(req, res) {
|
||||
var key = req.headers.host + req.url;
|
||||
receivedCookies[key] = req.cookies;
|
||||
@@ -277,6 +283,7 @@ describe('HTTP Request Node', function() {
|
||||
msg.should.have.property('headers');
|
||||
msg.headers.should.have.property('content-length',''+('hello'.length));
|
||||
msg.headers.should.have.property('content-type').which.startWith('text/html');
|
||||
msg.redirectList.length.should.equal(0);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
@@ -1510,6 +1517,10 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://localhost:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToSameDomainCookie.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToSameDomainCookie.value.should.equal('same1');
|
||||
done();
|
||||
});
|
||||
n1.receive({});
|
||||
@@ -1533,6 +1544,10 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://127.0.0.1:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToDifferentDomain.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToDifferentDomain.value.should.equal('different1');
|
||||
done();
|
||||
});
|
||||
n1.receive({});
|
||||
@@ -1559,6 +1574,10 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://localhost:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToSameDomainCookie.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToSameDomainCookie.value.should.equal('same1');
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
@@ -1585,6 +1604,10 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://127.0.0.1:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToDifferentDomain.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToDifferentDomain.value.should.equal('different1');
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
@@ -1613,6 +1636,10 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://localhost:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToSameDomainCookie.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToSameDomainCookie.value.should.equal('same1');
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
@@ -1639,6 +1666,33 @@ describe('HTTP Request Node', function() {
|
||||
done(new Error('Invalid cookie(path:/rediectReurn)'));
|
||||
return;
|
||||
}
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://127.0.0.1:'+testPort+'/redirectReturn');
|
||||
redirect1.cookies.redirectToDifferentDomain.Path.should.equal('/');
|
||||
redirect1.cookies.redirectToDifferentDomain.value.should.equal('different1');
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
headers: { cookie: 'requestCookie=request1' }
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should return all redirect information when redirected multiple times', function(done) {
|
||||
var flow = [{id:'n1',type:'http request',wires:[['n2']],method:'GET',ret:'obj',url:getTestURL('/redirectMultipleTimes')},
|
||||
{id:"n2", type:"helper"}];
|
||||
receivedCookies = {};
|
||||
helper.load(httpRequestNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
var redirect1 = msg.redirectList[0];
|
||||
redirect1.location.should.equal('http://localhost:'+testPort+'/redirectToDifferentDomain');
|
||||
redirect1.cookies.redirectMultipleTimes.Path.should.equal('/');
|
||||
redirect1.cookies.redirectMultipleTimes.value.should.equal('multiple1');
|
||||
var redirect2 = msg.redirectList[1];
|
||||
redirect2.location.should.equal('http://127.0.0.1:'+testPort+'/redirectReturn');
|
||||
redirect2.cookies.redirectToDifferentDomain.Path.should.equal('/');
|
||||
redirect2.cookies.redirectToDifferentDomain.value.should.equal('different1');
|
||||
done();
|
||||
});
|
||||
n1.receive({
|
||||
|
@@ -1,206 +0,0 @@
|
||||
/**
|
||||
* 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 path = require('path');
|
||||
var os = require('os');
|
||||
var fs = require('fs-extra');
|
||||
var sinon = require('sinon');
|
||||
var tailNode = require("nr-test-utils").require("@node-red/nodes/core/storage/28-tail.js");
|
||||
var helper = require("node-red-node-test-helper");
|
||||
|
||||
describe('tail Node', function() {
|
||||
|
||||
var wait = 150;
|
||||
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
||||
var fileToTail = path.join(resourcesDir,"28-tail-test-file.txt");
|
||||
|
||||
beforeEach(function(done) {
|
||||
fs.writeFileSync(fileToTail, "Tail message line 1\nTail message line 2\n");
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
helper.unload().then(function() {
|
||||
fs.unlinkSync(fileToTail);
|
||||
helper.stopServer(done);
|
||||
});
|
||||
});
|
||||
|
||||
if (os.type() !== "Windows_NT") {
|
||||
it('should be loaded', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
tailNode1.should.have.property('name', 'tailNode');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should tail a file', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
var inputCounter = 0;
|
||||
helperNode1.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.should.equal("Tail message line " + (++inputCounter + 2));
|
||||
if (inputCounter === 2) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
setTimeout( function() {
|
||||
fs.appendFileSync(fileToTail, "Tail message line 3\n");
|
||||
fs.appendFileSync(fileToTail, "Tail message line 4\n");
|
||||
},wait);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work in non-split mode', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":false, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.should.equal("Tail message line 5\nTail message line 6\n");
|
||||
done();
|
||||
});
|
||||
setTimeout( function() {
|
||||
fs.appendFileSync(fileToTail, "Tail message line 5\nTail message line 6\n");
|
||||
},wait);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work in binary mode', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "filetype":"binary", "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.toString().should.equal("Tail message line 7\nTail message line 8\n");
|
||||
done();
|
||||
});
|
||||
setTimeout( function() {
|
||||
fs.appendFileSync(fileToTail, "Tail message line 7\nTail message line 8\n");
|
||||
},wait);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle a non-existent file', function(done) {
|
||||
fs.writeFileSync(fileToTail, "Tail message line.\n");
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
msg.payload.should.equal("Tail message line");
|
||||
done();
|
||||
});
|
||||
setTimeout(function() {
|
||||
fs.unlinkSync(fileToTail);
|
||||
},500);
|
||||
setTimeout( function() {
|
||||
fs.writeFile(fileToTail, "Tail message line\n");
|
||||
},1000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('should throw an error if run on Windows', function() {
|
||||
// Stub os platform so we can make it look like windows
|
||||
var os = require('os');
|
||||
var spy = sinon.stub(os, 'platform', function(arg) { return("windows"); });
|
||||
|
||||
/*jshint immed: false */
|
||||
try {
|
||||
(function() { tailNode("1234"); }).should.throw();
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
os.platform.restore();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
it('tail should handle file truncation', function(done) {
|
||||
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(tailNode, flow, function() {
|
||||
var tailNode1 = helper.getNode("tailNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
var inputCounter = 0;
|
||||
var warned = false;
|
||||
tailNode1.on("log", function(msg) {
|
||||
if (msg.level == "warn") { warned = true; }
|
||||
});
|
||||
helperNode1.on("input", function(msg) {
|
||||
console.log("inputCounter =",inputCounter);
|
||||
console.log(msg);
|
||||
msg.should.have.property('topic', fileToTail);
|
||||
inputCounter++;
|
||||
if (inputCounter === 1) {
|
||||
warned.should.be.false();
|
||||
msg.payload.should.equal("Tail message line append");
|
||||
} else if (inputCounter === 2) {
|
||||
msg.payload.should.equal("Tail message line truncate");
|
||||
} else {
|
||||
msg.payload.should.equal("Tail message line append "+inputCounter);
|
||||
}
|
||||
|
||||
if (inputCounter === 5) {
|
||||
setTimeout(function() {
|
||||
warned.should.be.true();
|
||||
done();
|
||||
},100);
|
||||
}
|
||||
});
|
||||
var actions = [
|
||||
function() { fs.appendFileSync(fileToTail, "Tail message line append\n");},
|
||||
function() { fs.writeFileSync(fileToTail, "Tail message line truncate\n");},
|
||||
function() { fs.appendFileSync(fileToTail, "Tail message line append 3\n");},
|
||||
function() { fs.appendFileSync(fileToTail, "Tail message line append 4\n");},
|
||||
function() { fs.appendFileSync(fileToTail, "Tail message line append 5\n");}
|
||||
];
|
||||
|
||||
function processAction() {
|
||||
var action = actions.shift();
|
||||
action();
|
||||
if (actions.length > 0) {
|
||||
setTimeout(function() {
|
||||
processAction();
|
||||
},250);
|
||||
}
|
||||
}
|
||||
setTimeout( function() {
|
||||
processAction();
|
||||
},wait);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
});
|
@@ -59,8 +59,8 @@ describe("api/index", function() {
|
||||
afterEach(afterEach);
|
||||
|
||||
it("does not setup admin api if httpAdminRoot is false", function(done) {
|
||||
api.init({},{ httpAdminRoot: false },{},{});
|
||||
should.not.exist(api.adminApp);
|
||||
api.init({ httpAdminRoot: false },{},{},{});
|
||||
should.not.exist(api.httpAdmin);
|
||||
done();
|
||||
});
|
||||
describe('initalises admin api without adminAuth', function(done) {
|
||||
@@ -70,30 +70,30 @@ describe("api/index", function() {
|
||||
});
|
||||
after(afterEach);
|
||||
it('exposes the editor',function(done) {
|
||||
request(api.adminApp).get("/editor").expect(200).end(done);
|
||||
request(api.httpAdmin).get("/editor").expect(200).end(done);
|
||||
})
|
||||
it('exposes the admin api',function(done) {
|
||||
request(api.adminApp).get("/admin").expect(200).end(done);
|
||||
request(api.httpAdmin).get("/admin").expect(200).end(done);
|
||||
})
|
||||
it('exposes the auth api',function(done) {
|
||||
request(api.adminApp).get("/auth/login").expect(200).end(done);
|
||||
request(api.httpAdmin).get("/auth/login").expect(200).end(done);
|
||||
})
|
||||
});
|
||||
|
||||
describe('initalises admin api without editor', function(done) {
|
||||
before(function() {
|
||||
beforeEach();
|
||||
api.init({},{ disableEditor: true },{},{});
|
||||
api.init({ disableEditor: true },{},{},{});
|
||||
});
|
||||
after(afterEach);
|
||||
it('does not expose the editor',function(done) {
|
||||
request(api.adminApp).get("/editor").expect(404).end(done);
|
||||
request(api.httpAdmin).get("/editor").expect(404).end(done);
|
||||
})
|
||||
it('exposes the admin api',function(done) {
|
||||
request(api.adminApp).get("/admin").expect(200).end(done);
|
||||
request(api.httpAdmin).get("/admin").expect(200).end(done);
|
||||
})
|
||||
it('exposes the auth api',function(done) {
|
||||
request(api.adminApp).get("/auth/login").expect(200).end(done)
|
||||
request(api.httpAdmin).get("/auth/login").expect(200).end(done)
|
||||
})
|
||||
});
|
||||
});
|
||||
|
20
test/unit/@node-red/registry/lib/util_spec.js
Normal file
20
test/unit/@node-red/registry/lib/util_spec.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
|
||||
describe("red/nodes/registry/util",function() {
|
||||
it.skip("NEEDS TESTS");
|
||||
});
|
@@ -25,6 +25,8 @@ var runtime = NR_TEST_UTILS.require("@node-red/runtime");
|
||||
var redNodes = NR_TEST_UTILS.require("@node-red/runtime/lib/nodes");
|
||||
var storage = NR_TEST_UTILS.require("@node-red/runtime/lib/storage");
|
||||
var settings = NR_TEST_UTILS.require("@node-red/runtime/lib/settings");
|
||||
var util = NR_TEST_UTILS.require("@node-red/util");
|
||||
|
||||
var log = NR_TEST_UTILS.require("@node-red/util").log;
|
||||
|
||||
describe("runtime", function() {
|
||||
@@ -41,6 +43,7 @@ describe("runtime", function() {
|
||||
delete process.env.NODE_RED_HOME;
|
||||
});
|
||||
function mockUtil(metrics) {
|
||||
|
||||
return {
|
||||
log:{
|
||||
log: sinon.stub(),
|
||||
@@ -95,6 +98,7 @@ describe("runtime", function() {
|
||||
var redNodesLoadFlows;
|
||||
var redNodesStartFlows;
|
||||
var redNodesLoadContextsPlugin;
|
||||
var i18nRegisterMessageCatalog;
|
||||
|
||||
beforeEach(function() {
|
||||
storageInit = sinon.stub(storage,"init",function(settings) {return Promise.resolve();});
|
||||
@@ -104,6 +108,7 @@ describe("runtime", function() {
|
||||
redNodesLoadFlows = sinon.stub(redNodes,"loadFlows",function() {return Promise.resolve()});
|
||||
redNodesStartFlows = sinon.stub(redNodes,"startFlows",function() {});
|
||||
redNodesLoadContextsPlugin = sinon.stub(redNodes,"loadContextsPlugin",function() {return Promise.resolve()});
|
||||
i18nRegisterMessageCatalog = sinon.stub(util.i18n,"registerMessageCatalog",function() {return Promise.resolve()});
|
||||
});
|
||||
afterEach(function() {
|
||||
storageInit.restore();
|
||||
@@ -114,6 +119,7 @@ describe("runtime", function() {
|
||||
redNodesLoadFlows.restore();
|
||||
redNodesStartFlows.restore();
|
||||
redNodesLoadContextsPlugin.restore();
|
||||
i18nRegisterMessageCatalog.restore();
|
||||
});
|
||||
it("reports errored/missing modules",function(done) {
|
||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function(cb) {
|
||||
@@ -199,10 +205,14 @@ describe("runtime", function() {
|
||||
var stopFlows = sinon.stub(redNodes,"stopFlows",function() { return Promise.resolve();} );
|
||||
redNodesGetNodeList = sinon.stub(redNodes,"getNodeList", function() {return []});
|
||||
var util = mockUtil(true);
|
||||
runtime.init({testSettings: true, runtimeMetricInterval:200, httpAdminRoot:"/", load:function() { return Promise.resolve();}},util);
|
||||
sinon.stub(console,"log");
|
||||
runtime.init(
|
||||
{testSettings: true, runtimeMetricInterval:200, httpAdminRoot:"/", load:function() { return Promise.resolve();}},
|
||||
{},
|
||||
undefined,
|
||||
util);
|
||||
// sinon.stub(console,"log");
|
||||
runtime.start().then(function() {
|
||||
console.log.restore();
|
||||
// console.log.restore();
|
||||
setTimeout(function() {
|
||||
try {
|
||||
util.log.log.args.should.have.lengthOf(3);
|
||||
|
@@ -31,31 +31,31 @@ var api = NR_TEST_UTILS.require("@node-red/runtime/lib/api");
|
||||
|
||||
describe("red/red", function() {
|
||||
|
||||
describe("check build", function() {
|
||||
beforeEach(function() {
|
||||
sinon.stub(runtime,"init",function() {});
|
||||
sinon.stub(api,"init",function() {});
|
||||
sinon.stub(RED,"version",function() { return "version";});
|
||||
});
|
||||
afterEach(function() {
|
||||
runtime.init.restore();
|
||||
api.init.restore();
|
||||
fs.statSync.restore();
|
||||
RED.version.restore();
|
||||
});
|
||||
it.skip('warns if build has not been run',function() {
|
||||
sinon.stub(fs,"statSync",function() { throw new Error();});
|
||||
|
||||
/*jshint immed: false */
|
||||
(function() {
|
||||
RED.init({},{});
|
||||
}).should.throw("Node-RED not built");
|
||||
});
|
||||
it('passed if build has been run',function() {
|
||||
sinon.stub(fs,"statSync",function() { });
|
||||
RED.init({},{});
|
||||
});
|
||||
});
|
||||
// describe("check build", function() {
|
||||
// beforeEach(function() {
|
||||
// sinon.stub(runtime,"init",function() {});
|
||||
// sinon.stub(api,"init",function() {});
|
||||
// // sinon.stub(RED,"version",function() { return "version";});
|
||||
// });
|
||||
// afterEach(function() {
|
||||
// runtime.init.restore();
|
||||
// api.init.restore();
|
||||
// fs.statSync.restore();
|
||||
// // RED.version.restore();
|
||||
// });
|
||||
// it.skip('warns if build has not been run',function() {
|
||||
// sinon.stub(fs,"statSync",function() { throw new Error();});
|
||||
//
|
||||
// /*jshint immed: false */
|
||||
// (function() {
|
||||
// RED.init({},{});
|
||||
// }).should.throw("Node-RED not built");
|
||||
// });
|
||||
// it('passed if build has been run',function() {
|
||||
// sinon.stub(fs,"statSync",function() { });
|
||||
// RED.init({},{});
|
||||
// });
|
||||
// });
|
||||
|
||||
describe("externals", function() {
|
||||
it('reports version', function() {
|
||||
|
Reference in New Issue
Block a user