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

feat: add option for ignoring unhandled errors #1678

Merged

Conversation

DerYeger
Copy link
Member

@DerYeger DerYeger commented Jul 19, 2022

I recently migrated a large project from Jest to Vitest.
During the migration, I encountered issues with unhandled errors due to race conditions (caused by poor tests that don't clean up their async React hooks).

Since there's a huge number of tests, without any way of knowing which tests cause these issues, I had to use patch-package to prevent Vitest from failing due to unhandled errors.

I am aware that this isn't the proper way, but there was no other way of getting around this issue.

With this PR, I propose a new config option for ignoring unhandled errors.
It's fittingly labelled dangerouslyIgnoreUnhandledErrors.

@DerYeger DerYeger added the enhancement New feature or request label Jul 19, 2022
Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would much prefer if we could provide a better way of displaying errors to help users find the issues, instead of ignoring it.

@DerYeger
Copy link
Member Author

I would much prefer if we could provide a better way of displaying errors to help users find the issues, instead of ignoring it.

While I agree, I'm not sure if much can be done about improving the reports of unhandled errors.
I'd be happy to work on a solution if someone has an idea.

With the proposed option enabled, Vitest's behaviour would match the behaviour of older Jest versions, making iterative migration much simpler.

@DerYeger DerYeger force-pushed the feat/dangerously-ignore-unhandled-errors branch from 40cc27b to 2964443 Compare July 19, 2022 14:53
@antfu
Copy link
Member

antfu commented Jul 19, 2022

Or maybe we could return a different exitCode so you could ignore it with a UNIX pipe or some ci config?

@DerYeger
Copy link
Member Author

Or maybe we could return a different exitCode so you could ignore it with a UNIX pipe or some ci config?

I guess that would work as well (if actually failing tests in presence of unhandled errors still result in exit code 1).

Though it would also have downsides compared to the config option (no central config, no platform independence, can't call package script differently like nr test --no-ui).

@antfu
Copy link
Member

antfu commented Jul 22, 2022

I am fine with adding the option, since we have the --dangerously prefix

@DerYeger DerYeger force-pushed the feat/dangerously-ignore-unhandled-errors branch from 2964443 to 9d5b35e Compare July 25, 2022 10:10
@sheremet-va sheremet-va merged commit 409aa45 into vitest-dev:main Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants