Jest: Fix support for sourcemaps in transforms

Created on 18 Dec 2017  路  7Comments  路  Source: facebook/jest

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

Bug Help Wanted

All 7 comments

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.

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

I'd like to contribute if possible.

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

Cool! I'll give it a shot!

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

Should be fixed in #5177

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ticky picture ticky  路  3Comments

paularmstrong picture paularmstrong  路  3Comments

hramos picture hramos  路  3Comments

withinboredom picture withinboredom  路  3Comments

samzhang111 picture samzhang111  路  3Comments