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

Incorrect source mapping leads to Inaccurate istanbul coverage #257

Open
Neemsigo opened this issue Aug 7, 2024 · 0 comments
Open

Incorrect source mapping leads to Inaccurate istanbul coverage #257

Neemsigo opened this issue Aug 7, 2024 · 0 comments

Comments

@Neemsigo
Copy link

Neemsigo commented Aug 7, 2024

Hi!

I've encountered an issue with sourcemaps, which leads to inflated coverage in my project. When dealing with large chunks, the file is considered fully covered after conversion in Istanbul while in v8 report code is not covered.

The problem lies in this magical code inside the v8-to-istanbul

// The source maps generated by https://github.com/istanbuljs/istanbuljs
  // (using @babel/core 7.7.5) have behavior, such that a mapping
  // mid-way through a line maps to an earlier line than a mapping
  // at position 0. Using the line at positon 0 seems to provide better reports:
  //
  //     if (true) {
  //        cov_y5divc6zu().b[1][0]++;
  //        cov_y5divc6zu().s[3]++;
  //        console.info('reachable');
  //     }  else { ... }
  //  ^  ^
  // l5  l3
  const min = originalPositionFor(sourceMap, {
    line,
    column: 0,
    bias: GREATEST_LOWER_BOUND
  })
  if (min.line > original.line) {
    original = min
  }

Due to this in the method _maybeRemapStartColEndCol program can't find covSource for some of my project files.

const matchingSource = this.covSources.find(covSource => covSource.path === source)

For example, a path for code located in ./lib/test.ts is assigned to some ./node_modules/lib-name

I resolved this by forking and removing this magical code. It looks like it breaks the coverage.
Can you please explain the purpose of this code?
Is there a way to fix this behavior without fork?

Reproduction steps:

  • git clone https://github.com/Neemsigo/v8-to-istanbul-source-map-problem.git
  • cd v8-to-istanbul-source-map-problem
  • npm i
  • node test.js

This will generate a result.json file where you can see that all files are considered fully covered in the Istanbul format, even though v8 shows that they are not.

Environment:

  • node: v20.11.1
  • npm: 10.2.4
  • OS: macOS 14.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant