Skip to content

TypeScript mapRoot setting breaks source map URL generation #1718

@ArtemGovorov

Description

@ArtemGovorov

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions