Skip to content

Commit 25fd32b

Browse files
fix!: verbose reporter prints tests in a list, introduce tree reporter (#8500)
Co-authored-by: Ari Perkkiö <[email protected]>
1 parent 965cefc commit 25fd32b

File tree

19 files changed

+524
-273
lines changed

19 files changed

+524
-273
lines changed

docs/advanced/reporters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class MyReporter implements Reporter {
9393
6. `JUnitReporter`
9494
7. `TapFlatReporter`
9595
8. `HangingProcessReporter`
96+
9. `TreeReporter`
9697

9798
### Base Abstract reporters:
9899

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Hide logs for skipped tests
8989
- **CLI:** `--reporter <name>`
9090
- **Config:** [reporters](/config/#reporters)
9191

92-
Specify reporters (default, blob, verbose, dot, json, tap, tap-flat, junit, hanging-process, github-actions)
92+
Specify reporters (default, blob, verbose, dot, json, tap, tap-flat, junit, tree, hanging-process, github-actions)
9393

9494
### outputFile
9595

docs/guide/migration.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@ outline: deep
77

88
## Migrating to Vitest 4.0 {#vitest-4}
99

10-
### Removed `reporters: 'basic'`
11-
12-
Basic reporter is removed as it is equal to:
13-
14-
```ts
15-
export default defineConfig({
16-
test: {
17-
reporters: [
18-
['default', { summary: false }]
19-
]
20-
}
21-
})
22-
```
23-
2410
### V8 Code Coverage Major Changes
2511

2612
Vitest's V8 code coverage provider is now using more accurate coverage result remapping logic.
@@ -260,13 +246,39 @@ export default defineConfig({
260246

261247
The naming of properties in `playwright` factory now also aligns with [Playwright documentation](https://playwright.dev/docs/api/class-testoptions#test-options-launch-options) making it easier to find.
262248

249+
### Reporter Updates
250+
251+
Reporter APIs `onCollected`, `onSpecsCollected`, `onPathsCollected`, `onTaskUpdate` and `onFinished` were removed. See [`Reporters API`](/advanced/api/reporters) for new alternatives. The new APIs were introduced in Vitest `v3.0.0`.
252+
253+
The `basic` reporter was removed as it is equal to:
254+
255+
```ts
256+
export default defineConfig({
257+
test: {
258+
reporters: [
259+
['default', { summary: false }]
260+
]
261+
}
262+
})
263+
```
264+
265+
The [`verbose`](/guide/reporters#verbose-reporter) reporter now prints test cases as a flat list. To revert to the previous behaviour, use `--reporter=tree`:
266+
267+
```ts
268+
export default defineConfig({
269+
test: {
270+
reporters: ['verbose'], // [!code --]
271+
reporters: ['tree'], // [!code ++]
272+
}
273+
})
274+
```
275+
263276
### Deprecated APIs are Removed
264277

265278
Vitest 4.0 removes some deprecated APIs, including:
266279

267280
- `poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
268281
- `environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
269-
- Reporter APIs `onCollected`, `onSpecsCollected`, `onPathsCollected`, `onTaskUpdate` and `onFinished`. See [`Reporters API`](/advanced/api/reporters) for new alternatives. These APIs were introduced in Vitest `v3.0.0`.
270282
- `deps.external`, `deps.inline`, `deps.fallbackCJS` config options. Use `server.deps.external`, `server.deps.inline`, or `server.deps.fallbackCJS` instead.
271283
- `browser.testerScripts` config option. Use [`browser.testerHtmlPath`](/guide/browser/config#browser-testerhtmlpath) instead.
272284
- `minWorkers` config option. Only `maxWorkers` has any effect on how tests are running, so we are removing this public option.

docs/guide/reporters.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,27 @@ Final output after tests have finished:
141141
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
142142
```
143143

144+
If there is only one test file running, Vitest will output the full test tree of that file, simillar to the [`tree`](#tree-reporter) reporter. The default reporter will also print the test tree if there is at least one failed test in the file.
145+
146+
```bash
147+
✓ __tests__/file1.test.ts (2) 725ms
148+
✓ first test file (2) 725ms
149+
✓ 2 + 2 should equal 4
150+
✓ 4 - 2 should equal 2
151+
152+
Test Files 1 passed (1)
153+
Tests 2 passed (2)
154+
Start at 12:34:32
155+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
156+
```
157+
144158
### Verbose Reporter
145159

146-
Verbose reporter is same as `default` reporter, but it also displays each individual test after the suite has finished. It also displays currently running tests that are taking longer than [`slowTestThreshold`](/config/#slowtestthreshold). Similar to `default` reporter, you can disable the summary by configuring the reporter.
160+
The verbose reporter prints every test case once it is finished. It does not report suites or files separately. If `--includeTaskLocation` is enabled, it will also include the location of each test in the output. Similar to `default` reporter, you can disable the summary by configuring the reporter.
161+
162+
In addition to this, the `verbose` reporter prints test error messages right away. The full test error is reported when the test run is finished.
163+
164+
This is the only terminal reporter that reports [annotations](/guide/test-annotations) when the test doesn't fail.
147165

148166
:::code-group
149167
```bash [CLI]
@@ -161,6 +179,54 @@ export default defineConfig({
161179
```
162180
:::
163181

182+
Example output:
183+
184+
```bash
185+
✓ __tests__/file1.test.ts > first test file > 2 + 2 should equal 4 1ms
186+
✓ __tests__/file1.test.ts > first test file > 4 - 2 should equal 2 1ms
187+
✓ __tests__/file2.test.ts > second test file > 1 + 1 should equal 2 1ms
188+
✓ __tests__/file2.test.ts > second test file > 2 - 1 should equal 1 1ms
189+
190+
Test Files 2 passed (2)
191+
Tests 4 passed (4)
192+
Start at 12:34:32
193+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
194+
```
195+
196+
An example with `--includeTaskLocation`:
197+
198+
```bash
199+
✓ __tests__/file1.test.ts:2:1 > first test file > 2 + 2 should equal 4 1ms
200+
✓ __tests__/file1.test.ts:3:1 > first test file > 4 - 2 should equal 2 1ms
201+
✓ __tests__/file2.test.ts:2:1 > second test file > 1 + 1 should equal 2 1ms
202+
✓ __tests__/file2.test.ts:3:1 > second test file > 2 - 1 should equal 1 1ms
203+
204+
Test Files 2 passed (2)
205+
Tests 4 passed (4)
206+
Start at 12:34:32
207+
Duration 1.26s (transform 35ms, setup 1ms, collect 90ms, tests 1.47s, environment 0ms, prepare 267ms)
208+
```
209+
210+
### Tree Reporter
211+
212+
The tree reporter is same as `default` reporter, but it also displays each individual test after the suite has finished. Similar to `default` reporter, you can disable the summary by configuring the reporter.
213+
214+
:::code-group
215+
```bash [CLI]
216+
npx vitest --reporter=tree
217+
```
218+
219+
```ts [vitest.config.ts]
220+
export default defineConfig({
221+
test: {
222+
reporters: [
223+
['tree', { summary: false }]
224+
]
225+
},
226+
})
227+
```
228+
:::
229+
164230
Example output for tests in progress with default `slowTestThreshold: 300`:
165231

166232
```bash

docs/guide/test-annotations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Error: thrown error
5353

5454
### verbose
5555

56-
In a TTY terminal, the `verbose` reporter works similarly to the `default` reporter. However, in a non-TTY environment, the `verbose` reporter will also print annotations after every test.
56+
The `verbose` reporter is the only terminal reporter that reports annotations when the test doesn't fail.
5757

5858
```
5959
✓ example.test.js > an example of a test with annotation

0 commit comments

Comments
 (0)