-
Notifications
You must be signed in to change notification settings - Fork 453
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
jest.mock() calls underneath the code mangle the stacktraces #240
Comments
This happens because the sourcemaps generated by babel are based on the code as it is after hoisting. Any suggestions/contributions to fix this would be very welcome. |
Babel supports inputting a sourcemap alongside the input code, right? So if the hoisting process generates a sourcemap, pass it to babel.
|
Hoisting is done in jest and not in babel (afaik) and jest doesn't update the sourcemap during the hosting process |
@kulshekhar If that's the case, why does ts-jest have to call babel? Wouldn't jest be doing that after this preprocessor has finished its job? I'm trying to debug this bug so I'm figuring out how everything works. |
iirc, this was needed to do hoisting. #235 has all the related discussion.
Jest doesn't directly do hoisting. It uses the babel-jest transformer to do that. Since jest doesn't use babel-jest when using ts-jest, we had to incorporate that bit of functionality directly in here. This is to the best of my recollection. Please correct if I'm wrong @GeeWee |
Yeah that's accurate. Edit: I still think babel should be able to update the sourcemap during the hoisting though - I don't know why it doesn't happen in our case. Would love a PR fixing this, as I'm 90% sure it should be possible. |
This PR uses the jest infrastructure for sourcemaps. It completely removes any dependance on source-map-support from our part. Note that removing the languageServer is a breaking change - however it was never documented. A language-server branch has been created based off master. This PR is based on #552 so merge that in first. It closes #340. Surprisingly enough it also closes #240 - passing the sourcemaps explicitly to babel means that the line# are correct in the other end - you'll see that in one of the updated tests. It fixes part of #529 Note that no line# has changed, but some column names have in the tests. I'm not sure the original column names were ever accurate.
If you place code that is hoisted, such as jest.mock() calls, underneath your tests, the stacktrace line numbers are off.
Issue raised in #239 - more details there.
Workaround is to place the mock calls before any actual test code.
This bug is considered low priority.
The text was updated successfully, but these errors were encountered: