Skip to content

Commit 9936c09

Browse files
authored
docs: update workspace.md (#6664)
1 parent 5c73ebe commit 9936c09

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

docs/guide/workspace.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ Vitest provides built-in support for monorepos through a workspace configuration
1414

1515
## Defining a Workspace
1616

17-
A workspace should have a `vitest.workspace` or `vitest.projects` file in its root (in the same folder as your config file if you have one). Vitest supports `ts`/`js`/`json` extensions for this file.
17+
A workspace must include a `vitest.workspace` or `vitest.projects` file in its root directory (located in the same folder as your root configuration file, if applicable). Vitest supports `ts`, `js`, and `json` extensions for this file.
1818

19-
Workspace configuration file should have a default export with a list of files or glob patterns referencing your projects. For example, if you have a folder named `packages` that contains your projects, you can define a workspace with this config file:
19+
::: tip NAMING
20+
Please note that this feature is named `workspace`, not `workspaces` (without an "s" at the end).
21+
:::
22+
23+
Workspace configuration file must have a default export with a list of files or glob patterns referencing your projects. For example, if you have a folder named `packages` that contains your projects, you can define a workspace with this config file:
2024

2125
:::code-group
2226
```ts [vitest.workspace.ts]
@@ -26,10 +30,10 @@ export default [
2630
```
2731
:::
2832

29-
Vitest will consider every folder in `packages` as a separate project even if it doesn't have a config file inside. Since Vitest 2.1, if this glob pattern matches any file it will be considered a Vitest config even if it doesn't have a `vitest` in its name.
33+
Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. Since Vitest 2.1, if this glob pattern matches any file it will be considered a Vitest config even if it doesn't have a `vitest` in its name.
3034

3135
::: warning
32-
Vitest will not consider the root config as a workspace project (so it will not run tests specified in `include`) unless it is specified in this config.
36+
Vitest does not treat the root `vitest.config` file as a workspace project unless it is explicitly specified in the workspace configuration. Consequently, the root configuration will only influence global options such as `reporters` and `coverage`.
3337
:::
3438

3539
You can also reference projects with their config files:
@@ -42,9 +46,9 @@ export default [
4246
```
4347
:::
4448

45-
This pattern will only include projects with `vitest.config` file that includes `e2e` and `unit` before the extension.
49+
This pattern will only include projects with a `vitest.config` file that contains `e2e` or `unit` before the extension.
4650

47-
You can also define projects with inline config. Workspace file supports using both syntaxes at the same time.
51+
You can also define projects using inline configuration. The workspace file supports both syntaxes simultaneously.
4852

4953
:::code-group
5054
```ts [vitest.workspace.ts]
@@ -76,10 +80,10 @@ export default defineWorkspace([
7680
:::
7781

7882
::: warning
79-
All projects should have unique names. Otherwise, Vitest will throw an error. If you do not provide a name inside the inline config, Vitest will assign a number. If you don't provide a name inside a project config defined with glob syntax, Vitest will use the directory name by default.
83+
All projects must have unique names; otherwise, Vitest will throw an error. If a name is not provided in the inline configuration, Vitest will assign a number. For project configurations defined with glob syntax, Vitest will default to using the "name" property in the nearest `package.json` file or the folder name if no such file exists.
8084
:::
8185

82-
If you don't rely on inline configs, you can just create a small json file in your root directory:
86+
If you do not use inline configurations, you can create a small JSON file in your root directory:
8387

8488
:::code-group
8589
```json [vitest.workspace.json]
@@ -89,7 +93,7 @@ If you don't rely on inline configs, you can just create a small json file in yo
8993
```
9094
:::
9195

92-
Workspace projects don't support all configuration properties. For better type safety, use `defineProject` instead of `defineConfig` method inside project configuration files:
96+
Workspace projects do not support all configuration properties. For better type safety, use the `defineProject` method instead of `defineConfig` within project configuration files:
9397

9498
:::code-group
9599
```ts [packages/a/vitest.config.ts] twoslash
@@ -191,9 +195,10 @@ export default mergeConfig(
191195
```
192196
:::
193197

194-
At the `defineWorkspace` level you can also use the `extends` option instead to inherit from your root-level config.
198+
At the `defineWorkspace` level, you can use the `extends` option to inherit from your root-level configuration. All options will be merged.
199+
195200
::: code-group
196-
```ts [packages/a/vitest.config.ts]
201+
```ts [vitest.workspace.ts]
197202
import { defineWorkspace } from 'vitest/config'
198203

199204
export default defineWorkspace([
@@ -215,17 +220,13 @@ export default defineWorkspace([
215220
```
216221
:::
217222

218-
Also, some of the configuration options are not allowed in a project config. Most notably:
223+
Some of the configuration options are not allowed in a project config. Most notably:
219224

220225
- `coverage`: coverage is done for the whole workspace
221226
- `reporters`: only root-level reporters can be supported
222227
- `resolveSnapshotPath`: only root-level resolver is respected
223228
- all other options that don't affect test runners
224229

225230
::: tip
226-
All configuration options that are not supported inside a project config have <NonProjectOption /> sign next them in ["Config"](/config/) page.
231+
All configuration options that are not supported inside a project configuration are marked with a <NonProjectOption /> sign in the ["Config"](/config/) guide.
227232
:::
228-
229-
## Coverage
230-
231-
Coverage for workspace projects works out of the box.

0 commit comments

Comments
 (0)