Skip to content

Commit 583dd8a

Browse files
authoredJul 3, 2024··
feat(vitest)!: add "vitest list" API to print collected tests without running them (#6013)
1 parent f645e48 commit 583dd8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+815
-108
lines changed
 

‎docs/advanced/pool.md

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { ProcessPool, WorkspaceProject } from 'vitest/node'
4545
export interface ProcessPool {
4646
name: string
4747
runTests: (files: [project: WorkspaceProject, testFile: string][], invalidates?: string[]) => Promise<void>
48+
collectTests: (files: [project: WorkspaceProject, testFile: string][], invalidates?: string[]) => Promise<void>
4849
close?: () => Promise<void>
4950
}
5051
```
@@ -57,6 +58,8 @@ Vitest will wait until `runTests` is executed before finishing a run (i.e., it w
5758

5859
If you are using a custom pool, you will have to provide test files and their results yourself - you can reference [`vitest.state`](https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/state.ts) for that (most important are `collectFiles` and `updateTasks`). Vitest uses `startTests` function from `@vitest/runner` package to do that.
5960

61+
Vitest will call `collectTests` if `vitest.collect` is called or `vitest list` is invoked via a CLI command. It works the same way as `runTests`, but you don't have to run test callbacks, only report their tasks by calling `vitest.state.collectFiles(files)`.
62+
6063
To communicate between different processes, you can create methods object using `createMethodsRPC` from `vitest/node`, and use any form of communication that you prefer. For example, to use WebSockets with `birpc` you can write something like this:
6164

6265
```ts

‎docs/guide/cli.md

+30
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ export default {
5555

5656
Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experimental) tests, which compare performance results.
5757

58+
### `vitest init`
59+
60+
`vitest init <name>` can be used to setup project configuration. At the moment, it only supports [`browser`](/guide/browser) value:
61+
62+
```bash
63+
vitest init browser
64+
```
65+
66+
### `vitest list`
67+
68+
`vitest list` command inherits all `vitest` options to print the list of all matching tests. This command ignores `reporters` option. By default, it will print the names of all tests that matched the file filter and name pattern:
69+
70+
```shell
71+
vitest list filename.spec.ts -t="some-test"
72+
```
73+
74+
```txt
75+
describe > some-test
76+
describe > some-test > test 1
77+
describe > some-test > test 2
78+
```
79+
80+
You can pass down `--json` flag to print tests in JSON format or save it in a separate file:
81+
82+
```bash
83+
vitest list filename.spec.ts -t="some-test" --json=./file.json
84+
```
85+
86+
If `--json` flag doesn't receive a value, it will output the JSON into stdout.
87+
5888
## Options
5989

6090
<!--@include: ./cli-table.md-->

0 commit comments

Comments
 (0)
Please sign in to comment.