Skip to content

Commit 41beb26

Browse files
feat: deprecate workspace in favor of projects (#7923)
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
1 parent 5f50495 commit 41beb26

File tree

92 files changed

+721
-714
lines changed

Some content is hidden

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

92 files changed

+721
-714
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Next generation testing framework powered by Vite.
4343
- Components testing ([Vue](https://github.com/vitest-tests/browser-examples/tree/main/examples/vue), [React](https://github.com/vitest-tests/browser-examples/tree/main/examples/react), [Svelte](https://github.com/vitest-tests/browser-examples/tree/main/examples/svelte), [Lit](./examples/lit), [Marko](https://github.com/marko-js/examples/tree/master/examples/library-ts))
4444
- Workers multi-threading via [Tinypool](https://github.com/tinylibs/tinypool) (a lightweight fork of [Piscina](https://github.com/piscinajs/piscina))
4545
- Benchmarking support with [Tinybench](https://github.com/tinylibs/tinybench)
46-
- [Workspace](https://vitest.dev/guide/workspace) support
46+
- [Projects](https://vitest.dev/guide/projects) support
4747
- [expect-type](https://github.com/mmkal/expect-type) for type-level testing
4848
- ESM first, top level await
4949
- Out-of-box TypeScript / JSX support

docs/.vitepress/components/FeaturesList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ListItem>Workers multi-threading via <a target="_blank" href="https://github.com/tinylibs/tinypool" rel="noopener noreferrer">Tinypool</a></ListItem>
1414
<ListItem>Benchmarking support with <a target="_blank" href="https://github.com/tinylibs/tinybench" rel="noopener noreferrer">Tinybench</a></ListItem>
1515
<ListItem>Filtering, timeouts, concurrent for suite and tests</ListItem>
16-
<ListItem><a href="/guide/workspace">Workspace</a> support</ListItem>
16+
<ListItem><a href="/guide/projects">Projects</a> support</ListItem>
1717
<ListItem>
1818
<a href="/guide/snapshot">
1919
Jest-compatible Snapshot

docs/.vitepress/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ function guide(): DefaultTheme.SidebarItem[] {
477477
link: '/guide/filtering',
478478
},
479479
{
480-
text: 'Workspace',
481-
link: '/guide/workspace',
480+
text: 'Test Projects',
481+
link: '/guide/projects',
482482
},
483483
{
484484
text: 'Reporters',

docs/advanced/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ If you pass down the config to the `startVitest` or `createVitest` APIs, Vitest
119119
:::
120120

121121
::: warning
122-
The `resolveConfig` doesn't resolve the `workspace`. To resolve workspace configs, Vitest needs an established Vite server.
122+
The `resolveConfig` doesn't resolve `projects`. To resolve projects configs, Vitest needs an established Vite server.
123123

124124
Also note that `viteConfig.test` will not be fully resolved. If you need Vitest config, use `vitestConfig` instead.
125125
:::

docs/advanced/api/plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Vitest re-exports all Vite type-only imports via a `Vite` namespace, which you c
5353
```
5454
:::
5555

56-
Unlike [`reporter.onInit`](/advanced/api/reporters#oninit), this hooks runs early in Vitest lifecycle allowing you to make changes to configuration like `coverage` and `reporters`. A more notable change is that you can manipulate the global config from a [workspace project](/guide/workspace) if your plugin is defined in the project and not in the global config.
56+
Unlike [`reporter.onInit`](/advanced/api/reporters#oninit), this hooks runs early in Vitest lifecycle allowing you to make changes to configuration like `coverage` and `reporters`. A more notable change is that you can manipulate the global config from a [test project](/guide/projects) if your plugin is defined in the project and not in the global config.
5757

5858
## Context
5959

@@ -107,7 +107,7 @@ const newProjects = await injectTestProjects({
107107
```
108108

109109
::: warning Projects are Filtered
110-
Vitest filters projects during the config resolution, so if the user defined a filter, injected project might not be resolved unless it [matches the filter](./vitest#matchesprojectfilter). You can update the filter via the `vitest.config.project` option to always include your workspace project:
110+
Vitest filters projects during the config resolution, so if the user defined a filter, injected project might not be resolved unless it [matches the filter](./vitest#matchesprojectfilter). You can update the filter via the `vitest.config.project` option to always include your test project:
111111

112112
```ts
113113
vitest.config.project.push('my-project-name')

docs/advanced/api/test-project.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ title: TestProject
44

55
# TestProject <Version>3.0.0</Version> {#testproject}
66

7-
- **Alias**: `WorkspaceProject` before 3.0.0
8-
97
::: warning
10-
This guide describes the advanced Node.js API. If you just want to create a workspace, follow the ["Workspace"](/guide/workspace) guide.
8+
This guide describes the advanced Node.js API. If you just want to define projects, follow the ["Test Projects"](/guide/projects) guide.
119
:::
1210

1311
## name
@@ -26,28 +24,34 @@ vitest.projects.map(p => p.name) === [
2624
'custom'
2725
]
2826
```
29-
```ts [vitest.workspace.js]
30-
export default [
31-
'./packages/server', // has package.json with "@pkg/server"
32-
'./utils', // doesn't have a package.json file
33-
{
34-
// doesn't customize the name
35-
test: {
36-
pool: 'threads',
37-
},
38-
},
39-
{
40-
// customized the name
41-
test: {
42-
name: 'custom',
43-
},
27+
```ts [vitest.config.js]
28+
import { defineConfig } from 'vitest/config'
29+
30+
export default defineConfig({
31+
test: {
32+
projects: [
33+
'./packages/server', // has package.json with "@pkg/server"
34+
'./utils', // doesn't have a package.json file
35+
{
36+
// doesn't customize the name
37+
test: {
38+
pool: 'threads',
39+
},
40+
},
41+
{
42+
// customized the name
43+
test: {
44+
name: 'custom',
45+
},
46+
},
47+
],
4448
},
45-
]
49+
})
4650
```
4751
:::
4852

4953
::: info
50-
If the [root project](/advanced/api/vitest#getroottestproject) is not part of a user workspace, its `name` will not be resolved.
54+
If the [root project](/advanced/api/vitest#getroottestproject) is not part of user projects, its `name` will not be resolved.
5155
:::
5256

5357
## vitest
@@ -279,7 +283,7 @@ dynamicExample !== staticExample // ✅
279283
:::
280284

281285
::: info
282-
Internally, Vitest uses this method to import global setups, custom coverage providers, workspace file, and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
286+
Internally, Vitest uses this method to import global setups, custom coverage providers and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
283287
:::
284288

285289
## onTestsRerun

docs/advanced/api/vitest.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Benchmark mode calls `bench` functions and throws an error, when it encounters `
6464

6565
## config
6666

67-
The root (or global) config. If workspace feature is enabled, projects will reference this as `globalConfig`.
67+
The root (or global) config. If projects are defined, they will reference this as `globalConfig`.
6868

6969
::: warning
7070
This is Vitest config, it doesn't extend _Vite_ config. It only has resolved values from the `test` property.
@@ -101,17 +101,17 @@ Cache manager that stores information about latest test results and test file st
101101

102102
## projects
103103

104-
An array of [test projects](/advanced/api/test-project) that belong to the user's workspace. If the user did not specify a custom workspace, the workspace will only have a [root project](#getrootproject).
104+
An array of [test projects](/advanced/api/test-project) that belong to user's projects. If the user did not specify a them, this array will only contain a [root project](#getrootproject).
105105

106-
Vitest will ensure that there is always at least one project in the workspace. If the user specifies a non-existent `--project` name, Vitest will throw an error.
106+
Vitest will ensure that there is always at least one project in this array. If the user specifies a non-existent `--project` name, Vitest will throw an error before this array is defined.
107107

108108
## getRootProject
109109

110110
```ts
111111
function getRootProject(): TestProject
112112
```
113113

114-
This returns the root test project. The root project generally doesn't run any tests and is not included in `vitest.projects` unless the user explicitly includes the root config in their workspace, or the workspace is not defined at all.
114+
This returns the root test project. The root project generally doesn't run any tests and is not included in `vitest.projects` unless the user explicitly includes the root config in their configuration, or projects are not defined at all.
115115

116116
The primary goal of the root project is to setup the global config. In fact, `rootProject.config` references `rootProject.globalConfig` and `vitest.config` directly:
117117

@@ -433,7 +433,7 @@ dynamicExample !== staticExample // ✅
433433
:::
434434

435435
::: info
436-
Internally, Vitest uses this method to import global setups, custom coverage providers, workspace file, and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
436+
Internally, Vitest uses this method to import global setups, custom coverage providers, and custom reporters, meaning all of them share the same module graph as long as they belong to the same Vite server.
437437
:::
438438

439439
## close

docs/advanced/pool.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export default defineConfig({
3131
})
3232
```
3333

34-
If you need to run tests in different pools, use the [workspace](/guide/workspace) feature:
34+
If you need to run tests in different pools, use the [`projects`](/guide/projects) feature:
3535

3636
```ts [vitest.config.ts]
3737
export default defineConfig({
3838
test: {
39-
workspace: [
39+
projects: [
4040
{
4141
extends: true,
4242
test: {
@@ -48,10 +48,6 @@ export default defineConfig({
4848
})
4949
```
5050

51-
::: info
52-
The `workspace` field was introduced in Vitest 3. To define a workspace in [Vitest 2](https://v2.vitest.dev/), create a separate `vitest.workspace.ts` file.
53-
:::
54-
5551
## API
5652

5753
The file specified in `pool` option should export a function (can be async) that accepts `Vitest` interface as its first option. This function needs to return an object matching `ProcessPool` interface:
@@ -69,7 +65,7 @@ export interface ProcessPool {
6965

7066
The function is called only once (unless the server config was updated), and it's generally a good idea to initialize everything you need for tests inside that function and reuse it when `runTests` is called.
7167

72-
Vitest calls `runTest` when new tests are scheduled to run. It will not call it if `files` is empty. The first argument is an array of [TestSpecifications](/advanced/api/test-specification). Files are sorted using [`sequencer`](/config/#sequence-sequencer) before `runTests` is called. It's possible (but unlikely) to have the same file twice, but it will always have a different project - this is implemented via [`vitest.workspace.ts`](/guide/workspace) configuration.
68+
Vitest calls `runTest` when new tests are scheduled to run. It will not call it if `files` is empty. The first argument is an array of [TestSpecifications](/advanced/api/test-specification). Files are sorted using [`sequencer`](/config/#sequence-sequencer) before `runTests` is called. It's possible (but unlikely) to have the same file twice, but it will always have a different project - this is implemented via [`projects`](/guide/projects) configuration.
7369

7470
Vitest will wait until `runTests` is executed before finishing a run (i.e., it will emit [`onFinished`](/advanced/reporters) only after `runTests` is resolved).
7571

docs/advanced/runner.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ interface File extends Suite {
164164
*/
165165
filepath: string
166166
/**
167-
* The name of the workspace project the file belongs to.
167+
* The name of the test project the file belongs to.
168168
*/
169169
projectName: string | undefined
170170
/**

docs/blog/vitest-3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ You can follow the design process in [#7069](https://github.com/vitest-dev/vites
7272

7373
## Inline Workspace
7474

75-
Rejoice! No more separate files to define your [workspace](/guide/workspace) - specify an array of projects using the `workspace` field in your `vitest.config` file:
75+
Rejoice! No more separate files to define your [workspace](/guide/projects) - specify an array of projects using the `workspace` field in your `vitest.config` file:
7676

7777
```jsx
7878
import { defineConfig } from 'vitest/config'

docs/config/index.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default defineConfig({
106106

107107
Since 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.
108108

109-
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.
109+
Configuration options that are not supported inside a [project](/guide/projects) config have <NonProjectOption /> sign next to them. This means they can only be set in the root Vitest config.
110110
:::
111111

112112
### include
@@ -588,15 +588,15 @@ These options are passed down to `setup` method of current [`environment`](#envi
588588
- **Default:** `[]`
589589

590590
::: danger DEPRECATED
591-
This API was deprecated in Vitest 3. Use [workspace](/guide/workspace) to define different configurations instead.
591+
This API was deprecated in Vitest 3. Use [projects](/guide/projects) to define different configurations instead.
592592

593593
```ts
594594
export default defineConfig({
595595
test: {
596596
environmentMatchGlobs: [ // [!code --]
597597
['./*.jsdom.test.ts', 'jsdom'], // [!code --]
598598
], // [!code --]
599-
workspace: [ // [!code ++]
599+
projects: [ // [!code ++]
600600
{ // [!code ++]
601601
extends: true, // [!code ++]
602602
test: { // [!code ++]
@@ -635,15 +635,15 @@ export default defineConfig({
635635
- **Default:** `[]`
636636

637637
::: danger DEPRECATED
638-
This API was deprecated in Vitest 3. Use [workspace](/guide/workspace) to define different configurations instead:
638+
This API was deprecated in Vitest 3. Use [projects](/guide/projects) to define different configurations instead:
639639

640640
```ts
641641
export default defineConfig({
642642
test: {
643643
poolMatchGlobs: [ // [!code --]
644644
['./*.threads.test.ts', 'threads'], // [!code --]
645645
], // [!code --]
646-
workspace: [ // [!code ++]
646+
projects: [ // [!code ++]
647647
{ // [!code ++]
648648
test: { // [!code ++]
649649
extends: true, // [!code ++]
@@ -724,7 +724,7 @@ export default defineConfig({
724724
```
725725

726726
::: warning
727-
Returned files should be either absolute or relative to the root. Note that this is a global option, and it cannot be used inside of [project](/guide/workspace) configs.
727+
Returned files should be either absolute or relative to the root. Note that this is a global option, and it cannot be used inside of [project](/guide/projects) configs.
728728
:::
729729

730730
### root
@@ -2436,14 +2436,25 @@ Tells fake timers to clear "native" (i.e. not fake) timers by delegating to thei
24362436

24372437
### workspace<NonProjectOption /> {#workspace}
24382438

2439-
- **Type:** `string | TestProjectConfiguration`
2439+
::: danger DEPRECATED
2440+
This options is deprecated and will be removed in the next major. Please, use [`projects`](#projects) instead.
2441+
:::
2442+
2443+
- **Type:** `string | TestProjectConfiguration[]`
24402444
- **CLI:** `--workspace=./file.js`
24412445
- **Default:** `vitest.{workspace,projects}.{js,ts,json}` close to the config file or root
24422446

2443-
Path to a [workspace](/guide/workspace) config file relative to [root](#root).
2447+
Path to a [workspace](/guide/projects) config file relative to [root](#root).
24442448

24452449
Since Vitest 3, 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.
24462450

2451+
### projects<NonProjectOption /> {#projects}
2452+
2453+
- **Type:** `TestProjectConfiguration[]`
2454+
- **Default:** `[]`
2455+
2456+
An array of [projects](/guide/projects).
2457+
24472458
### isolate
24482459

24492460
- **Type:** `boolean`

docs/guide/browser/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Command is a function that invokes another function on the server and passes dow
1111

1212
### Files Handling
1313

14-
You can use the `readFile`, `writeFile`, and `removeFile` APIs to handle files in your browser tests. Since Vitest 3.2, all paths are resolved relative to the [project](/guide/workspace) root (which is `process.cwd()`, unless overriden manually). Previously, paths were resolved relative to the test file.
14+
You can use the `readFile`, `writeFile`, and `removeFile` APIs to handle files in your browser tests. Since Vitest 3.2, all paths are resolved relative to the [project](/guide/projects) root (which is `process.cwd()`, unless overriden manually). Previously, paths were resolved relative to the test file.
1515

1616
By default, Vitest uses `utf-8` encoding but you can override it with options.
1717

0 commit comments

Comments
 (0)