···106106107107Since Vitest uses Vite config, you can also use any configuration option from [Vite](https://vitejs.dev/config/). For example, `define` to define global variables, or `resolve.alias` to define aliases - these options should be defined on the top level, _not_ within a `test` property.
108108109109-Configuration options that are not supported inside a [workspace](/guide/workspace) project config have <NonProjectOption /> sign next to them.
109109+Configuration options that are not supported inside a [workspace](/guide/workspace) project config have <NonProjectOption /> sign next to them. This means they can only be set in the root Vitest config.
110110:::
111111112112### include
+31-27
docs/guide/index.md
···177177178178## Workspaces Support
179179180180-Run different project configurations inside the same project with [Vitest Workspaces](/guide/workspace). You can define a list of files and folders that define your workspace in `vitest.workspace` file. The file supports `js`/`ts`/`json` extensions. This feature works great with monorepo setups.
180180+Run different project configurations inside the same project with [Vitest Workspaces](/guide/workspace). You can define a list of files and folders that define your workspace in `vitest.config` file.
181181182182-```ts [vitest.workspace.ts]
183183-import { defineWorkspace } from 'vitest/config'
182182+```ts [vitest.config.ts]
183183+import { defineConfig } from 'vitest/config'
184184185185-export default defineWorkspace([
186186- // you can use a list of glob patterns to define your workspaces
187187- // Vitest expects a list of config files
188188- // or directories where there is a config file
189189- 'packages/*',
190190- 'tests/*/vitest.config.{e2e,unit}.ts',
191191- // you can even run the same tests,
192192- // but with different configs in the same "vitest" process
193193- {
194194- test: {
195195- name: 'happy-dom',
196196- root: './shared_tests',
197197- environment: 'happy-dom',
198198- setupFiles: ['./setup.happy-dom.ts'],
199199- },
185185+export default defineConfig({
186186+ test: {
187187+ workspace: [
188188+ // you can use a list of glob patterns to define your workspaces
189189+ // Vitest expects a list of config files
190190+ // or directories where there is a config file
191191+ 'packages/*',
192192+ 'tests/*/vitest.config.{e2e,unit}.ts',
193193+ // you can even run the same tests,
194194+ // but with different configs in the same "vitest" process
195195+ {
196196+ test: {
197197+ name: 'happy-dom',
198198+ root: './shared_tests',
199199+ environment: 'happy-dom',
200200+ setupFiles: ['./setup.happy-dom.ts'],
201201+ },
202202+ },
203203+ {
204204+ test: {
205205+ name: 'node',
206206+ root: './shared_tests',
207207+ environment: 'node',
208208+ setupFiles: ['./setup.node.ts'],
209209+ },
210210+ },
211211+ ],
200212 },
201201- {
202202- test: {
203203- name: 'node',
204204- root: './shared_tests',
205205- environment: 'node',
206206- setupFiles: ['./setup.node.ts'],
207207- },
208208- },
209209-])
213213+})
210214```
211215212216## Command Line Interface
+74-75
docs/guide/workspace.md
···14141515## Defining a Workspace
16161717-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.
1717+Since Vitest 3, you can define a workspace in your root [config](/config/). In this case, Vitest will ignore the `vitest.workspace` file in the root, if one exists.
18181919-Since Vitest 3, 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.
1919+```ts [vitest.config.ts]
2020+import { defineConfig } from 'vitest/config'
2121+2222+export default defineConfig({
2323+ test: {
2424+ workspace: ['packages/*'],
2525+ },
2626+})
2727+```
2828+2929+If you are using an older version, a workspace must include `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.
20302131::: tip NAMING
2232Please note that this feature is named `workspace`, not `workspaces` (without an "s" at the end).
···2535A 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:
26362737:::code-group
2828-```ts [vitest.workspace.ts]
2929-export default [
3030- 'packages/*'
3131-]
3232-```
3338```ts [vitest.config.ts <Version>3.0.0</Version>]
3439import { defineConfig } from 'vitest/config'
3540···3843 workspace: ['packages/*'],
3944 },
4045})
4646+```
4747+```ts [vitest.workspace.ts]
4848+export default [
4949+ 'packages/*'
5050+]
4151```
4252:::
4353···5060You can also reference projects with their config files:
51615262:::code-group
5353-```ts [vitest.workspace.ts]
5454-export default [
5555- 'packages/*/vitest.config.{e2e,unit}.ts'
5656-]
5757-```
5863```ts [vitest.config.ts <Version>3.0.0</Version>]
5964import { defineConfig } from 'vitest/config'
6065···6469 },
6570})
6671```
7272+```ts [vitest.workspace.ts]
7373+export default [
7474+ 'packages/*/vitest.config.{e2e,unit}.ts'
7575+]
7676+```
6777:::
68786979This pattern will only include projects with a `vitest.config` file that contains `e2e` or `unit` before the extension.
70807171-You can also define projects using inline configuration. The workspace file supports both syntaxes simultaneously.
8181+You can also define projects using inline configuration. The workspace configuration supports both syntaxes simultaneously.
72827383:::code-group
7474-```ts [vitest.workspace.ts]
7575-import { defineWorkspace } from 'vitest/config'
7676-7777-// defineWorkspace provides a nice type hinting DX
7878-export default defineWorkspace([
7979- // matches every folder and file inside the `packages` folder
8080- 'packages/*',
8181- {
8282- // add "extends" to merge two configs together
8383- extends: './vite.config.js',
8484- test: {
8585- include: ['tests/**/*.{browser}.test.{ts,js}'],
8686- // it is recommended to define a name when using inline configs
8787- name: 'happy-dom',
8888- environment: 'happy-dom',
8989- }
9090- },
9191- {
9292- test: {
9393- include: ['tests/**/*.{node}.test.{ts,js}'],
9494- name: 'node',
9595- environment: 'node',
9696- }
9797- }
9898-])
9999-```
10084```ts [vitest.config.ts <Version>3.0.0</Version>]
10185import { defineConfig } from 'vitest/config'
10286···126110 }
127111})
128112```
113113+```ts [vitest.workspace.ts]
114114+import { defineWorkspace } from 'vitest/config'
115115+116116+// defineWorkspace provides a nice type hinting DX
117117+export default defineWorkspace([
118118+ // matches every folder and file inside the `packages` folder
119119+ 'packages/*',
120120+ {
121121+ // add "extends" to merge two configs together
122122+ extends: './vite.config.js',
123123+ test: {
124124+ include: ['tests/**/*.{browser}.test.{ts,js}'],
125125+ // it is recommended to define a name when using inline configs
126126+ name: 'happy-dom',
127127+ environment: 'happy-dom',
128128+ }
129129+ },
130130+ {
131131+ test: {
132132+ include: ['tests/**/*.{node}.test.{ts,js}'],
133133+ name: 'node',
134134+ environment: 'node',
135135+ }
136136+ }
137137+])
138138+```
129139:::
130140131141::: warning
···134144135145If 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:
136146137137-:::code-group
138147```json [vitest.workspace.json]
139148[
140149 "packages/*"
141150]
142151```
143143-```ts [vitest.config.ts <Version>3.0.0</Version>]
144144-import { defineConfig } from 'vitest/config'
145145-146146-export default defineConfig({
147147- test: {
148148- workspace: ['packages/*'],
149149- },
150150-})
151151-```
152152-:::
153152154153Workspace projects do not support all configuration properties. For better type safety, use the `defineProject` method instead of `defineConfig` within project configuration files:
155154···192191pnpm run test
193192```
194193```bash [bun]
195195-bun test
194194+bun run test
196195```
197196:::
198197···209208pnpm run test --project e2e
210209```
211210```bash [bun]
212212-bun test --project e2e
211211+bun run test --project e2e
213212```
214213:::
215214···227226pnpm run test --project e2e --project unit
228227```
229228```bash [bun]
230230-bun test --project e2e --project unit
229229+bun run test --project e2e --project unit
231230```
232231:::
233232···252251Additionally, at the `defineWorkspace` level, you can use the `extends` option to inherit from your root-level configuration. All options will be merged.
253252254253::: code-group
255255-```ts [vitest.workspace.ts]
256256-import { defineWorkspace } from 'vitest/config'
257257-258258-export default defineWorkspace([
259259- {
260260- extends: './vitest.config.ts',
261261- test: {
262262- name: 'unit',
263263- include: ['**/*.unit.test.ts'],
264264- },
265265- },
266266- {
267267- extends: './vitest.config.ts',
268268- test: {
269269- name: 'integration',
270270- include: ['**/*.integration.test.ts'],
271271- },
272272- },
273273-])
274274-```
275254```ts [vitest.config.ts <Version>3.0.0</Version>]
276255import { defineConfig } from 'vitest/config'
277256import react from '@vitejs/plugin-react'
···302281 },
303282})
304283```
284284+```ts [vitest.workspace.ts]
285285+import { defineWorkspace } from 'vitest/config'
286286+287287+export default defineWorkspace([
288288+ {
289289+ extends: './vitest.config.ts',
290290+ test: {
291291+ name: 'unit',
292292+ include: ['**/*.unit.test.ts'],
293293+ },
294294+ },
295295+ {
296296+ extends: './vitest.config.ts',
297297+ test: {
298298+ name: 'integration',
299299+ include: ['**/*.integration.test.ts'],
300300+ },
301301+ },
302302+])
303303+```
305304:::
306305306306+::: danger Unsupported Options
307307Some of the configuration options are not allowed in a project config. Most notably:
308308309309- `coverage`: coverage is done for the whole workspace
···311311- `resolveSnapshotPath`: only root-level resolver is respected
312312- all other options that don't affect test runners
313313314314-::: tip
315315-All configuration options that are not supported inside a project configuration are marked with a <NonProjectOption /> sign in the ["Config"](/config/) guide.
314314+All configuration options that are not supported inside a project configuration are marked with a <NonProjectOption /> sign in the ["Config"](/config/) guide. They have to be defined once in the root config file.
316315:::