-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source maps are mis-aligned #10330
Comments
Repo with minimal code to reproduce: https://github.com/Marik-D/jest-source-map-issue require('source-map-support').install() //commenting out this line makes the issue dissapear
test('test', () => {
expect(false).toEqual(true)
}) Looks like just using jest with Also, console logs and node's assert are unaffected by this issue. |
So I dug into the code and where Istanbul is working it should not be. Also I doubt It will be fixed any time soon coverage is built into V8 directly for example implementation see |
I have noticed an issue with the same symptoms that may or may not be related when using A detailed ticket and minimal repro is here: kulshekhar/ts-jest#2372 Let me know if I should move that ticket to this or another issue against jest. |
It looks like this is a Jest issue (?). Let me inline my reproduction with ## 🐛 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 I want to use To ReproduceTest a file with Expected behaviorLine numbers should be correct from Link to repoMinimal repro here: https://github.com/silasdavis/ts-jest-repro Just run 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 envinfo
|
Okay, just for any fellow travellers it would appear than since 12.12.0 (nodejs/node#29564) source-map-support is not required since there is native node support. So unless you transitively depend on it you can safely remove it and still get nice stack traces. That seems to resolve issues with jest/ts-jest. |
Jest installs |
No library should ever set up I don't think this is a bug in Jest however, so I'll close it. |
The issue here is that production files (under test) set up source-map-support by importing it, which causes the breakage in Jest. You can set up source-map-support dynamically by passing an argument to node or by using a dynamic import/require (and so avoid this issue by not registering when running with Jest). For people importing the support in production code it does seem like a bug (somewhere at least) that this breaks line numbers in jest; we ought not to have to change our production code to appease our testing framework. That said given the workarounds and the fact source map support does not seem to be needed in node 12.12 and above this doesn't seem like a priority. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
Jest errors that show line numbers and code snippets aren't showing the right thing.
This seems to happen by merely including another package that already loads
source-map-support
module prior, for examplepino-caller
. You can see the code for pino-caller is very simple, and in fact no code paths get triggered, other than just the loading of the module itself.When I comment out the
require
line inpino-caller
, the source maps align fine.I've looked at other source maps issues here, and none of them seem to be relevant to this.
To Reproduce
Steps to reproduce the behavior:
Results in:
Expected behavior
To point to the right line of code.
Link to repl or repo (highly encouraged)
envinfo
The text was updated successfully, but these errors were encountered: