Skip to content

Commit d22b029

Browse files
authored
fix(reporters)!: blob reporter and --merge-reports default to .vitest/blob/ (#10232)
1 parent e60b2f4 commit d22b029

14 files changed

Lines changed: 72 additions & 75 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ jobs:
135135
- uses: actions/upload-artifact@v7
136136
if: ${{ !cancelled() }}
137137
with:
138-
name: vitest-blob-${{ matrix.os }}-node-${{ matrix.node_version }}
138+
name: vitest-results-${{ matrix.os }}-node-${{ matrix.node_version }}
139139
path: |
140140
README.md
141-
test/unit/.vitest-reports
142-
test/e2e/.vitest-reports
141+
test/unit/.vitest
142+
test/e2e/.vitest
143143
retention-days: 1
144144
include-hidden-files: true
145145

@@ -284,7 +284,7 @@ jobs:
284284

285285
- uses: actions/download-artifact@v4
286286
with:
287-
pattern: vitest-blob-*
287+
pattern: vitest-results-*
288288
merge-multiple: true
289289

290290
- name: Merge reports

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ test/**/__screenshots__/**/*
2828
test/**/__traces__/**/*
2929
test/browser/fixtures/update-snapshot/basic.test.ts
3030
test/e2e/fixtures/browser-multiple/basic-*
31-
.vitest-reports
3231
*.tsbuildinfo
3332
# exclude static html reporter folder
3433
test/browser/html/

docs/api/advanced/vitest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ This method can be slow because it needs to filter `--changed` flags. Do not use
202202
function mergeReports(directory?: string): Promise<TestRunResult>
203203
```
204204

205-
Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified). This value can also be set on `config.mergeReports` (by default, it will read `.vitest-reports` folder).
205+
Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified). This value can also be set on `config.mergeReports` (by default, it will read `.vitest/blob/` folder).
206206

207207
Note that the `directory` will always be resolved relative to the working directory.
208208

docs/guide/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ If `--reporter=blob` is used without an output file, the default path will inclu
232232

233233
- **Type:** `boolean | string`
234234

235-
Merges every blob report located in the specified folder (`.vitest-reports` by default). You can use any reporters with this command (except [`blob`](/guide/reporters#blob-reporter)):
235+
Merges every blob report located in the specified folder (`.vitest/blob/` by default). You can use any reporters with this command (except [`blob`](/guide/reporters#blob-reporter)):
236236

237237
```sh
238238
vitest --merge-reports --reporter=junit

docs/guide/improving-performance.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ vitest run --reporter=blob --shard=3/3 # 3rd machine
126126

127127
> Vitest splits your _test files_, not your test cases, into shards. If you've got 1000 test files, the `--shard=1/4` option will run 250 test files, no matter how many test cases individual files have.
128128
129-
Collect the results stored in `.vitest-reports` directory from each machine and merge them with [`--merge-reports`](/guide/cli#merge-reports) option:
129+
Collect the results stored in `.vitest/blob/` directory from each machine and merge them with [`--merge-reports`](/guide/cli#merge-reports) option:
130130

131131
```sh
132132
vitest run --merge-reports
@@ -173,21 +173,12 @@ jobs:
173173
env:
174174
VITEST_BLOB_LABEL: ${{ matrix.os }}
175175

176-
- name: Upload blob report to GitHub Actions Artifacts
176+
- name: Upload Vitest results GitHub Actions Artifacts
177177
if: ${{ !cancelled() }}
178178
uses: actions/upload-artifact@v4
179179
with:
180-
name: blob-report-${{ matrix.os }}-${{ matrix.shardIndex }}
181-
path: .vitest-reports/*
182-
include-hidden-files: true
183-
retention-days: 1
184-
185-
- name: Upload attachments to GitHub Actions Artifacts
186-
if: ${{ !cancelled() }}
187-
uses: actions/upload-artifact@v4
188-
with:
189-
name: blob-attachments-${{ matrix.os }}-${{ matrix.shardIndex }}
190-
path: .vitest/**
180+
name: vitest-results-${{ matrix.os }}-${{ matrix.shardIndex }}
181+
path: .vitest
191182
include-hidden-files: true
192183
retention-days: 1
193184

@@ -208,18 +199,10 @@ jobs:
208199
- name: Install dependencies
209200
run: pnpm i
210201

211-
- name: Download blob reports from GitHub Actions Artifacts
212-
uses: actions/download-artifact@v4
213-
with:
214-
path: .vitest-reports
215-
pattern: blob-report-*
216-
merge-multiple: true
217-
218-
- name: Download attachments from GitHub Actions Artifacts
202+
- name: Download Vitest results from GitHub Actions Artifacts
219203
uses: actions/download-artifact@v4
220204
with:
221205
path: .vitest
222-
pattern: blob-attachments-*
223206
merge-multiple: true
224207

225208
- name: Merge reports

docs/guide/reporters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export default defineConfig({
742742
### Blob Reporter
743743

744744
Stores test results on the machine so they can be later merged using [`--merge-reports`](/guide/cli#merge-reports) command.
745-
By default, stores all results in `.vitest-reports` folder, but can be overridden with `--outputFile` or `--outputFile.blob` flags.
745+
By default, stores all results in `.vitest/blob/` folder, but can be overridden with `--outputFile` or `--outputFile.blob` flags.
746746

747747
```bash
748748
npx vitest --reporter=blob --outputFile=reports/blob-1.json

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
855855
argument: '[path]',
856856
transform(value) {
857857
if (!value || typeof value === 'boolean') {
858-
return '.vitest-reports'
858+
return '.vitest/blob'
859859
}
860860
return value
861861
},

packages/vitest/src/node/reporters/blob.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ export class BlobReporter implements Reporter {
4848
const errors = [...unhandledErrors]
4949
const coverage = this.coverage
5050

51-
let outputFile
52-
= this.options.outputFile ?? getOutputFile(this.ctx.config, 'blob')
53-
if (!outputFile) {
54-
const shard = this.ctx.config.shard
55-
const filename = [
56-
'blob',
57-
this.ctx.config.mergeReportsLabel,
58-
shard && `${shard.index}-${shard.count}`,
59-
].filter(Boolean).join('-')
60-
outputFile = `.vitest-reports/${sanitizeFilePath(filename)}.json`
61-
}
62-
6351
const environmentModules: MergeReportEnvironmentModules = {}
6452
this.ctx.projects.forEach((project) => {
6553
const serializedProject: MergeReportEnvironmentModules[string] = {
@@ -87,31 +75,45 @@ export class BlobReporter implements Reporter {
8775
environmentModules[project.name] = serializedProject
8876
})
8977

90-
const report = [
78+
const content = stringify([
9179
this.ctx.version,
9280
files,
9381
errors,
9482
coverage,
9583
executionTime,
9684
environmentModules,
97-
] satisfies MergeReport
85+
] satisfies MergeReport)
9886

99-
const reportFile = resolve(this.ctx.config.root, outputFile)
100-
await writeBlob(report, reportFile)
87+
let outputFile = this.options.outputFile ?? getOutputFile(this.ctx.config, 'blob')
10188

102-
this.ctx.logger.log('blob report written to', reportFile)
103-
}
104-
}
89+
if (outputFile) {
90+
outputFile = resolve(this.ctx.config.root, outputFile)
10591

106-
export async function writeBlob(content: MergeReport, filename: string): Promise<void> {
107-
const report = stringify(content)
92+
const dir = dirname(outputFile)
93+
if (!existsSync(dir)) {
94+
await mkdir(dir, { recursive: true })
95+
}
10896

109-
const dir = dirname(filename)
110-
if (!existsSync(dir)) {
111-
await mkdir(dir, { recursive: true })
112-
}
97+
await writeFile(outputFile, content, 'utf-8')
98+
}
99+
else {
100+
const report = this.ctx.createReport('blob')
101+
102+
const shard = this.ctx.config.shard
103+
outputFile = [
104+
'blob',
105+
this.ctx.config.mergeReportsLabel,
106+
shard ? `-${shard.index}-${shard.count}` : '',
107+
].join('')
113108

114-
await writeFile(filename, report, 'utf-8')
109+
outputFile = `${sanitizeFilePath(outputFile)}.json`
110+
111+
await report.writeFile(outputFile, content, 'utf-8')
112+
outputFile = resolve(report.root, outputFile)
113+
}
114+
115+
this.ctx.logger.log('blob report written to', outputFile)
116+
}
115117
}
116118

117119
export async function readBlobs(
@@ -223,7 +225,7 @@ export interface MergedBlobs {
223225
executionTimes: number[]
224226
}
225227

226-
type MergeReport = [
228+
export type MergeReport = [
227229
vitestVersion: string,
228230
files: File[],
229231
errors: unknown[],

packages/vitest/src/node/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ export interface UserConfig extends InlineConfig {
11021102

11031103
/**
11041104
* Directory of blob reports to merge
1105-
* @default '.vitest-reports'
1105+
* @default '.vitest/blob'
11061106
*/
11071107
mergeReports?: string
11081108

test/config/test/failures.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ test('nextTick can be mocked inside worker_threads', async () => {
379379
})
380380

381381
test('mergeReports doesn\'t work with watch mode enabled', async () => {
382-
const { stderr } = await runVitest({ watch: true, mergeReports: '.vitest-reports' })
382+
const { stderr } = await runVitest({ watch: true, mergeReports: '.vitest/blob' })
383383

384384
expect(stderr).toMatch('Cannot merge reports with --watch enabled')
385385
})

0 commit comments

Comments
 (0)