Tests pass but vitest fails non-deterministically and sometimes causes Unhandled Rejection
See original GitHub issueDescribe the bug
While test cases results themselves are deterministic but the runs are not. Some of the runs produce unhandled rejection. This seems to be similar to https://github.com/vitest-dev/vitest/issues/1191 but not same. My test specs are fairly minimal at this time, like just checking for component rendering and not much.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 2 unhandled errors during the test run. This might cause false positive tests.
Please, resolve all the errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error:
❯ post node_modules/vitest/dist/worker.mjs:70:14
❯ node_modules/vitest/dist/chunk-vite-node-utils.8077cd3c.mjs:1376:11
❯ sendCall node_modules/vitest/dist/chunk-vite-node-utils.8077cd3c.mjs:1373:16
❯ node_modules/vitest/dist/chunk-runtime-rpc.9d1f4c48.mjs:7:55
5| return new Proxy(rpc2, {
6| get(target, p, handler) {
7| const sendCall = Reflect.get(target, p, handler);
| ^
8| const safeSendCall = (...args) => withSafeTimers(() => sendCall(...args));
9| safeSendCall.asEvent = sendCall.asEvent;
❯ withSafeTimers node_modules/vitest/dist/chunk-utils-global.0a7416cf.mjs:472:20
❯ Proxy.safeSendCall node_modules/vitest/dist/chunk-runtime-rpc.9d1f4c48.mjs:7:41
❯ process.<anonymous> node_modules/vitest/dist/worker.mjs:34:11
❯ process.emit node:events:527:28
❯ emit node:internal/process/promises:140:20
Reproduction
You should be able to reproduce it using this repo.
https://github.com/zinclabs/zinc/tree/38303f59af5f329c62068a320eecd4f53c17b107
steps.
git clone https://github.com/zinclabs/zinc
cd zinc
git checkout 38303f59af5f329c62068a320eecd4f53c17b107
cd web
npm i
npm run test-once
run the test a couple of times. You will notice that sometimes tests are successful however sometimes there is unhandled rejection.
System Info
System:
OS: macOS 12.4
CPU: (8) arm64 Apple M2
Memory: 372.69 MB / 24.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - /usr/local/bin/node
npm: 8.11.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 103.1.41.96
Chrome: 103.0.5060.134
Safari: 15.5
npmPackages:
@vitejs/plugin-vue: ^2.3.3 => 2.3.3
vite: ^2.9.14 => 2.9.14
vitest: ^0.18.1 => 0.18.1
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Vitest is catching an error when I use ... - JTuto
I'm making tests on an application that has several pages. ... Vitest caught 1 unhandled error during the test run. This might cause...
Read more >Jest: Creating promise rejections in beforeEach causes errors ...
This is a particular problem when running npm run test in a CRA, since the unhandled rejection causes the watching jest command to...
Read more >Testing-library: avoid these mistakes in async tests
Sometimes, tests start to unexpectedly fail even if no changes were made to the business logic. It may happen after e.g. you updated...
Read more >How to write tests in Sveltekit and Vitest - Eternal Dev
SvelteKit is very promising but not recommended for production use ... These form the basis of our test since the test passing/ failing...
Read more >Testing promise rejection in JavaScript with Jest - Codeleak.pl
Error : expect(received).resolves.toEqual() Received promise rejected instead of resolved Rejected to value: [...] But what if one want to test ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@calvinf thank you for pointing it out, Vitest didn’t serialise errors thrown in
unhandledRejection
, so some errors might’ve slipped asUnknown Error: undefined
. #2253 should fix it.Yes, mentioned in this PR error is fixed.
You probably have an asynchronous process that’s executed after all tests have passed. Vitest cannot track it, it’s unhandled.