-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getting 'test exited without ending' when using subtests with async calls #42
Comments
Have you tried simplifying your test: var test = require('tape').test;
var asyncFunction = function (callback) {
setTimeout(callback, Math.random * 50);
};
test('master test', function (t) {
t.pass('inner test 1 before async call');
asyncFunction(function () {
t.pass('inner test 1 in async callback');
});
t.pass('inner test 2 before async call');
asyncFunction(function () {
t.pass('inner test 2 in async callback');
t.end();
});
}); This will run all tests and call end when the second async function callback is called. The only problem I can foresee with this solution is in the scenario where the second call to asyncFunction comes back slower than the first since the second contains calls end on the test. You could nest your second test to make sure sure it is run in order: var test = require('tape').test;
var asyncFunction = function (callback) {
setTimeout(callback, Math.random * 50);
};
test('master test', function (t) {
t.pass('inner test 1 before async call');
asyncFunction(function () {
t.pass('inner test 1 in async callback');
t.pass('inner test 2 before async call');
asyncFunction(function () {
t.pass('inner test 2 in async callback');
t.end();
});
});
}); Yet another way to write it if you insist on "sub-tests": var test = require('tape').test;
var asyncFunction = function (callback) {
setTimeout(callback, Math.random * 50);
};
test('master test', function (t) {
test('inner test 1', function (tt) {
tt.pass('inner test 1 before async call');
asyncFunction(function () {
tt.pass('inner test 1 in async callback');
tt.end();
})
});
test('inner test 2', function (ttt) {
ttt.pass('inner test 2 before async call');
asyncFunction(function () {
ttt.pass('inner test 2 in async callback');
ttt.end();
})
});
t.end(); // test fails with or without this, is t.end in master test necessary?
}); |
It passes on this branch with no changes, w00t
@cappslock please give my PR branch over on #51 a try, I added your test over there and it passed just fine. |
I'm away from the computer this week but I'll check it out Monday. Thank
|
It passes on this branch with no changes, w00t
This was added to the test suite and fixed a while back. Closing. |
Found this when writing a test. When using subtests with async calls, test output looks incorrect and test fails with 'test exited without ending'. Here's a simple example:
And the output:
Note that the first test is actually run twice. This isn't an issue when removing the async call:
produces:
I can open a pull request for these tests, if you like.
The text was updated successfully, but these errors were encountered: