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

Invalid Characters in Path #3780

Closed
6 tasks done
SimonSimCity opened this issue Jul 18, 2023 · 4 comments · Fixed by #3794
Closed
6 tasks done

Invalid Characters in Path #3780

SimonSimCity opened this issue Jul 18, 2023 · 4 comments · Fixed by #3794
Labels
feat: coverage Issues and PRs related to the coverage feature

Comments

@SimonSimCity
Copy link

Describe the bug

I have a nuxt project, where I had the same problem as described in #3013. I've tried to create a minimal example of how to reproduce this. The output is:

 % Coverage report from v8
-----------------------------------------------------------------------------------------------|---------|----------|---------|---------|-------------------
File                                                                                           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-----------------------------------------------------------------------------------------------|---------|----------|---------|---------|-------------------
All files                                                                                      |     100 |    96.66 |   32.14 |     100 |                   
 coverage-invalid-path                                                                         |     100 |      100 |     100 |     100 |                   
  app.vue                                                                                      |     100 |      100 |     100 |     100 |                   
 coverage-invalid-path/virtual:nuxt:/Users/simon/Documents/coverage-invalid-path/.nuxt         |     100 |    96.42 |   32.14 |     100 |                   
  app-component.mjs                                                                            |     100 |      100 |     100 |     100 |                   
  components.plugin.mjs                                                                        |     100 |      100 |     100 |     100 |                   
  css.mjs                                                                                      |     100 |      100 |     100 |     100 |                   
  error-component.mjs                                                                          |     100 |      100 |       0 |     100 |                   
  middleware.mjs                                                                               |     100 |      100 |      50 |     100 |                   
  nitro.client.mjs                                                                             |     100 |       80 |     100 |     100 | 1                 
  nuxt.config.mjs                                                                              |     100 |      100 |   30.76 |     100 |                   
  paths.mjs                                                                                    |     100 |      100 |       0 |     100 |                   
  root-component.mjs                                                                           |     100 |      100 |     100 |     100 |                   
 coverage-invalid-path/virtual:nuxt:/Users/simon/Documents/coverage-invalid-path/.nuxt/plugins |     100 |      100 |     100 |     100 |                   
  client.mjs                                                                                   |     100 |      100 |     100 |     100 |                   
-----------------------------------------------------------------------------------------------|---------|----------|---------|---------|-------------------

Reproduction

https://github.com/SimonSimCity/vitest-invalid-coverage-path

Run the pnpm commands pnpm install, followed by pnpm coverage.

System Info

System:
    OS: macOS 13.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Memory: 22.90 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.0/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
    pnpm: 8.5.1 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 114.0.5735.198
    Safari: 16.5
  npmPackages:
    @vitest/coverage-v8: ^0.33.0 => 0.33.0 
    vitest: ^0.33.0 => 0.33.0

Used Package Manager

npm

Validations

@AriPerkkio AriPerkkio added bug feat: coverage Issues and PRs related to the coverage feature and removed pending triage labels Jul 19, 2023
@AriPerkkio
Copy link
Member

@SimonSimCity you can set these virtual:nuxt files to be ignored in coverage for now:

import { defineVitestConfig } from "nuxt-vitest/config";
+import { coverageConfigDefaults } from "vitest/config";

export default defineVitestConfig({
  test: {
    environment: "nuxt",
+    coverage: {
+      exclude: [...coverageConfigDefaults.exclude, "**/virtual:nuxt:/**"],
+    },
  },
});

Maybe Vitest should add **/virtual:* in the exclusion pattern by default? In #3013 this similar pattern was used by Storybook (:wave: @olafurw). I have not seen this virtual: in filenames before. Is this a common convention?

@SimonSimCity
Copy link
Author

I don't know how those file paths are formed, but I found some reference in the package nuxt has:

Maybe the correct place to continue from here is to take the libraries individually..? It seems like nuxt has something like a virtual file system ...

@SimonSimCity
Copy link
Author

@AriPerkkio As I was pointed to on the Nuxt Discord: This is in fact convention by vite: https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention

I don't know whether the code actually can be made visible, but the colons in the file-name are not good. Maybe good to add this to the default config of vitest, if the code cannot be seen anyways, but could also be worth to include this in the coverage report for some modules, I don't know ...

@AriPerkkio
Copy link
Member

Thanks for looking into this @SimonSimCity. As the virtual:* pattern seems to indeed be convention of Vite's virtual modules I think we should add that pattern to coverage.exclude default values. Coverage report should contain results of source files only.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2023
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants