You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
timeoutAfter() makes sure that the tests failes after a certain amount of time, unless end() has been called.
However, due to the nature of asynchronous JavaScript, the test still continues to run and may still call end() later. This case is not handled and, even worse, makes successive tests fail due to the unexpected end() call.
Example:
vartest=require("tape");test("takes too long",function(t){// remove/comment-out the following line, and all tests will pass:t.timeoutAfter(2000);setTimeout(function(){// we're done... but let's say for some reason later than expected...t.end();},5000);});test("independent test",function(t){t.end();});
Output:
TAP version 13
# takes too long
not ok 1 test timed out after 2000ms
---
operator: fail
...
# independent test
not ok 2 .end() called twice
---
operator: fail
at: Timeout._onTimeout (/src-protected/tonidb/packages/tonidb/test/collections.test.js:11:7)
...
1..2
# tests 2
# pass 0
...or am I using timeoutAfter() incorrectly?
In any case, it surprises me that one test can make another fail. Consider another example:
test("something goes wrong", function(t) {
t.plan(2);
[1, 2, 3].forEach(function(value) {
// let's cause one end() too much..
setTimeout(function() {
t.equals(1, 1);
}, value * 1000);
});
});
test("dummy test 1", function(t) { t.end(); });
test("dummy test 2", function(t) { t.end(); });
test("dummy test 3", function(t) { t.end(); });
test("last test...", function(t) { t.end(); });
...this shows the last test as failed, even if the problem is in the first test. Since the t is scoped, I'm sure that tape could detect that the superfluous end() was from the first test.
The text was updated successfully, but these errors were encountered:
timeoutAfter()
makes sure that the tests failes after a certain amount of time, unlessend()
has been called.However, due to the nature of asynchronous JavaScript, the test still continues to run and may still call
end()
later. This case is not handled and, even worse, makes successive tests fail due to the unexpectedend()
call.Example:
Output:
...or am I using
timeoutAfter()
incorrectly?In any case, it surprises me that one test can make another fail. Consider another example:
...this shows the last test as failed, even if the problem is in the first test. Since the
t
is scoped, I'm sure thattape
could detect that the superfluousend()
was from the first test.The text was updated successfully, but these errors were encountered: