-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Describe the bug
When using the 'html' reporter for vitest, with the html coverage reporter also enabled, the UI contains a button to load the coverage report in an iframe, but the iframe fails to load because it is loaded from '/coverage/index.html'.
There are really two problems here.
- By iframing in the url starting with a
/the browser will attempt to loadhttp://my-host.io/coverage/index.htmlregardless of the url route your report is served from. Instead, it might be preferrable to use a relative path:http://my-host.io/report/12345/coverage/index.htmletc. - With the default configured options, the two reports are generated in separate directories:
./coverageand./htmlThis makes it harder to bundle all the report artifacts because they are in separate places.
Regarding #2 it would be nice if the html report directory was automatically copied into the vitest html report directory and just referenced via a relative url if the html coverage reporter is enabled. That would solve both issues at once for me without requiring extra configuration. That is my ideal fix, but I can also see the following being useful:
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['lcov', 'text-summary', ['html', {subdir: '../vitest-report/coverage'}]],
},
reporters: [['html', {outputFile: './vitest-report/index.html'}]],
},
});
The above configuration correctly places the html coverage directory inside of the vitest html report directory, but the paths are not resolved correctly still, Additional work would be needed to support this:

Related Issue: #6144
The above issue appears related in that they are trying to ultimately solve the same problem of the coverage not working depending on how the page is accessed or hosted, but I think the problems are deeper than what is described in the linked issue, so I created this new issue to track fixing some of those fundamental issues as at that point configuring the url to point to an externally hosted service is an orthogonal concern.
Reproduction
Use the following vitest config on a project:
import {defineConfig} from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['html'],
},
reporters: ['html'],
},
});Execute:
npx vitest runFollow the instructions for previewing the test results:
npx vite preview --outDir htmlObserve that the coverage page fails to load.
System Info
System:
OS: Windows 11 10.0.22631
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12800H
Memory: 10.12 GB / 31.64 GB
Binaries:
Node: 22.11.0 - ~\AppData\Local\fnm_multishells\20364_1732206955982\node.EXE
Yarn: 4.5.1 - ~\AppData\Local\fnm_multishells\20364_1732206955982\yarn.CMD
npm: 10.9.0 - ~\AppData\Local\fnm_multishells\20364_1732206955982\npm.CMD
bun: 1.1.29 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
npmPackages:
@vitejs/plugin-vue: ^5.1.4 => 5.1.4
@vitest/coverage-v8: ^2.1.2 => 2.1.3
@vitest/ui: 2.1.3 => 2.1.3
vite: ^5.4.8 => 5.4.10
vitest: ^2.1.2 => 2.1.3Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Sub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
