broken stacktraces + reproduce repo
Describe the bug
There are alot of wrong stack traces in my tests. In this reporduction, I see 2 stacktraces for an error: invalid + valid one.
In my real repo, I only see one invalid stacktrace.
Reproduction information:
Broken stacktraces:

Wrong stacktraces: (the upper stacktrces are wrong, the lower are correct)

Here is a huge hint:
When replacing the order of these two lines, the stacktraces are correct:


vitest:
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
import path from 'path'
// @ts-ignore
export default defineConfig({
// @ts-ignore
plugins: [tsconfigPaths({ root: __dirname })],
test: {
environment: 'node',
watch: false,
testTimeout: 60_000,
env: {
IS_TEST_MODE: 'true',
},
allowOnly: true,
setupFiles: [path.join(__dirname, 'vitest.before-all.ts')],
},
})
Reproduction
Here is a minimal repo (as far as I could. any additional change can/will possibily make different results):
https://github.com/stavalfi/vitest-wrong-stacktraces-reproduce
run: yarn test
test is located at: packages/il-backend/__tests__/sanity.spec.ts
System Info
System:
OS: macOS 12.2.1
CPU: (10) arm64 Apple M1 Max
Memory: 7.89 GB / 32.00 GB
Shell: 3.3.1 - /opt/homebrew/bin/fish
Binaries:
Node: 16.13.2 - /var/folders/sn/b0rx6xbx6snfcp1r0grqp6km0000gn/T/fnm_multishells/11306_1652852702882/bin/node
Yarn: 1.18.0 - /var/folders/sn/b0rx6xbx6snfcp1r0grqp6km0000gn/T/fnm_multishells/11306_1652852702882/bin/yarn
npm: 8.1.2 - /var/folders/sn/b0rx6xbx6snfcp1r0grqp6km0000gn/T/fnm_multishells/11306_1652852702882/bin/npm
Browsers:
Chrome: 101.0.4951.64
Safari: 15.3
npmPackages:
@vitejs/plugin-react-refresh: ^1.3.1 => 1.3.6
vite: ^2.9.5 => 2.9.5
vitest: ^0.12.6 => 0.12.6
### Used Package Manager
yarn
### Validations
- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
I cannot run yarn install in your reproduction:
error Couldn't find package "@coti-cvi/contracts-core@^1.0.0" required by "@coti-cvi/[email protected]" on the "npm" registry.
@sheremet-va fixed. try now.
this dependency was not in use anyway. I removed it.
So, this is more of a feature than a bug. You see correct stack trace in red color because we are processing it before outputting, but we don't process errors logged by hand. I see that jest outputs correct stack trace in both situations, so I think we can try and find a solution, but until then we have a current workaround.
@sheremet-va Thanks.
This is a bug because in other tests which it's harder to reproduce, vitest prints a single wrong stacktraces without a correct stcktraces.
I worked really hard to give you this reproduction and this is a huge clue for the more critical bug.
Single wrong stacktrace is printed by you console.logging.
Th reproduction is too verbose. All I can see is if it fails before the event loop finishes, then Vitest shows our error. If not, then Vitest can’t catch error. The issue is with your setup.