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

TypeScript mapRoot setting breaks source map URL generation #1718

Closed
ArtemGovorov opened this issue Jun 9, 2020 · 1 comment · Fixed by #1741
Closed

TypeScript mapRoot setting breaks source map URL generation #1718

ArtemGovorov opened this issue Jun 9, 2020 · 1 comment · Fixed by #1741
Labels
🐛 Bug Confirmed Bug is confirmed

Comments

@ArtemGovorov
Copy link

ArtemGovorov commented Jun 9, 2020

🐛 Bug Report

The mapRoot setting breaks source map URL generation.

To Reproduce

Steps to reproduce the behavior:

  • add "mapRoot": "./src", to tsconfig.json (any relative path will do),
  • TypeScript generated file sourceMappingURL will be a relative path, not a file name in this case: //# sourceMappingURL=../../src/app/app.component.spec.js.map
  • the updateOutput function expects the path to be just a file name
    const sourceMapLength =
    `${base}.map`.length + (getExtension(normalizedFileName).length - extname(normalizedFileName).length)
    , so the code updated by ts-jest looks like: //sourceMappingURL=../../src/app/data:application/json;charset=utf-8;base64,...,
  • the malformed sourceMappingURL causes Jest to ignore it and to map errors and coverage incorrectly.

Expected behavior

The updateOutput function should expect the path to be a relative path, not always a file name.

Link to repo (highly encouraged)

The issue can be reproduced in any repo by adding the mapRoot setting and either inspecting generated code, or producing any error in the sample repo and observing incorrect line reporting by Jest.

This sample repo may be used: https://github.com/ArtemGovorov/wallaby-2434.

Running npx jest in the repo's root produces wrong error report (lines are not mapped) because of the issue described above:

Screen Shot 2020-06-09 at 12 42 14 pm

@ArtemGovorov ArtemGovorov added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jun 9, 2020
@ahnpnl ahnpnl added 🐛 Bug Confirmed Bug is confirmed and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jun 9, 2020
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 9, 2020

Thank you for submitting the issue. Indeed this case has been never considered before. I myself don’t even know this option exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Confirmed Bug is confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants