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 fails to generate if using a custom json reporter file #480

Closed
4 tasks done
BenShelton opened this issue Sep 30, 2024 · 0 comments · Fixed by #481
Closed
4 tasks done

Coverage fails to generate if using a custom json reporter file #480

BenShelton opened this issue Sep 30, 2024 · 0 comments · Fixed by #481

Comments

@BenShelton
Copy link
Contributor

Describe the bug

If a custom file is specified for the json reporter then the output is not able to be read as the report reader is looking specifically for a file called coverage-final.json. This causes an error to be thrown.

Reproduction

Add the following to the test section of any vitest.config.ts in one of the samples (I used the basic one for the output below)

coverage: {
  reporter: [
    ['json', { file: 'coverage-custom.json' }],
  ]
}

Output

[INFO 14:30:43] [v1.2.12] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 14:30:43] [API] Running Vitest v1.4.0 (basic/vitest.config.ts) with Node.js@v20.15.1: /Users/benshelton/.nvm/versions/node/v20.15.1/bin/node 
[INFO 14:30:43] [Worker] Starting inspector on 127.0.0.1:53087 failed: address already in use
[INFO 14:30:44] [API] Vitest v1.4.0 (basic/vitest.config.ts) process 38352 created
[INFO 14:30:57] [Worker] Running coverage with configuration: {
  provider: 'v8',
  enabled: true,
  all: true,
  clean: true,
  cleanOnRerun: true,
  reportsDirectory: '/var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788',
  exclude: [
    'coverage/**',
    'dist/**',
    '**/[.]**',
    'packages/*/test?(s)/**',
    '**/*.d.ts',
    '**/virtual:*',
    '**/__x00__*',
    '**/\x00*',
    'cypress/**',
    'test?(s)/**',
    'test?(-*).?(c|m)[jt]s?(x)',
    '**/*{.,-}{test,spec}.?(c|m)[jt]s?(x)',
    '**/__tests__/**',
    '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
    '**/vitest.{workspace,projects}.[jt]s?(on)',
    '**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}'
  ],
  reportOnFailure: true,
  reporter: [ [ 'json', [Object] ] ],
  extension: [
    '.js',    '.cjs',
    '.mjs',   '.ts',
    '.mts',   '.cts',
    '.tsx',   '.jsx',
    '.vue',   '.svelte',
    '.marko'
  ],
  allowExternal: false,
  processingConcurrency: 10
}
[INFO 14:30:57] Running 1 file(s): src/should_included_test.ts
[14:30:57] The runner is starting because tests ***/vscode/samples/basic/src/should_included_test.ts were started due to a file change
[14:30:57] Enqueuing "should_included_test.ts"
[14:30:57] No task result for "is included because of workspace plugin setting", assuming the test just started running
[14:30:57] Marking "is included because of workspace plugin setting" as passed
[INFO 14:30:57] [Worker] Waiting for the coverage report to generate: /var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788
[INFO 14:30:57] [Worker] Coverage reports retrieved: /var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788
[14:30:57] Ending test run src/should_included_test.ts
[14:30:57] Coverage was disabled due to all requests being exhausted
[Error 14:30:57] [Error Error] Could not read coverage-final.json in /var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788. Make sure the test was run with "json" coverage enabled: Error: ENOENT: no such file or directory, open '/var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788/coverage-final.json'
Error: Could not read coverage-final.json in /var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788. Make sure the test was run with "json" coverage enabled: Error: ENOENT: no such file or directory, open '/var/folders/cz/xhwb1xys7v335hr7pzhssrx00000gn/T/vitest-coverage-fba48b1b-0317-4a1c-92b5-6d615c7f3788/coverage-final.json'
    at readCoverageReport (***/vscode/src/coverage.ts:14:11)
    at TestRunner.reportCoverage (***/vscode/src/runner/runner.ts:360:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ***/vscode/src/runner/runner.ts:109:11

Version

1.2.12

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant