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

Fix support for sourcemaps in transforms #5121

Closed
SimenB opened this issue Dec 18, 2017 · 8 comments
Closed

Fix support for sourcemaps in transforms #5121

SimenB opened this issue Dec 18, 2017 · 8 comments

Comments

@SimenB
Copy link
Member

SimenB commented Dec 18, 2017

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

What is the current behavior?
In #5117, #3458 was partially reverted. This is a tracking issue for its reactivation.

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

N/A

What is the expected behavior?
Make the skipped test in #5117 pass.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

N/A

@SimenB
Copy link
Member Author

SimenB commented Dec 18, 2017

I don't understand properly what's going on here.

The reason we attempt to read from the sourcemap, is that the test file is added to sourceMapInfo here: https://github.com/facebook/jest/blob/d1845116ebe818e6d945d50ad4857752758970ee/packages/jest-runtime/src/index.js#L440-L447

But when we try to read the file, it's not there:
https://github.com/facebook/jest/blob/d1845116ebe818e6d945d50ad4857752758970ee/packages/jest-cli/src/reporters/coverage_reporter.js#L63

It might be that we just have to add the source map information we write to disk to the _sourceMapStore instance.

@SimenB
Copy link
Member Author

SimenB commented Dec 23, 2017

Make sure to test that we support #5151 as well when this is fixed.

@Aftabnack
Copy link
Contributor

I'd like to contribute if possible.

@SimenB
Copy link
Member Author

SimenB commented Dec 23, 2017

PR very much welcome! I won't personally work on this for some time, but happy to review code :)

@Aftabnack
Copy link
Contributor

Cool! I'll give it a shot!

@Aftabnack
Copy link
Contributor

Aftabnack commented Dec 25, 2017

Here is what I have found so far

TLDR

  • Suspect an incorrect usage of mapCoverage boolean at this line

Longer version

  • Here in the getSourceMapInfo() function, It is taking sourceMaps written into jest's cache folder.
    https://github.com/facebook/jest/blob/4f8f6fba35c1cedfb2ce3cb622831c188b221af5/packages/jest-runtime/src/index.js#L440-L447

  • Here's a sample of what the object this._sourceMapRegistry looks like, all the values end with .map looking for a sourcemap file

    {
    '/home/aftab/work/code/eoc-ui/src/components/reusable-components/feedback/FeedBack.phnx': '/tmp/jest_rs/jest-transform-cache-f634946ae80171f59c1ddb40b765ffcb-c8daf9fb18de3edbc88a4eda9bec586e/d4/FeedBack_d4992420ed5d74d7f3a0cddeea3ba313.map',
    '/home/aftab/work/code/eoc-ui/src/components/reusable-components/feedback/TextToMarkdown.phnx': '/tmp/jest_rs/jest-transform-cache-f634946ae80171f59c1ddb40b765ffcb-c8daf9fb18de3edbc88a4eda9bec586e/12/TextToMarkdown_12d9a7499ca565056659ef0951ca7515.map'
    }
  • From there I went to script_transformer.js transformSource() function.
    https://github.com/facebook/jest/blob/4f8f6fba35c1cedfb2ce3cb622831c188b221af5/packages/jest-runtime/src/script_transformer.js#L194-L280

  • In the snippet that I posted above, the inlineSourceMaps are never read, since mapCoverage defaults to false.

  • The if block where the .map file is supposed to be written, the transformed.map won't be defined. Hence the .map file won't be written into cache.

  • So when the getSourceMapInfo() is called, it returns an empty object.

  • So my guess is we shouldn't have the mapCoverage boolean in the place where we read the inlineSourceMaps

@SimenB
Copy link
Member Author

SimenB commented Feb 17, 2018

Should be fixed in #5177

@SimenB SimenB closed this as completed Feb 17, 2018
@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
Development

No branches or pull requests

2 participants