tape-testing / tape

tap-producing test harness for node and browsers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async: supported or not? Change docs?

Download opened this issue · comments

I am confused whether async is supported in Tape.

In the example in the README I see this:

test('test using promises', async function (t) {
    const result = await someAsyncThing();
    t.ok(result);
});

This to me strongly suggests Tape supports async.
Though I see no t.plan() or t.end(), which confuses me...
And indeed my test does not end... Even not after adding a call to t.end()...

So I perused the issue list where I found this issue:

Test using async/await does not end #358

In there, I see this comment by the author:

You can't really pass an async function to tape because tape does not do anything with the promise it returns.

I guess the author knows what he is talking about. But this leaves me wondering. Why explicitly give an example of an async test when it is not really supported? Should we maybe remove that example from the docs?

That comment described tape v4 - v5 supports a returned promise from the function, which means it supports async function. What version are you using?

There's no need for t.end() because the promise itself fulfilling notifies tape when the test is over.

Ah! That clarifies a lot!

In the mean time I have been doing some testing and it seems that you are right that it is supported as another async function that only calls setTimeout does finish as expected. So the issue seems to be in my code... as usual.

UPDATE

Did some more testing and figured it out. It has nothing to do with tape. The issue was that knex keeps the process alive unless I explictly call destroy on it or use process.exit. Thanks for your reply!