Incorrect line numbers in Jest output if sourceMaps are not enabled
See original GitHub issueExample
I put throw new Error('TEST ERROR') in one of my test files.
Source maps not enabled in .swcrc
Jest output shows the failure occurring at the wrong line:
FAIL src/__tests__/Skeleton.test.tsx
● disables the animation if and only if enableAnimation is false
TEST ERROR
68 | expect(skeleton).toHaveClass('react-loading-skeleton')
69 | expect(skeleton).toHaveClass('test-class')
> 70 | })
| ^
71 |
72 | it('applies the containerClassName and containerTestId', () => {
73 | render(<Skeleton containerClassName="test-class" containerTestId="myTestId" />)
at Object.<anonymous> (src/__tests__/Skeleton.test.tsx:70:11)
Source maps enabled in .swcrc
Jest output shows the failure occurring at the correct line:
FAIL src/__tests__/Skeleton.test.tsx
● disables the animation if and only if enableAnimation is false
TEST ERROR
58 | expect(skeleton.style.animation).toBe('none')
59 |
> 60 | throw new Error('TEST ERROR')
| ^
61 | })
62 |
63 | it('uses a custom className', () => {
at Object.<anonymous> (src/__tests__/Skeleton.test.tsx:60:11)
Possible Solutions
- If this behavior is unintended, fix the bug. (I can provide a minimal reproducible example.)
- Update https://swc.rs/docs/usage-swc-jest to recommend enabling source maps in
.swcrc. - (?) Automatically enable source maps in the
@swc/jestcode.
Additional Context
This occurred in a React .tsx file.
.swcrc:
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"dynamicImport": true
},
"target": "es2021"
},
"module": {
"type": "commonjs"
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:6
Top Results From Across the Web
Jest test of Typescript shows wrong error lines - Stack Overflow
I have sourceMap: true, and changed to sourceMaps:true, still with no change. I added the "sourceMaps":true to the "compilerOptions" section. I ...
Read more >Debug Node.js Apps using Visual Studio Code
The JavaScript debugger of VS Code supports source maps that help debugging of transpiled languages, for example, TypeScript or minified/uglified JavaScript.
Read more >Why does the stack trace for my jest tests point to the wrong ...
It has to do with source maps. If those are not correctly generated or processed, the debugger will show the wrong line. I...
Read more >Jest + Babel: Debugger stops on a wrong line : WEB-27680
This seems to be a systematic problem no matter what the source code is. ... Is Webstorm using the transpiled line numbers instead...
Read more >Configuring Jest
When using the --config option, the JSON file must not contain a "jest" key: ... number it represents the maximum number of uncovered...
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
Any status on this?
I’m facing this issue even with sourceMaps:true, even after clearing the cache! Tests run but line numbers a good bit off. I don’t want to spam a closed issue, but I’m not sure what else to try. Let me know if any suggestions!
Here’s an exerpt of my .swcrc: