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

jest.mock() calls underneath the code mangle the stacktraces #240

Closed
GeeWee opened this issue Jun 4, 2017 · 6 comments · Fixed by #554
Closed

jest.mock() calls underneath the code mangle the stacktraces #240

GeeWee opened this issue Jun 4, 2017 · 6 comments · Fixed by #554

Comments

@GeeWee
Copy link
Collaborator

GeeWee commented Jun 4, 2017

  • Issue

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.

@GeeWee GeeWee added the 🐛 Bug label Jun 4, 2017
@kulshekhar
Copy link
Owner

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.

@cspotcode
Copy link
Contributor

Babel supports inputting a sourcemap alongside the input code, right? So if the hoisting process generates a sourcemap, pass it to babel.

inputSourceMap option: https://babeljs.io/docs/usage/api/

@kulshekhar
Copy link
Owner

Hoisting is done in jest and not in babel (afaik) and jest doesn't update the sourcemap during the hosting process

@cspotcode
Copy link
Contributor

@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.

@kulshekhar
Copy link
Owner

why does ts-jest have to call babel

iirc, this was needed to do hoisting. #235 has all the related discussion.

Wouldn't jest be doing that after this preprocessor has finished its job?

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

@GeeWee
Copy link
Collaborator Author

GeeWee commented Oct 30, 2017

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.

GeeWee added a commit that referenced this issue May 26, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants