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.
[email protected]
[email protected]
[email protected] (High Sierra)
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?
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.
I meant require, not going through runtime. Shouldn't be needed though...
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).
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 https://github.com/kulshekhar/ts-jest/issues/485 there.
See #5945. Not sure it's the correct solution, but seemingly works
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!
Can we reopen this issue, since it's no longer fixed following https://github.com/facebook/jest/pull/6106
Sure. We're gonna fix it (somehow) before release, though
Most helpful comment
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
disableSourceMapSupportoption there). Seems like this is closing in on a final solution!