Skip to content

Coverage page is broken in the html report for @vitest/ui #6945

@thebanjomatic

Description

@thebanjomatic

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.

  1. By iframing in the url starting with a / the browser will attempt to load http://my-host.io/coverage/index.html regardless 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.html etc.
  2. With the default configured options, the two reports are generated in separate directories: ./coverage and ./html This 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:
image

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 run

Follow the instructions for previewing the test results:

npx vite preview --outDir html

Click the coverage button:
image

Observe 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.3

Used Package Manager

yarn

Validations

Sub-issues

Metadata

Metadata

Assignees

Labels

feat: uiVitest UIp3-minor-bugAn edge case that only affects very specific usage (priority)

Type

Projects

Status

Approved

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions