Skip to content

feat!(coverage): glob based coverage thresholds#4442

Merged
sheremet-va merged 1 commit intovitest-dev:mainfrom
AriPerkkio:feat/coverage-glob-thresholds
Nov 17, 2023
Merged

feat!(coverage): glob based coverage thresholds#4442
sheremet-va merged 1 commit intovitest-dev:mainfrom
AriPerkkio:feat/coverage-glob-thresholds

Conversation

@AriPerkkio
Copy link
Copy Markdown
Member

@AriPerkkio AriPerkkio commented Nov 5, 2023

Description

Closes #3709.

Refactors coverage thresholds API into new shape and adds support for specifying thresholds for specific files using glob patterns. Introducing breaking changes for the configuration options made sense here and final results looks clean and simple.

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    coverage: {
      thresholds: {
        100: false,
        perFile: true,
        autoUpdate: true,

        // Thresholds for all files
        lines: 100,
        functions: 100,
        branches: 80,
        statements: 90,

        // Thresholds for utilities
        "**/utils/**": {
          lines: 80,
          statements: 50,
        },
      },
    },
  },
});

BREAKING CHANGES

  • coverage.perFile is now coverage.thresholds.perFile
  • coverage.thresholdAutoUpdate is now coverage.thresholds.autoUpdate
  • coverage.100 is now coverage.thresholds.100
  • coverage.lines is now coverage.thresholds.lines
  • coverage.functions is now coverage.thresholds.functions
  • coverage.branches is now coverage.thresholds.branches
  • coverage.statements is now coverage.thresholds.statements

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 5, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 8dd1640
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/655630028b12f3000816be58

Comment thread packages/vitest/src/types/coverage.ts Outdated
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from e96b8a3 to 490aafb Compare November 8, 2023 19:31
@arianshi
Copy link
Copy Markdown

arianshi commented Nov 9, 2023

@AriPerkkio
Can you make a patched version? We really need this feature

@AriPerkkio
Copy link
Copy Markdown
Member Author

@arianshirepublik this feature is not yet finished but should make it to v1 release. I'm introducing some breaking changes to coverage option structure at the same time.

@AriPerkkio
Copy link
Copy Markdown
Member Author

Adding support to thresholdAutoUpdate now that there are multiple different coverage thresholds in configuration file is a bit tricky. Earlier we've used just search-and-replace with regexp but now we may need to parse the configuration file's AST.

@sheremet-va
Copy link
Copy Markdown
Member

Adding support to thresholdAutoUpdate now that there are multiple different coverage thresholds in configuration file is a bit tricky. Earlier we've used just search-and-replace with regexp but now we may need to parse the configuration file's AST.

Maybe you can try https://github.com/unjs/magicast ?

Comment thread packages/vitest/package.json Outdated
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from 23dee73 to 01036c9 Compare November 12, 2023 09:16
Comment thread packages/vitest/src/utils/coverage.ts Outdated
@arianshi
Copy link
Copy Markdown

@arianshirepublik this feature is not yet finished but should make it to v1 release. I'm introducing some breaking changes to coverage option structure at the same time.

Hi @AriPerkkio
Can we use this feature in v1.0.0-beta.4?

@AriPerkkio
Copy link
Copy Markdown
Member Author

No, this feature is not yet finished. Please wait patiently 😄
I'm planning to finalize this during this week.

@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch 3 times, most recently from aead892 to b934bc3 Compare November 15, 2023 19:04
@AriPerkkio AriPerkkio changed the title feat(coverage): glob based coverage thresholds feat!(coverage): glob based coverage thresholds Nov 15, 2023
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch 2 times, most recently from e19d3e0 to 8c0855d Compare November 16, 2023 05:53
@AriPerkkio AriPerkkio marked this pull request as ready for review November 16, 2023 05:53
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from 8c0855d to cfae6cd Compare November 16, 2023 05:56
Comment thread packages/vitest/src/utils/coverage.ts Outdated
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from cfae6cd to 9c01123 Compare November 16, 2023 15:02
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from 9c01123 to 6b4a109 Compare November 16, 2023 15:03
BREAKING CHANGES

- `coverage.perFile` is now `coverage.thresholds.perFile`
- `coverage.thresholdAutoUpdate` is now `coverage.thresholds.autoUpdate`
- `coverage.100` is now `coverage.thresholds.100`
- `coverage.lines` is now `coverage.thresholds.lines`
- `coverage.functions` is now `coverage.thresholds.functions`
- `coverage.branches` is now `coverage.thresholds.branches`
- `coverage.statements` is now `coverage.thresholds.statements`
@AriPerkkio AriPerkkio force-pushed the feat/coverage-glob-thresholds branch from 6b4a109 to 8dd1640 Compare November 16, 2023 15:06
@sheremet-va sheremet-va merged commit 4953410 into vitest-dev:main Nov 17, 2023
@AriPerkkio AriPerkkio deleted the feat/coverage-glob-thresholds branch November 17, 2023 19:09
@arianshi
Copy link
Copy Markdown

Hi @AriPerkkio
I tested v1.0.0-beta.5
The report will not be generated. Can you check it?

image

@arianshi
Copy link
Copy Markdown

arianshi commented Nov 21, 2023

Hi @AriPerkkio

When I run the command: yarn run test --coverage,

The desired test case has been executed but no test report or coverage table has been generated, and then the program stops here.

My config:

test: {
      setupFiles: './src/test/setup.ts',
      globals: true,
      environment: 'jsdom',
      coverage: {
        reporter: ['text', 'json-summary', 'json'],
        thresholds: {
          100: true,
          perFile: true,
          autoUpdate: true,

          // Thresholds for all files
          lines: 100,
          functions: 100,
          branches: 100,
          statements: 100,
        },
      },
    }

image

I can't see this table:

image

@AriPerkkio
Copy link
Copy Markdown
Member Author

@arianshirepublik please open new issue with reproducible setup.

renovate Bot referenced this pull request in s1adem4n/soundcloud Dec 7, 2023