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

Add excludeAfterRemap option for c8 coverage #3818

Closed
4 tasks done
RebeccaStevens opened this issue Jul 26, 2023 · 8 comments · Fixed by #6309
Closed
4 tasks done

Add excludeAfterRemap option for c8 coverage #3818

RebeccaStevens opened this issue Jul 26, 2023 · 8 comments · Fixed by #6309
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@RebeccaStevens
Copy link

RebeccaStevens commented Jul 26, 2023

Clear and concise description of the problem

The option --exclude-after-remap can't currently be set in vite.config.ts.

Suggested solution

Add excludeAfterRemap as an option to the test.coverage config for provider v8.

Alternative

Use the c8 provider or run vitest as c8 vitest run and a .c8rc.json config file.

Additional context

The c8 provider currently supports excludeAfterRemap but TypeScript complains about it not being a valid option.

Also: #3813

Validations

@AriPerkkio
Copy link
Member

The @vitest/coverage-c8 package has been removed and won't be receiving any updates from now. See #3614.

@RebeccaStevens
Copy link
Author

This issue relates to @vitest/coverage-v8 as well.

@RebeccaStevens
Copy link
Author

RebeccaStevens commented Jul 26, 2023

@AriPerkkio I was going off this quote from #3339

Adds new coverage provider package @vitest/coverage-v8. For end-users it should provide identical coverage results as @vitest/coverage-c8.

My assumption being that the v8 provider also supports source map remappming like c8 does. Is this not the case?

@AriPerkkio
Copy link
Member

The @vitest/coverage-v8 and @vitest/coverage-istanbul both remap the coverage results back to source files using istanbul-lib-source-maps. Without source map remapping users who are using Typescript, Vue, React, Svelte, or any compiled language/feature would be unable to see coverage of their source files.

Doesn't coverage.exclude achieve everything that excludeAfterRemap could provide? After reading #3813 I'm not really sure what your use case is.

@RebeccaStevens
Copy link
Author

RebeccaStevens commented Jul 26, 2023

This is the vite.config.ts that works for my currently:

// ...

export default defineConfig({
  plugins: [tsconfigPaths()],

  test: {
    include: [testFilePattern],
    coverage: {
      provider: "c8",
      include: ["src/**/*.ts"],
      exclude: ["src/util/conditional-imports/**/*.ts"],
      // @ts-expect-error -- Untyped option.
      excludeAfterRemap: true,
      clean: true,
      reporter: ["lcov", "text"],
      watermarks: {
        lines: [80, 95],
        functions: [80, 95],
        branches: [80, 95],
        statements: [80, 95],
      },
    },
  },
});

With this config, the coverage result look like this:

image

If I remove excludeAfterRemap, the remapping doesn't work properly and I get:

image

If I also remove the include and exclude options so we can see all the coverage is on the compiled files, not the source files:

image

@RebeccaStevens
Copy link
Author

Here's a link to the repo if you want to have a look there: https://github.com/eslint-functional/eslint-plugin-functional/tree/next

@RebeccaStevens
Copy link
Author

@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2023
@AriPerkkio AriPerkkio reopened this Aug 9, 2024
@AriPerkkio
Copy link
Member

This was accidentally locked by the bot.

Sorry for forgetting this feature request @RebeccaStevens! I didn't understand the issue completely earlier. I've now run into this same issue myself and see what you meant.

Let's add support for this. As the globbing might be slow, and people who don't bundle their source files for tests do not need this feature, let's make this opt-in and disabled by default. Exactly as c8 does.

@AriPerkkio AriPerkkio added feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority) labels Aug 9, 2024
@vitest-dev vitest-dev unlocked this conversation Aug 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants