I have a section of code that is using node-sync like so:
function funcA() {
return new Promise(function(resolve, reject) {
Sync(function () {
return funcB.sync();
}, function (err, result) {
if(err) {
reject(err);
} else {
resolve(result);
}
});
}
This code is tested using mocha+chai:
it("should return array", function() {
return funcA().then(function(result) {
expect(result).to.be.an.instanceof(Array);
});
});
It worked just fine couple of months ago, but now this test always times out:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
What I've tried so far:
- using
done()instead of returning a promise - replacing
node-syncwithsynchronize.js - increasing timeout
What I found out, is that expect(... part of this test is, in fact, being called, but only after mocha kills the test. No matter what timeout interval is currently set, expect(.. is being called always ~20 milliseconds after I get Error: timeout message.
I fixed the issue by adding setInterval(function(){}, 10) on the top of the test file. I'd like to know why this worked and if there is some better way to fix that?
[EDIT] It looks like this is a node-version specific issue. Test fails on 0.12.4 but runs correctly on 0.10.38 .
[EDIT] Actual code is available here.
done