Closed barrierye closed 4 years ago
This library doesn't concern itself with timeouts. That will depend on what test runner you are using, such as mocha.
thank you for your reply! I tried to change the timeout time to 5s, but it still timed out. I don’t know why, can you help me? Below is my simplified test code:
var should = require('should');
var helper = require("node-red-node-test-helper");
var chartNode = require("../src/chart-render.js");
helper.init(require.resolve('node-red'));
describe('chart-render Node', function () {
this.timeout(5000);
beforeEach(function (done) {
helper.startServer(done);
});
afterEach(function (done) {
helper.unload();
helper.stopServer(done);
});
it('should be loaded', function (done) {
var flow = [{ id: "n1", type: "chart-render", name: "test name" }];
helper.load(chartNode, flow, function () {
var n1 = helper.getNode("n1");
n1.should.have.property('name', 'test name');
done();
});
});
it('should make line chart', function (done) {
var flow = [{
id: "chartNode",
type: "chart-render",
name: "test name",
}, {
id: "helperNode",
type: "helper"
}
];
helper.load(chartNode, flow, function () {
var n1 = helper.getNode("chartNode");
var n2 = helper.getNode("helperNode");
n2.on("input", function (msg) {
try {
console.log("no output here"); // no output here
done();
} catch (err) {
done(err);
}
});
});
});
});
The result of running nyc mocha
:
> nyc mocha
chart-render Node
✓ should be loaded (103ms)
1) should make line chart
1 passing (5s)
1 failing
1) chart-render Node
should make line chart:
Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/path/to/chart-render_spec.js)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
I don't know why the code in the try-block are not executed.
Sorry, I found that I had reversed the input node and the output node.
My node may run slow and always time out when doing unit tests. I want to know how to modify the timeout time.