You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/config/index.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -2437,12 +2437,14 @@ Tells fake timers to clear "native" (i.e. not fake) timers by delegating to thei
2437
2437
2438
2438
### workspace<NonProjectOption /> {#workspace}
2439
2439
2440
-
-**Type:**`string`
2440
+
-**Type:**`string | TestProjectConfiguration`
2441
2441
-**CLI:**`--workspace=./file.js`
2442
2442
-**Default:**`vitest.{workspace,projects}.{js,ts,json}` close to the config file or root
2443
2443
2444
2444
Path to a [workspace](/guide/workspace) config file relative to [root](#root).
2445
2445
2446
+
Since Vitest 2.2, you can also define the workspace array in the root config. If the `workspace` is defined in the config manually, Vitest will ignore the `vitest.workspace` file in the root.
Copy file name to clipboardexpand all lines: docs/guide/workspace.md
+92-4
Original file line number
Diff line number
Diff line change
@@ -14,20 +14,31 @@ Vitest provides a way to define multiple project configurations within a single
14
14
15
15
## Defining a Workspace
16
16
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 or working directory if it doesn't exist). Vitest supports `ts`, `js`, and `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 or working directory if it doesn't exist). Note that `projects` is just an alias and does not change the behavior or semantics of this feature. Vitest supports `ts`, `js`, and `json` extensions for this file.
18
+
19
+
Since Vitest 2.2, you can also define a workspace in the root config. In this case, Vitest will ignore the `vitest.workspace` file in the root, if one exists.
18
20
19
21
::: tip NAMING
20
22
Please note that this feature is named `workspace`, not `workspaces` (without an "s" at the end).
21
23
:::
22
24
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:
25
+
A workspace is a list of inlined configs, files, or glob patterns referencing your projects. For example, if you have a folder named `packages` that contains your projects, you can either create a workspace file or define an array in the root config:
24
26
25
27
:::code-group
26
28
```ts [vitest.workspace.ts]
27
29
exportdefault [
28
30
'packages/*'
29
31
]
30
32
```
33
+
```ts [vitest.config.ts <Version>2.2.0</Version>]
34
+
import { defineConfig } from'vitest/config'
35
+
36
+
exportdefaultdefineConfig({
37
+
test: {
38
+
workspace: ['packages/*'],
39
+
},
40
+
})
41
+
```
31
42
:::
32
43
33
44
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.
// matches every folder and file inside the `packages` folder
107
+
'packages/*',
108
+
{
109
+
// add "extends: true" to inherit the options from the root config
110
+
extends: true,
111
+
test: {
112
+
include: ['tests/**/*.{browser}.test.{ts,js}'],
113
+
// it is recommended to define a name when using inline configs
114
+
name: 'happy-dom',
115
+
environment: 'happy-dom',
116
+
}
117
+
},
118
+
{
119
+
test: {
120
+
include: ['tests/**/*.{node}.test.{ts,js}'],
121
+
name: 'node',
122
+
environment: 'node',
123
+
}
124
+
}
125
+
]
126
+
}
127
+
})
128
+
```
80
129
:::
81
130
82
131
::: warning
83
132
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, if none exists, the folder name.
84
133
:::
85
134
86
-
If you do not use inline configurations, you can create a small JSON file in your root directory:
135
+
If you do not use inline configurations, you can create a small JSON file in your root directory or just specify it in the root config:
87
136
88
137
:::code-group
89
138
```json [vitest.workspace.json]
90
139
[
91
140
"packages/*"
92
141
]
93
142
```
143
+
```ts [vitest.config.ts <Version>2.2.0</Version>]
144
+
import { defineConfig } from'vitest/config'
145
+
146
+
exportdefaultdefineConfig({
147
+
test: {
148
+
workspace: ['packages/*'],
149
+
},
150
+
})
151
+
```
94
152
:::
95
153
96
154
Workspace projects do not support all configuration properties. For better type safety, use the `defineProject` method instead of `defineConfig` within project configuration files:
@@ -195,7 +253,7 @@ export default mergeConfig(
195
253
```
196
254
:::
197
255
198
-
At the `defineWorkspace` level, you can use the `extends` option to inherit from your root-level configuration. All options will be merged.
256
+
Additionally, at the `defineWorkspace` level, you can use the `extends` option to inherit from your root-level configuration. All options will be merged.
0 commit comments