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

Empty report on a file with multiple sources #229

Open
luixo opened this issue Oct 9, 2023 · 0 comments
Open

Empty report on a file with multiple sources #229

luixo opened this issue Oct 9, 2023 · 0 comments

Comments

@luixo
Copy link

luixo commented Oct 9, 2023

Hello,
I'm building 100% coverage for my frontend.
And it seems like (empty-report) directive applies only to this.covSource[0] (or the one that matches by path), so if I map my source to multiple files - I cannot mark all of them as empty.

Details:
I run next.js build, run frontend tests on it and record coverage via Playwright's startJSCoverage. As I want to include all the files been built to get the 100% coverage, I read the whole build folder, tinker around with sourcemaps (kudos to playwright-coverage package) - and voila - I get all my files in the report.
The only problem I got is that report indicates all statements as run exactly once.
Eventually I tracked it down to generation of CovLine with count equals 1 to push it down to 0 later and magic (empty-report) function name.

The object I pass to applyCoverage looks like this:

[{
    ranges: [{
        startOffset: 0,
        endOffset: Infinity,
        count: 0,
    }],
    functionName: '(empty-report)',
    isBlockCoverage: true
}]

Unfortunately, this line picks only one covSource to apply empty report to.

I applied a patch to that piece to accomplish empty report for all the covSources:

applyCoverage (blocks) {
  blocks.forEach(block => {
+   if (block.functionName === '(empty-report)') {
+     this.covSources.forEach((covSource) => covSource.source.lines.forEach((line) => {
+       line.count = 0
+       return true
+     }));
+   }
    block.ranges.forEach((range, i) => {
      const { startCol, endCol, path, covSource } = this._maybeRemapStartColEndCol(range)

Is there a way around it or my patch looks good and we should include it in the repo?

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