Skip to content

feat(experimental): support merge reports for non-sharded multi-environment runs (take 2)#10031

Open
hi-ogawa wants to merge 68 commits intovitest-dev:mainfrom
hi-ogawa:feat-merge-report-label-v2
Open

feat(experimental): support merge reports for non-sharded multi-environment runs (take 2)#10031
hi-ogawa wants to merge 68 commits intovitest-dev:mainfrom
hi-ogawa:feat-merge-report-label-v2

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Mar 31, 2026

Description

Alternative take for #9967 (comment)

This PR adds new blob reporter option label so --merge-reports can distinguish results from the same test files across different environments, such as linux/macos/windows CI jobs.

Usage example

Set VITEST_BLOB_LABEL when creating blobs:

VITEST_BLOB_LABEL=linux vitest run --reporter=blob
VITEST_BLOB_LABEL=macos vitest run --reporter=blob

Or pass the label via the blob reporter option:

// vitest.config.ts
export default defineConfig({
  test: {
    reporters: [
      ['blob', { label: process.platform }],
    ],
  },
})

The label is included in the default blob filename (blob-linux.json) to avoid collisions. When merging, each labeled run is shown separately:

$ vitest --merge-reports
 ✓  linux  src/basic.test.ts (2 tests)
 ✓  macos  src/basic.test.ts (2 tests)

How it works

The label is a blob reporter option, with VITEST_BLOB_LABEL as an environment-variable shortcut for CI usage. During config resolution, Vitest extracts the label from ['blob', { label }] or process.env.VITEST_BLOB_LABEL and stores it as internal core config (mergeReportsLabel).

During the original test run, this label is not exposed as a normal built-in reporter label. This keeps terminal output unchanged for runs that create blobs with another reporter enabled, for example reporters: ['default', ['blob', { label: 'linux' }]].

The label is stored in blob task metadata and salts the file identity used for merged reports, so state deduplication can keep same-filepath files from different environments separate. The default blob output filename also uses the label as blob-(label)-(shard).json when no explicit output file is configured.

Reporters read the label from merged blob metadata and display it when replaying --merge-reports.

The difference from #9967

Concern #9967 (label as project.name) This PR (label as blob metadata)
Mechanism Clone TestProject per label at read time Store label in blob task metadata and salt file identity
readBlobs changes Significant — label discovery, ID rewrite, env module rewrite No project cloning or read-time project rewrite
file.projectName Mutated to include label projectName unchanged
API [["blob", { label }]] reporter option or VITEST_BLOB_LABEL [["blob", { label }]] reporter option or VITEST_BLOB_LABEL (same)
Original run output Label could appear as a project-style label Built-in reporters do not show the blob label during the original run

Demo

I setup CI to upload html reports for test/cli and test/core. It's viewable on newly introduced viewer #10023.

https://viewer.vitest.dev/?url=https://github.com/vitest-dev/vitest/actions/runs/24275938517/artifacts/6383832383

image

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 hi-ogawa changed the title feat: support merge reports for non-sharded multi-environment runs (take 2) feat(experimental): support merge reports for non-sharded multi-environment runs (take 2) Apr 1, 2026
@sheremet-va
Copy link
Copy Markdown
Member

I like the approach, but I feel like meta.label might be too generic. Typecheck is a static one where users can't even modify meta, and in benchmark you don't have access to meta.

Should we make it more internal to avoid clashes with user meta? It could also be removed from json.meta: #10078

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 8, 2026

Agree meta.label can definitely crash. I'll rename it to sound like something vitest owned.

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

hi-ogawa commented Apr 8, 2026

Hash was aligned so pre-parse mode was broken. I consolidated ast-collect with the same createFileTask from runner package.

@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

We discussed that

  • receive the label via blob reporter option ['blob', { label: ... }]
  • stash this as core level internal config by extracting it during resolveConfig
  • during the original test run, this label shouldn't show up as label for builtin reporters.

@hi-ogawa hi-ogawa self-assigned this Apr 10, 2026
@hi-ogawa
Copy link
Copy Markdown
Collaborator Author

The PR is updated with blob reporter level option. I've also revived VITEST_BLOB_LABEL environment support so it can one shot from CLI VITEST_BLOB_LABEL=linux vitest --reporter=blob.

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.

Support merging reports for non-sharded multi-environment runs

3 participants