-
-
Notifications
You must be signed in to change notification settings - Fork 307
Closed
Description
Would be great to support returning a promise to end the test when the promise is resolved.
- It would play nice with future extensions of the language, allowing one to call
tape
with Async Functions to transparently return a promise. - It would eliminate some otherwise unfixable ordering issues with nested tests.
- Rewriting
var test = require('tape');
test('first', function (t) {
setTimeout(function () {
t.ok(1, 'first test');
t.end();
}, 200);
t.test('second', function (t) {
t.ok(1, 'second test');
t.end();
});
});
test('third', function (t) {
setTimeout(function () {
t.ok(1, 'third test');
t.end();
}, 100);
});
to (assuming a function delay
returning a Promise
resolved after t
milliseconds)
var test = require('tape');
test('first', async function (t) {
await delay(200);
t.ok(1, 'first test');
t.test('second', async function (t) {
t.ok(1, 'second test');
});
});
test('third', async function (t) {
await delay(100);
t.ok(1, 'third test');
});
will preserve the expected order (see #222).
Looking at blue-tape it should be doable with something along the lines of
var ret = this._cb(this);
var self = this;
if (ret && typeof ret.then === 'function') {
ret.then(function () {
self.end();
}, function (err) {
nextTick(function () {
throw err;
});
});
}
Note that it would not require a Promise
library nor any configuration. Users wanting to take advantage of this feature would need to provide their own Promise
implementation if necessary anyway.
Metadata
Metadata
Assignees
Labels
No labels