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

--coverage.all=false doesn't work for vitest workspace #4694

Closed
6 tasks done
ocavue opened this issue Dec 7, 2023 · 2 comments · Fixed by #4697
Closed
6 tasks done

--coverage.all=false doesn't work for vitest workspace #4694

ocavue opened this issue Dec 7, 2023 · 2 comments · Fixed by #4697
Labels

Comments

@ocavue
Copy link
Contributor

ocavue commented Dec 7, 2023

Describe the bug

I have multiple packages in a monorepo and I'm using vitest workspace to test them. Some packages in this repo have test files while some other packages don't. However, even if I have --coverage.all=false, all packages are included in the coverage reporter.

Reproduction

$ git clone https://github.com/issueset/vitest-v1-coverage.git
$ cd vitest-v1-coverage
$ pnpm install

$ pnpm run test:v8
> vitest run --coverage.enabled --coverage.provider=v8 --coverage.all=false
--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------|---------|----------|---------|---------|-------------------
All files           |      30 |       50 |      50 |      30 |                   
 pkg-with-vitest    |     100 |      100 |     100 |     100 |                   
  index.ts          |     100 |      100 |     100 |     100 |                   
 pkg-without-vitest |       0 |        0 |       0 |       0 |                   
  index.vue         |       0 |        0 |       0 |       0 | 1-7               
--------------------|---------|----------|---------|---------|-------------------

$ pnpm run test:istanbul
> vitest run --coverage.enabled --coverage.provider=istanbul --coverage.all=false
SyntaxError: /private/tmp/vitest-v1-coverage/packages/pkg-without-vitest/index.vue: Support for the experimental syntax 'jsx' isn't currently enabled (1:1):

> 1 | <script setup lang="ts">
    | ^
  2 | const a = 1;
  3 | </script>
  4 |

System Info

System:
    OS: macOS 14.1.1
    CPU: (8) arm64 Apple M2
    Memory: 3.39 GB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - /opt/homebrew/opt/node@18/bin/node
    npm: 9.6.7 - /opt/homebrew/opt/node@18/bin/npm
    pnpm: 8.10.0 - /opt/homebrew/opt/node@18/bin/pnpm
    bun: 1.0.4 - ~/.bun/bin/bun
  Browsers:
    Chrome: 119.0.6045.199
    Chrome Canary: 118.0.5975.0
    Safari: 17.1
    Safari Technology Preview: 17.4
  npmPackages:
    @vitest/coverage-istanbul: ^1.0.2 => 1.0.2 
    @vitest/coverage-v8: ^1.0.2 => 1.0.2 
    vite: ^4.5.0 => 4.5.0 
    vitest: 1.0.2 => 1.0.2 

Used Package Manager

pnpm

Validations

@AriPerkkio
Copy link
Member

AriPerkkio commented Dec 7, 2023

Does it work when defined in configuration file? Or does --coverage.all=0 work?
After quick testing it seems that there might be some CLI argument parsing issues, again. 😢

@mbland
Copy link
Contributor

mbland commented Dec 8, 2023

#3962, correct?

It looks like cac does a great job of parsing args, but leaves it up to the client to convert strings to other types. The Negated Options section of the README suggests a different schema that would allow for boolean options, though:

To allow an option whose value is false, you need to manually specify a negated option:

  cli
    .command('build [project]', 'Build a project')
    .option('--no-config', 'Disable config file')
    .option('--config <path>', 'Use a custom config file')

This will let CAC set the default value of config to true, and you can use --no-config flag to set it to false.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants