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

Threshold on a Glob Pattern does not show an error message #5545

Closed
6 tasks done
kanteankit opened this issue Apr 15, 2024 · 3 comments · Fixed by #5574
Closed
6 tasks done

Threshold on a Glob Pattern does not show an error message #5545

kanteankit opened this issue Apr 15, 2024 · 3 comments · Fixed by #5574
Labels
feat: coverage Issues and PRs related to the coverage feature p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@kanteankit
Copy link

kanteankit commented Apr 15, 2024

Describe the bug

When a global coverage threshold is set in vitest configuration, an error message is shown like this

ERROR: Coverage for functions (0%) does not meet global threshold (100%)

image

But, when threshold for a particular file is set using the glob-pattern option, there is no such error message.

Reproduction

1.Clone this repo: https://github.com/kanteankit/vitest
2. Run npm install
3. Run npm run coverage

Expected behaviour: An error message should show up which says that the threshold for the file AsAsync.vue is not met.
Actual behaviour: There is no error message

In vitest.config.ts, a threshold of 100 is set on components/AsAsync.vue. But, it is not throwing any error.

/// <reference types="vitest" />

import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    Vue(),
  ],
  test: {
    globals: true,
    environment: 'jsdom',
    coverage: {
      thresholds: {
        // functions: 100, // This shows an error message
        'components/AsAsync.vue': {
          functions: 100 // This does not show an error message
        }
      }
    }
  },
})

Note: Couldn't provide a Stackblitz because it gives an error saying @vitest/coverage-v8 does not work on Stackblitz. Report will be empty.

System Info

System:
    OS: Linux 5.19 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 5.60 GB / 15.48 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 10.2.5 - ~/.nvm/versions/node/v20.9.0/bin/npm
  Browsers:
    Chrome: 123.0.6312.122
  npmPackages:
    @vitejs/plugin-vue: latest => 5.0.4 
    @vitest/coverage-istanbul: ^1.5.0 => 1.5.0 
    @vitest/coverage-v8: ^1.5.0 => 1.5.0 
    vite: latest => 5.2.8 
    vitest: latest => 1.5.0

Used Package Manager

npm

Validations

@AriPerkkio
Copy link
Member

Does this work?

    coverage: {
      thresholds: {
        // functions: 100, // This shows an error message
-       'components/AsAsync.vue': {
+       '**/components/AsAsync.vue': {
          functions: 100 // This does not show an error message
        }
      }
    }

@kanteankit
Copy link
Author

kanteankit commented Apr 16, 2024

Does this work?

Yeah. It does. Thanks a lot.
But, this is a valid bug, right? I provided an actual path of a file and it did not consider it during coverage.

We were using jest before and these full paths were working there.

We had also added coverage for certain folders like this:

'./src/folder-1': {
      statements: 64,
      branches: 61,
      lines: 64,
      functions: 68
    },

This is also not working in vitest. I think as per @AriPerkkio example, we will have to use **/folder-1/** .

@AriPerkkio
Copy link
Member

Glob patterns are matched against absolute file paths here:

const matchingFiles = files.filter(file => mm.isMatch(file, glob))

Instead we should resolve the files relative to project root and match those against the glob patterns.

@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) and removed pending triage labels Apr 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 7, 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