Skip to content
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

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

Closed
wokalski opened this issue Aug 30, 2022 · 6 comments

Comments

@wokalski
Copy link

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".

@lorenzofox3
Copy link
Owner

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 ?

@wokalski
Copy link
Author

wokalski commented Sep 2, 2022

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

@lorenzofox3
Copy link
Owner

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

@lorenzofox3
Copy link
Owner

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

@wokalski
Copy link
Author

wokalski commented Sep 3, 2022

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.

@lorenzofox3
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants