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

[BUG] Incorrect code coverage when converting from V8 to istanbul #216

Open
edumserrano opened this issue Jun 17, 2023 · 2 comments
Open

Comments

@edumserrano
Copy link

Hi,

Bug description

I have a project where I'm using monocart-reporter to produce a code coverage report. The way my project is configured captures code coverage in V8 and then that is converted to istanbul.

I'm not doing the conversation myself, I use some options on the monocart-reporter that when set use this package v8-to-istanbul to convert the V8 code coverage:

coverage: {
    toIstanbul: true,
    lcov: true,
    ...
},

When I enable these options the code coverage that I get is incorrect. Please see screenshots below for more information. The code coverage screenshots were produced by running with:

  • babel + istanbul: this shows correct code coverage.
  • v8 + monocart reporter without the toIstanbul property set which defaults to false: this shows correct code coverage.
  • v8 + monocart reporter with the toIstanbul property set to true: this shows INCORRECT code coverage.
babel+istanbul

Note
The code coverage below is correct

app/core/ui-services/ui-helper-functions.ts
image

app/features/find-institution/institutions-list/institutions-list.component.ts
image

v8 + monocart reporter without the toIstanbul property set which defaults to false

Note
The code coverage below is correct

src/app/core/ui-services/ui-helper-functions.ts
image

src/app/features/find-institution/institutions-list/institutions-list.component.ts
image

v8 + monocart reporter with the toIstanbul property set to true

Warning
The code coverage below is INCORRECT. Some lines are showed as covered when they should not be.

app/core/ui-services/ui-helper-functions.ts
image

app/features/find-institution/institutions-list/institutions-list.component.ts
image

How to reproduce

  1. Checkout the temp branch at edumserrano/monocart-code-coverage-demo/tree/temp.
  2. run npm install to install all the required packages

To get the babel+istanbul code coverage:

  1. run npm run test-istanbul. The first time tests will fail because of missing snapshots, you can ignore this.
  2. run npm run nyc-report.
  3. run npm run open-istanbul-coverage.

To get the v8 + monocart reporter without the toIstanbul property set which defaults to false code coverage:

  1. run npm run test-monocart. The first time tests will fail because of missing snapshots, you can ignore this.
  2. run npm run open-monocart-coverage.

To get the v8 + monocart reporter with the toIstanbul property set to true code coverage:

  1. go to the playwright.confi.ts for the monocart setup and uncomment the lines:
// toIstanbul: true,
// lcov: true,
  1. run npm run test-monocart. The first time tests will fail because of missing snapshots, you can ignore this.
  2. run npm run open-monocart-coverage.

More notes

  • To clarify, the problem is that when using toIstanbul set to true the code coverage conversion marks some lines as covered when they should not be.

  • I first opened this bug at [BUG] Incorrect code coverage when converting from V8 to istanbul cenfun/monocart-reporter#50. I was told that the monocart-reporter package uses this package v8-to-istanbul to do the conversion.

  • I hope the instructions provided are enough to replicate the issue and debug it. I'm hoping that by following the instructions to run with v8 + monocart reporter without the toIstanbul property set which defaults to false, you can look at the V8 coverage file and then you would be able to provide that to the v8-to-istanbul package to debug the problem.

Let me know if you need more information.

@AriPerkkio
Copy link
Contributor

@cenfun could you fix this to v8-to-istanbul as well?

@cenfun
Copy link

cenfun commented Jan 28, 2024

@AriPerkkio Sorry, I can't fix it, It's very complicated, any changes could break its function.

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

3 participants