Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Feb 10, 2026

Description

This PR simplifies how coverage HTML is served in UI mode and HTML reporter by introducing a new coverage.htmlDir option.

Before: Coverage HTML serving relied on complex path resolution from coverage.reportsDirectory and the html reporter's subdir option. This required reportsDirectory to be set as a subdirectory of the HTML report directory and also inconsistency between ui mode and html reporting.

After: Coverage HTML is served at a fixed ./coverage subpath relative to the UI base. The new coverage.htmlDir option is automatically inferred from html or lcov coverage reporters, and can be explicitly set for custom coverage providers. This removes the directory layout constraint and makes the integration work reliably across UI mode, HTML reporter, browser mode orchestrator html.

TODO

  • summary
  • test
  • doc

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

hi-ogawa and others added 5 commits February 10, 2026 18:01
- Use config.coverage.htmlDir in UI and browser dev servers
- Serve coverage at standardized /coverage/ path (no more basename heuristic)
- Remove resolveCoverageFolder helper functions (~70 lines)
- Serialize htmlDir to client config
- Update client to check htmlDir and use /coverage/index.html
- Remove complex path computation and TODO about subdirectory limitation

Benefits:
- Predictable coverage URL path
- Single source of truth for coverage directory
- Simplified client and server logic
- No configuration limitations

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Feb 10, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c338b2a
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/698bea7d9b79880007bc6e35
😎 Deploy Preview https://deploy-preview-9626--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa force-pushed the 02-10-chore_repro-6945 branch from ce3b606 to 07ca0c7 Compare February 11, 2026 02:25
@hi-ogawa hi-ogawa added this to the 4.1.0 milestone Feb 11, 2026
Comment on lines +1374 to +1380
// notify builtin ui and html reporter after coverage html is generated
for (const reporter of this.reporters) {
if (reporter instanceof WebSocketReporter) {
reporter.onFinishedReportCoverage()
if (
'onFinishedReportCoverage' in reporter
&& typeof reporter.onFinishedReportCoverage === 'function'
) {
await reporter.onFinishedReportCoverage()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportCoverage happens after onTestRunEnd, so now HTML reporter also needs this to be able to collect coverage html.

Copy link
Member

@sheremet-va sheremet-va Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AriPerkkio that's why I wanted onCoverage as a separate hook, by the way. We have it, but it's coupled to onTestRunEnd

@hi-ogawa hi-ogawa marked this pull request as ready for review February 11, 2026 03:18
Comment on lines +441 to +443
// infer default based on builtin reporter html output (html and lcov)
if (!resolved.coverage.htmlDir) {
const htmlReporter = resolved.coverage.reporter.find(([name]) => name === 'html')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also html-spa if we want to support that 👀

Comment on lines +397 to +405
## coverage.htmlDir

- **Type:** `string`
- **Default:** Automatically inferred from `html` or `lcov` coverage reporters
- **CLI:** `--coverage.htmlDir=<path>`

Directory of HTML coverage output to be served in [Vitest UI](/guide/ui) and [HTML reporter](/guide/reporters.html#html-reporter).

This is automatically configured when using builtin coverage reporters that produce HTML output (`html` and `lcov`). Use this option to override with a custom coverage reporting location when using custom coverage reporters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also mention here that:

Note that setting this option does not change where coverage HTML report is generated. 
Configure the `reporter` option to change the directory instead.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coverage page is broken in the html report for @vitest/ui Support for LCOV Reporter in Vitest UI to Improve Coverage Report Organization

3 participants