mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
fix many test problems (#1677)
* fix many test problems - adds [stoppable](https://npm.im/stoppable) to force-stop net & http servers - upgrades to latest mocha - much cleanup of servers - some removal of useless code Signed-off-by: Christopher Hiller <boneskull@boneskull.com> * increase wait time to hack at race condition * PoC with fork of stoppable Signed-off-by: Christopher Hiller <boneskull@boneskull.com> * fix custom stoppable url for newer npm * make travis go faster; attempt to avoid npm troubles * fix coveralls executable path * add extra time for flake to trigger spec Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
This commit is contained in:
committed by
Nick O'Leary
parent
25345302e8
commit
e1195ac00a
@@ -24,6 +24,10 @@ describe('sentiment Node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('inject node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -25,6 +25,10 @@ describe('debug node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
setTimeout(function() {
|
||||
done();
|
||||
|
@@ -24,6 +24,10 @@ describe('link Node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('function node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('template node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -304,11 +304,11 @@ describe('trigger node', function() {
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("payload", "bar");
|
||||
spy.restore();
|
||||
RED.util.evaluateNodeProperty.restore();
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(err) { spy.restore(); done(err); }
|
||||
catch(err) { RED.util.evaluateNodeProperty.restore(); done(err); }
|
||||
});
|
||||
n1.emit("input", {payload:null});
|
||||
});
|
||||
@@ -384,6 +384,7 @@ describe('trigger node', function() {
|
||||
});
|
||||
|
||||
it('should be able to extend the delay', function(done) {
|
||||
this.timeout(5000); // add extra time for flake
|
||||
var spy = sinon.stub(RED.util, 'evaluateNodeProperty',
|
||||
function(arg1, arg2, arg3, arg4) { return arg1; }
|
||||
);
|
||||
|
@@ -19,6 +19,7 @@ var http = require("http");
|
||||
var should = require("should");
|
||||
var express = require("express");
|
||||
var bodyParser = require('body-parser');
|
||||
var stoppable = require('stoppable');
|
||||
var helper = require("../../helper.js");
|
||||
var httpRequestNode = require("../../../../nodes/core/io/21-httprequest.js");
|
||||
var hashSum = require("hash-sum");
|
||||
@@ -30,13 +31,10 @@ describe('HTTP Request Node', function() {
|
||||
|
||||
function startServer(done) {
|
||||
testPort += 1;
|
||||
testServer = http.createServer(testApp);
|
||||
testServer.on('error', function(err) {
|
||||
startServer(done);
|
||||
});
|
||||
testServer = stoppable(http.createServer(testApp));
|
||||
testServer.listen(testPort,function(err) {
|
||||
done();
|
||||
})
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
function getTestURL(url) {
|
||||
@@ -57,13 +55,18 @@ describe('HTTP Request Node', function() {
|
||||
}
|
||||
res.json(result);
|
||||
});
|
||||
startServer(function() {
|
||||
startServer(function(err) {
|
||||
if (err) {
|
||||
done(err);
|
||||
}
|
||||
helper.startServer(done);
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
testServer.close();
|
||||
after(function(done) {
|
||||
testServer.stop(() => {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
|
@@ -61,6 +61,10 @@ describe('websocket Node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
closeAll();
|
||||
helper.unload();
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
var net = require("net");
|
||||
var should = require("should");
|
||||
var stoppable = require('stoppable');
|
||||
var helper = require("../../helper.js");
|
||||
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
|
||||
|
||||
@@ -26,20 +27,13 @@ describe('TCP in Node', function() {
|
||||
var server_port = 9300;
|
||||
var reply_data = undefined;
|
||||
|
||||
before(function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
after(function() {
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
startServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
stopServer();
|
||||
afterEach(function(done) {
|
||||
helper.unload();
|
||||
stopServer(done);
|
||||
});
|
||||
|
||||
function sendArray(sock, array) {
|
||||
@@ -55,15 +49,15 @@ describe('TCP in Node', function() {
|
||||
|
||||
function startServer(done) {
|
||||
server_port += 1;
|
||||
server = net.createServer(function(c) {
|
||||
server = stoppable(net.createServer(function(c) {
|
||||
sendArray(c, reply_data);
|
||||
}).listen(server_port, "localhost", function(err) {
|
||||
})).listen(server_port, "localhost", function(err) {
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
function stopServer() {
|
||||
server.close();
|
||||
function stopServer(done) {
|
||||
server.stop(done);
|
||||
}
|
||||
|
||||
function send(wdata) {
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
var net = require("net");
|
||||
var should = require("should");
|
||||
var stoppable = require('stoppable');
|
||||
var helper = require("../../helper.js");
|
||||
var tcpinNode = require("../../../../nodes/core/io/31-tcpin.js");
|
||||
|
||||
@@ -26,7 +27,7 @@ describe('TCP Request Node', function() {
|
||||
|
||||
function startServer(done) {
|
||||
port += 1;
|
||||
server = net.createServer(function(c) {
|
||||
server = stoppable(net.createServer(function(c) {
|
||||
c.on('data', function(data) {
|
||||
var rdata = "ACK:"+data.toString();
|
||||
c.write(rdata);
|
||||
@@ -34,7 +35,7 @@ describe('TCP Request Node', function() {
|
||||
c.on('error', function(err) {
|
||||
startServer(done);
|
||||
});
|
||||
}).listen(port, "127.0.0.1", function(err) {
|
||||
})).listen(port, "127.0.0.1", function(err) {
|
||||
done();
|
||||
});
|
||||
}
|
||||
@@ -43,8 +44,8 @@ describe('TCP Request Node', function() {
|
||||
startServer(done);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
server.close();
|
||||
after(function(done) {
|
||||
server.stop(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
@@ -27,7 +27,8 @@ describe('UDP in Node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
@@ -27,7 +27,8 @@ describe('UDP out Node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
@@ -38,7 +39,7 @@ describe('UDP out Node', function() {
|
||||
var sock = dgram.createSocket('udp4');
|
||||
sock.on('message', function(msg, rinfo) {
|
||||
msg.should.deepEqual(data);
|
||||
done();
|
||||
sock.close(done);
|
||||
});
|
||||
sock.bind(port, '127.0.0.1');
|
||||
port++;
|
||||
|
@@ -28,8 +28,8 @@ describe('switch Node', function() {
|
||||
|
||||
afterEach(function(done) {
|
||||
helper.unload();
|
||||
helper.stopServer(done);
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
it('should be loaded with some defaults', function(done) {
|
||||
|
@@ -578,7 +578,6 @@ describe('change Node', function() {
|
||||
});
|
||||
|
||||
it('reports invalid regex', function(done) {
|
||||
var sinon = require('sinon');
|
||||
var flow = [{"id":"changeNode1","type":"change","action":"change","property":"payload","from":"\\+**+","to":"NUMBER","reg":true,"name":"changeNode","wires":[["helperNode1"]]},
|
||||
{id:"helperNode1", type:"helper", wires:[]}];
|
||||
helper.load(changeNode, flow, function() {
|
||||
|
@@ -135,11 +135,13 @@ describe('range Node', function() {
|
||||
var sinon = require('sinon');
|
||||
sinon.stub(rangeNode1, 'log', function(log) {
|
||||
if (log.indexOf("notnumber") > -1) {
|
||||
rangeNode1.log.restore();
|
||||
done();
|
||||
} else {
|
||||
try {
|
||||
should.fail(null, null, "Non-number inputs should be reported!");
|
||||
} catch (err) {
|
||||
rangeNode1.log.restore();
|
||||
done(err);
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,10 @@ describe('SPLIT node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
@@ -268,6 +272,10 @@ describe('JOIN node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
|
@@ -25,6 +25,10 @@ describe('SORT node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
|
@@ -26,6 +26,10 @@ describe('BATCH node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
|
@@ -24,6 +24,10 @@ describe('CSV node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -15,7 +15,6 @@
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var sinon = require("sinon");
|
||||
var path = require("path");
|
||||
var fs = require('fs-extra');
|
||||
|
||||
@@ -31,6 +30,10 @@ describe('html node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
fs.existsSync(file).should.be.true();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('JSON node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('XML node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -24,6 +24,10 @@ describe('YAML node', function() {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
});
|
||||
|
@@ -130,15 +130,20 @@ describe('tail Node', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('should throw an error if run on Windows', function(done) {
|
||||
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 */
|
||||
(function() { tailNode("1234"); }).should.throw();
|
||||
os.platform.restore();
|
||||
done();
|
||||
try {
|
||||
(function() { tailNode("1234"); }).should.throw();
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
finally {
|
||||
os.platform.restore();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
@@ -28,7 +28,7 @@ describe('file Nodes', function() {
|
||||
|
||||
var resourcesDir = path.join(__dirname,"..","..","..","resources");
|
||||
var fileToTest = path.join(resourcesDir,"50-file-test-file.txt");
|
||||
var wait = 150;
|
||||
var wait = 250;
|
||||
|
||||
beforeEach(function(done) {
|
||||
//fs.writeFileSync(fileToTest, "File message line 1\File message line 2\n");
|
||||
|
Reference in New Issue
Block a user