-
Notifications
You must be signed in to change notification settings - Fork 467
Description
## 🐛 Bug Report
When testing files that use (https://github.com/evanw/node-source-map-support) with:
import 'source-map-support/register';
The line numbers in stack traces displayed via tests run with ts-jest
are wrong. In particular they point to the source line in the compiled .js
files not the .ts
files despite referencing the .ts
files.
I want to use source-map-support
in my production files to have nice stack traces.
To Reproduce
Test a file with ts-jest
that has import 'source-map-support/register';
and throw an error to get a stack trace. See the line numbers are misaligned. Remove the import and see the line numbers are correct.
Expected behavior
Line numbers should be correct from ts-jest
regardless of whether source-map-support
is imported.
Link to repo
Minimal repro here:
https://github.com/silasdavis/ts-jest-repro
Just run yarn test
(see the README.md for more details).
Annotated output:
/usr/bin/node /usr/lib/node_modules/yarn/bin/yarn.js test
yarn run v1.22.10
$ tsc --build && jest
FAIL src/source-map.test.ts
● tests › foo
bah
8 | return {a: 1}
9 | }
> 10 |
| ^
11 | export function blah() {
12 | throw new Error('bah')
13 | }
!!! line below is incorrect (should be line 12) !!!
at Object.blah (src/source-map.ts:10:11)
at src/source-map.test.ts:8:26
at Object.<anonymous> (src/source-map.test.ts:6:46)
FAIL src/no-source-map.test.ts
● tests › foo
bah
12 |
13 | export function blah() {
> 14 | throw new Error('bah')
| ^
15 | }
16 |
!!! line below is correct !!!
at Object.blah (src/no-source-map.ts:14:9)
at src/no-source-map.test.ts:5:5
at Object.<anonymous> (src/no-source-map.test.ts:4:15)
Test Suites: 2 failed, 2 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: 0.877 s, estimated 2 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Process finished with exit code 1
Debug log:
Find ts-jest
log here: https://github.com/silasdavis/ts-jest-repro/blob/main/ts-jest.log
envinfo
System:
OS: Linux cora 5.10.12-arch1-1 #1 SMP PREEMPT Sun, 31 Jan 2021 00:41:06 +0000 x86_64 GNU/Linux
Node version: v14.15.5
Npm packages:
jest: 26.6.3
ts-jest: 26.5.1
typescript: 4.1.5
babel(optional): N/A