Skip to content
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

Sourcemaps don't work for code executed before tests #5925

Closed
jamietre opened this issue Apr 4, 2018 · 10 comments · Fixed by #6176 or #5945
Closed

Sourcemaps don't work for code executed before tests #5925

jamietre opened this issue Apr 4, 2018 · 10 comments · Fixed by #6176 or #5945

Comments

@jamietre
Copy link
Contributor

jamietre commented Apr 4, 2018

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When errors occur in code that executes before actual test code (e.g. all module-level code in the modules being imported by a test), the source code excerpt and stack trace line numbers are reported incorrectly by Jest

If the current behavior is a bug, please provide the steps to reproduce.

Generally, just throw an error in module level code that's imported by a test.

https://github.com/jamietre/jest-source-map-problem/tree/6afd64cf0dfe0fc4d3b3e4f14ccc0bdea6f7787c

What is the expected behavior?

The source map should work

Please mention your node.js, yarn and operating system version.

node@8.9.4
yarn@1.3.2
macOS@10.13.4 (High Sierra)

@SimenB
Copy link
Member

SimenB commented Apr 4, 2018

Changing this into a normal require fixes it: https://github.com/facebook/jest/blob/23eec748db0de7b6b5fcda28cc51c48ddae16545/packages/jest-jasmine2/src/index.js#L119-L123

I'm not sure of the implications of it, though.

@jwbay thoughts?

@jwbay
Copy link
Contributor

jwbay commented Apr 4, 2018

Switching it to runtime.requireModule would mean source-map-support is mocked if automocking is enabled (that was a problem before). As far as a top-level require/import, I'm not sure either.

@SimenB
Copy link
Member

SimenB commented Apr 4, 2018

I meant require, not going through runtime. Shouldn't be needed though...

@jamietre
Copy link
Contributor Author

jamietre commented Apr 5, 2018

Changing runtime.requireInternalModule to require fixes it for errors thrown before the test code, but breaks it for errors thrown inside the test code in this simple scenario.

Not to muddy the waters, but source maps are also broken inside the test for the more complex scenario that led me to this bug report. I just haven't been able to repro in isolation yet; once i can repro outside of our application I'll add to this report. This change has no effect on that either (which makes sense, since it was already broken anyway).

@jamietre
Copy link
Contributor Author

jamietre commented Apr 6, 2018

Traced the problem with source maps in more complex scenario to manifesting when an error occurs in a JavaScript dependency of a TypeScript file when using ts-jest. Not sure if this is a problem with ts-jest or with using multiple transforms generally. Opened kulshekhar/ts-jest#485 there.

@SimenB
Copy link
Member

SimenB commented Apr 9, 2018

See #5945. Not sure it's the correct solution, but seemingly works

SimenB added a commit to SimenB/jest that referenced this issue Apr 9, 2018
@jamietre
Copy link
Contributor Author

Works for me too. I merged this and tested it in my more complex scenario (involving ts-jest) and it seems to also solve that problem (when using the disableSourceMapSupport option there). Seems like this is closing in on a final solution!

@jamietre
Copy link
Contributor Author

Can we reopen this issue, since it's no longer fixed following #6106

@SimenB
Copy link
Member

SimenB commented May 11, 2018

Sure. We're gonna fix it (somehow) before release, though

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants