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

[web-test-runner] Allow web test runner to fail a test / suite when there are uncaught promise rejections #1730

Open
skortchmark9 opened this issue Oct 19, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@skortchmark9
Copy link

We noticed that our test suite was passing, but unit tests were printing an error like this one:

build	18-Oct-2021 17:26:54	      An error was thrown in a Promise outside a test. Did you forget to await a function or assertion?
build	18-Oct-2021 17:26:54	      TypeError: Cannot read property 'getBoundingClientRect' of undefined

Upon further investigation, this revealed a real bug. We would like to consider these failures. Is there a good way to fail the tests based on uncaught promise resolutions at the test runner level?

I thought of a couple solutions:

  • pipe logs into grep
  • add an unhandled promise rejection listener to before before all test suites

But, I know there's already some mechanism for filtering logs and it seems like it might be possible to hook into it in a neat way.

I'm using mocha, if it makes a difference.

It seems like @LarsDenBakker wrote most of the logging stuff, so I'm curious to hear his opinion.

@web-padawan web-padawan added the bug Something isn't working label Nov 9, 2021
@web-padawan
Copy link
Contributor

Hi, thanks for the issue. Lars was on vacation the last time I checked with him. But this does seem like a bug.
Feel free to submit a PR if you would like to contribute, I can help with reviewing and merging it.

@LarsDenBakker
Copy link
Member

This is an issue with mocha, not with WTR. Mocha runs the actual tests in the browser.

@skortchmark9
Copy link
Author

This issue seems to indicate that unhandled rejections were included in mocha's exit code at one point, but not as of 8.2.1: mochajs/mocha#2640

Here is where WTR is doing the helpful logging:

'An error was thrown in a Promise outside a test. Did you forget to await a function or assertion?',

I will look into adding a userland patch until mocha is fixed. Will post it on here if I come up with something good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants