question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests pass but vitest fails non-deterministically and sometimes causes Unhandled Rejection

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sheremet-vacommented, Nov 1, 2022

@calvinf thank you for pointing it out, Vitest didn’t serialise errors thrown in unhandledRejection, so some errors might’ve slipped as Unknown Error: undefined. #2253 should fix it.

1reaction
sheremet-vacommented, Nov 8, 2022

@sheremet-va could you confirm if the issue was fixed? Facing the same problem right now and I’m using version 0.24.5.

I am randomly getting unhandled rejection errors.

Like 30% of the time the tests pass but get this unhanded rejection that doesn’t show exactly which test caused it.

Screen Shot 2022-11-08 at 12 34 40 PM

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found