-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reject a promise after a test will make test end earlier in browser mode. #7079
Comments
Does it show that only one test failed? Or does it run only one test? I think it's expected behaviour that Vitest doesn't start new tests when the environment is potentially broken which is why this safeguard mechanism exists. If we didn't have this check, Vitest could hang. |
It will run only one test, and the result of that test will be different with the actual test case. In sample above, it'll be passed. I'm also agreed that safeguard mechanism is necessary to keep Vitest running as expected. But this handled rejection is caused by test case, not Vitest itself. It'll be better to start the following tests, and end up with unhandled error failed or exit with 0 when dangerouslyIgnoreUnhandledErrors is on. As the discussion in discord, I'm shifting a historical project with lots of badly designed cases which all throw unhandled rejections. For rapid development, I would like to ignore them first and solve them gradually. Because I quite sure they will not cause any false positive tests as they are in another testing frameworks. So in my opinion, it'll be better to run all tests first and alert for the unhandled errors. Safeguard can be implemented in other strategy like watchdog timer. And this cases making Vitest hanging may be also reported as a potential bug of Vitest. |
It doesn't matter what called what in your reproduction. The error happened outside of the test body. If the error was handled inside the test, then Vitest won't fail. This code works correctly, for example: test('test unhandled rejection', async () => {
const promise = new Promise((resolve) => {
window.addEventListener('unhandledrejection', () => resolve())
})
new Promise((_, reject) => reject('test'))
await promise
}) Changing this behaviour is definitely not a priority.
You can use Vitest's
As I already explained, we cannot do that because we will have to remove the safeguard. From the framework perspective, the current safeguard is much better than allowing some weird unhandled rejections to be ignored because the tests are written incorrectly. |
I think I understand your opinion now. Keeping the safeguard unchanged seems to be ok to me. As a developer using Vitest, the test result is confusing. It seems that Vitest only collect one test case and ignore the others. I cost lots of time to double check the It would be better to adding more notes in this case. For example, "Vitest exited unexpectedly, checking unhandled errors or file an issue". Or just add the total count of collected cases in the result. |
Describe the bug
If a test case will make an unhandled rejection just after one test and before the next test, the cases in the other files will not be tested.
After debugging, there will post a "done" message included all test files. And It will break the next test process.
vitest/packages/browser/src/client/public/error-catcher.js
Line 69 in 4e60333
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-ceqdspje
This issue can also be reproduced by following steps.
mkdir
to create a new folder, and npm init.npx vitest init browser
to init the test with browser mode.package.json
to runvitest run
.npm test:browser
.The result will show that only one file is tested.
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: