vitest
vitest copied to clipboard
stack trace incorrect when react component throws with istanbul coverage
Describe the bug
When a test imports a react component which throw an error, the stack trace will be incorrect with istanbul coverage. Traces are wrong (but different) in both browser and jsdom modes. The trace is correct without --coverage.
Error: oops
Failure screenshot:
- test/__screenshots__/...
❯ Bar components/Bar.tsx:2:9
1| function Foo() {
2| return <>hi</>;
| ^
3| }
4| export default function Bar() {
When the file looks like
function Foo() {
return <>hi</>;
}
export default function Bar() {
throw new Error("oops");
return <Foo />;
}
Reproduction
https://github.com/kwojcik/vitestsourcemapbug/pull/new/reactErrorStackTrace
git checkout reactErrorStackTrace
npm install
npm run test
System Info
System:
OS: macOS 13.6.7
CPU: (12) arm64 Apple M2 Max
Memory: 20.87 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.18.2 - ~/.asdf/installs/nodejs/18.18.2/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/18.18.2/bin/yarn
npm: 9.8.1 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 9.5.0 - ~/.asdf/installs/nodejs/18.18.2/bin/pnpm
Watchman: 2024.04.01.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 126.0.6478.127
Firefox Nightly: 127.0
Safari: 16.6
npmPackages:
@vitest/browser: 2.0.2 => 2.0.2
@vitest/coverage-istanbul: ^2.0.2 => 2.0.2
@vitest/ui: 2.0.2 => 2.0.2
vite: latest => 5.3.3
vitest: 2.0.2 => 2.0.2
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue 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 or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Also getting this problem in node, since at least version 1.2.2, if that helps with debugging.
Has this ever worked correctly? I just tested 2.0.2, 1.2.2, 1.0.0 and 0.33.0. The error is shown incorrectly on all those versions.