cenfun / jest-monocart-coverage

A Jest custom reporter for monocart coverage reports
MIT License
3 stars 1 forks source link

Bug with v8 Paths, but not sure what is the root cause #5

Closed Aghassi closed 2 months ago

Aghassi commented 2 months ago

I followed the example provided in the README, but the issue I'm seeing with my system is that the v8 data strips out the sourcePath from the file. This does not happen if the jest config does not have coverageProvider: 'v8'. The thing is, I'm not sure why this is happening. I'm opening this issue more to discuss. I have not made a way to publicly reproduce because this is on our internal monorepo with Bazel.

Basically, the lcov file generate is missing path/to/file.ts with that option on. It just returns file.ts.

I have some theories, but nothing concrete. Any ideas?

cenfun commented 2 months ago

This path issue could be a sourcemap issue. The sourcemap of the file didn't provide the full path of the file.

{"version":3,"sources":["file.js"],"sourcesContent":[ ...

It is supposed to be:

{"version":3,"sources":["path/to/file.js"],"sourcesContent":[ ...

Please try to normalize the sourcePath with option sourcePath. Possible solutions:

const path = require("path")

// MCR coverage options
{
  sourcePath: (filePath, info)=> {
    if (!filePath.includes('/') && info.distFile) {
      return `${path.dirname(info.distFile)}/${filePath}`;
    }
    return filePath;
  },

}
Aghassi commented 2 months ago

Thanks I believe that did it! That's definitely worth documenting in the README. Should it go in this repo or the monocart main one?

cenfun commented 2 months ago

Thank you for the reminder, I have updated the document for both jest-monocart-coverage and monocart-coverage-reports repo.