Skip to content

Commit 69ca425

Browse files
authored
fix(reporter): print test only once in the verbose mode (#7738)
1 parent b166efa commit 69ca425

File tree

14 files changed

+352
-166
lines changed

14 files changed

+352
-166
lines changed

docs/advanced/api/test-case.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Checks if the test did not fail the suite. If the test is not finished yet or wa
125125
function meta(): TaskMeta
126126
```
127127

128-
Custom metadata that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run:
128+
Custom [metadata](/advanced/metadata) that was attached to the test during its execution. The meta can be attached by assigning a property to the `ctx.task.meta` object during a test run:
129129

130130
```ts {3,6}
131131
import { test } from 'vitest'

docs/advanced/api/test-module.md

+32
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,33 @@ function state(): TestModuleState
3232

3333
Works the same way as [`testSuite.state()`](/advanced/api/test-suite#state), but can also return `queued` if module wasn't executed yet.
3434

35+
## meta <Version>3.1.0</Version> {#meta}
36+
37+
```ts
38+
function meta(): TaskMeta
39+
```
40+
41+
Custom [metadata](/advanced/metadata) that was attached to the module during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run:
42+
43+
```ts {5,10}
44+
import { test } from 'vitest'
45+
46+
describe('the validation works correctly', (task) => {
47+
// assign "decorated" during collection
48+
task.file.meta.decorated = false
49+
50+
test('some test', ({ task }) => {
51+
// assign "decorated" during test run, it will be available
52+
// only in onTestCaseReady hook
53+
task.file.meta.decorated = false
54+
})
55+
})
56+
```
57+
58+
:::tip
59+
If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter.
60+
:::
61+
3562
## diagnostic
3663

3764
```ts
@@ -63,5 +90,10 @@ interface ModuleDiagnostic {
6390
* Accumulated duration of all tests and hooks in the module.
6491
*/
6592
readonly duration: number
93+
/**
94+
* The amount of memory used by the module in bytes.
95+
* This value is only available if the test was executed with `logHeapUsage` flag.
96+
*/
97+
readonly heap: number | undefined
6698
}
6799
```

docs/advanced/api/test-suite.md

+27
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,30 @@ describe('collection failed', () => {
190190
::: warning
191191
Note that errors are serialized into simple objects: `instanceof Error` will always return `false`.
192192
:::
193+
194+
## meta <Version>3.1.0</Version> {#meta}
195+
196+
```ts
197+
function meta(): TaskMeta
198+
```
199+
200+
Custom [metadata](/advanced/metadata) that was attached to the suite during its execution or collection. The meta can be attached by assigning a property to the `task.meta` object during a test run:
201+
202+
```ts {5,10}
203+
import { test } from 'vitest'
204+
205+
describe('the validation works correctly', (task) => {
206+
// assign "decorated" during collection
207+
task.meta.decorated = false
208+
209+
test('some test', ({ task }) => {
210+
// assign "decorated" during test run, it will be available
211+
// only in onTestCaseReady hook
212+
task.suite.meta.decorated = false
213+
})
214+
})
215+
```
216+
217+
:::tip
218+
If metadata was attached during collection (outside of the `test` function), then it will be available in [`onTestModuleCollected`](./reporters#ontestmodulecollected) hook in the custom reporter.
219+
:::

packages/vitest/src/node/core.ts

+24-19
Original file line numberDiff line numberDiff line change
@@ -502,25 +502,7 @@ export class Vitest {
502502
await this._testRun.start(specifications).catch(noop)
503503

504504
for (const file of files) {
505-
const project = this.getProjectByName(file.projectName || '')
506-
await this._testRun.enqueued(project, file).catch(noop)
507-
await this._testRun.collected(project, [file]).catch(noop)
508-
509-
const logs: UserConsoleLog[] = []
510-
511-
const { packs, events } = convertTasksToEvents(file, (task) => {
512-
if (task.logs) {
513-
logs.push(...task.logs)
514-
}
515-
})
516-
517-
logs.sort((log1, log2) => log1.time - log2.time)
518-
519-
for (const log of logs) {
520-
await this._testRun.log(log).catch(noop)
521-
}
522-
523-
await this._testRun.updated(packs, events).catch(noop)
505+
await this._reportFileTask(file)
524506
}
525507

526508
if (hasFailed(files)) {
@@ -538,6 +520,29 @@ export class Vitest {
538520
}
539521
}
540522

523+
/** @internal */
524+
public async _reportFileTask(file: File): Promise<void> {
525+
const project = this.getProjectByName(file.projectName || '')
526+
await this._testRun.enqueued(project, file).catch(noop)
527+
await this._testRun.collected(project, [file]).catch(noop)
528+
529+
const logs: UserConsoleLog[] = []
530+
531+
const { packs, events } = convertTasksToEvents(file, (task) => {
532+
if (task.logs) {
533+
logs.push(...task.logs)
534+
}
535+
})
536+
537+
logs.sort((log1, log2) => log1.time - log2.time)
538+
539+
for (const log of logs) {
540+
await this._testRun.log(log).catch(noop)
541+
}
542+
543+
await this._testRun.updated(packs, events).catch(noop)
544+
}
545+
541546
async collect(filters?: string[]): Promise<TestRunResult> {
542547
const files = await this.specifications.getRelevantTestSpecifications(filters)
543548

0 commit comments

Comments
 (0)