lorenzofox3 / zora

Lightest, yet Fastest Javascript test runner for nodejs and browsers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zora pta doesn't report anything if there are any pending tests that don't wait for any events

wokalski opened this issue · comments

I don't have a minimal zora repro but it's obvious from this:

// x.mjs
Promise.all([Promise.resolve(), new Promise(() => {})]).then(() => console.log("hello"))

run node x.mjs and you won't see hello but the program will terminate successfully. In the case of zora, you will see the program terminate but it won't report anything. Ideally (a 10 star experience) the test runner would execute normally and report and then it would tell me "hey, this and this test is still pending but it's not waiting for anything. It's most likely a bug".

For late assertion collection, you should have an error

import {test} from 'zora';

test('woot', ({ok}) => {
    // setTimeout is not awaited
    setTimeout(() => {
        ok(false)
    });

    ok(true);
})

Screenshot 2022-09-02 at 18 18 27

Hence, I am not sure what you are referring to. Would you mind providing a short repro ?

Its the opposire of late assertion. Create a test that returns new Promise(() => {}).then(() => t.equal(0, 1))

Oh I see. Thanks. I'am getting a look at it

Apparently, finding a broken promise is quite a thing

The only easy way I can think of (which would be cross platform) is to make the user spec function compete with a timeout function and throw if the timeout wins.

something like this PR

Here's what I'd do:

  1. When you register tests add them to a map
  2. When they conclude, remove them from the map
  3. On 'exit' hook, print the ones that are not concluded
  4. Profit
    You don't actually need to know what the state of the promise is, you can solve it reliably on the framework level.

Actually that's not that simple. There is only an exit hook in a nodejs environment (and Deno) but not in the browser. You can't either add this check after the reporting stream as it is simply broken (the code after won't run).

I think I'll rather go for test timeout which adds anyway a nice to have assertion