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/advanced/runner.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,14 +121,14 @@ export default CustomRunner
121
121
```
122
122
123
123
::: warning
124
-
Vitest also injects an instance of `ViteNodeRunner`as `__vitest_executor` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).
124
+
Vitest also injects an instance of `ModuleRunner` from `vite/module-runner`as `moduleRunner` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).
125
125
126
-
`ViteNodeRunner` exposes `executeId` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:
126
+
`ModuleRunner` exposes `import` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:
Enable dependency optimization. If you have a lot of tests, this might improve their performance.
@@ -245,7 +245,7 @@ When Vitest encounters the external library listed in `include`, it will be bund
245
245
- Your `alias` configuration is now respected inside bundled packages
246
246
- Code in your tests is running closer to how it's running in the browser
247
247
248
-
Be aware that only packages in `deps.optimizer?.[mode].include` option are bundled (some plugins populate this automatically, like Svelte). You can read more about available options in [Vite](https://vitejs.dev/config/dep-optimization-options.html) docs (Vitest doesn't support `disable` and `noDiscovery` options). By default, Vitest uses `optimizer.web` for `jsdom` and `happy-dom` environments, and `optimizer.ssr` for `node` and `edge` environments, but it is configurable by [`transformMode`](#testtransformmode).
248
+
Be aware that only packages in `deps.optimizer?.[mode].include` option are bundled (some plugins populate this automatically, like Svelte). You can read more about available options in [Vite](https://vitejs.dev/config/dep-optimization-options.html) docs (Vitest doesn't support `disable` and `noDiscovery` options). By default, Vitest uses `optimizer.client` for `jsdom` and `happy-dom` environments, and `optimizer.ssr` for `node` and `edge` environments.
249
249
250
250
This options also inherits your `optimizeDeps` configuration (for web Vitest will extend `optimizeDeps`, for ssr - `ssr.optimizeDeps`). If you redefine `include`/`exclude` option in `deps.optimizer` it will extend your `optimizeDeps` when running tests. Vitest automatically removes the same options from `include`, if they are listed in `exclude`.
251
251
@@ -260,15 +260,15 @@ You will not be able to edit your `node_modules` code for debugging, since the c
260
260
261
261
Enable dependency optimization.
262
262
263
-
#### deps.web {#deps-web}
263
+
#### deps.client {#deps-client}
264
264
265
265
-**Type:**`{ transformAssets?, ... }`
266
266
267
-
Options that are applied to external files when transform mode is set to `web`. By default, `jsdom` and `happy-dom` use `web` mode, while `node` and `edge` environments use `ssr` transform mode, so these options will have no affect on files inside those environments.
267
+
Options that are applied to external files when the environment is set to `client`. By default, `jsdom` and `happy-dom` use `client` environment, while `node` and `edge` environments use `ssr`, so these options will have no affect on files inside those environments.
268
268
269
269
Usually, files inside `node_modules` are externalized, but these options also affect files in [`server.deps.external`](#server-deps-external).
270
270
271
-
#### deps.web.transformAssets
271
+
#### deps.client.transformAssets
272
272
273
273
-**Type:**`boolean`
274
274
-**Default:**`true`
@@ -281,7 +281,7 @@ This module will have a default export equal to the path to the asset, if no que
281
281
At the moment, this option only works with [`vmThreads`](#vmthreads) and [`vmForks`](#vmforks) pools.
282
282
:::
283
283
284
-
#### deps.web.transformCss
284
+
#### deps.client.transformCss
285
285
286
286
-**Type:**`boolean`
287
287
-**Default:**`true`
@@ -294,7 +294,7 @@ If CSS files are disabled with [`css`](#css) options, this option will just sile
294
294
At the moment, this option only works with [`vmThreads`](#vmthreads) and [`vmForks`](#vmforks) pools.
295
295
:::
296
296
297
-
#### deps.web.transformGlobPattern
297
+
#### deps.client.transformGlobPattern
298
298
299
299
-**Type:**`RegExp | RegExp[]`
300
300
-**Default:**`[]`
@@ -560,7 +560,7 @@ import type { Environment } from 'vitest'
560
560
561
561
exportdefault <Environment>{
562
562
name: 'custom',
563
-
transformMode: 'ssr',
563
+
viteEnvironment: 'ssr',
564
564
setup() {
565
565
// custom setup
566
566
return {
@@ -1676,28 +1676,6 @@ Will call [`vi.unstubAllEnvs`](/api/vi#vi-unstuballenvs) before each test.
1676
1676
1677
1677
Will call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals) before each test.
1678
1678
1679
-
### testTransformMode {#testtransformmode}
1680
-
1681
-
-**Type:**`{ web?, ssr? }`
1682
-
1683
-
Determine the transform method for all modules imported inside a test that matches the glob pattern. By default, relies on the environment. For example, tests with JSDOM environment will process all files with `ssr: false` flag and tests with Node environment process all modules with `ssr: true`.
1684
-
1685
-
#### testTransformMode.ssr
1686
-
1687
-
-**Type:**`string[]`
1688
-
-**Default:**`[]`
1689
-
1690
-
Use SSR transform pipeline for all modules inside specified tests.<br>
1691
-
Vite plugins will receive `ssr: true` flag when processing those files.
1692
-
1693
-
#### testTransformMode.web
1694
-
1695
-
-**Type:**`string[]`
1696
-
-**Default:**`[]`
1697
-
1698
-
First do a normal transform pipeline (targeting browser), then do a SSR rewrite to run the code in Node.<br>
1699
-
Vite plugins will receive `ssr: false` flag when processing those files.
Copy file name to clipboardExpand all lines: docs/guide/environment.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ import type { Environment } from 'vitest/environments'
48
48
49
49
exportdefault <Environment>{
50
50
name: 'custom',
51
-
transformMode: 'ssr',
51
+
viteEnvironment: 'ssr',
52
52
// optional - only if you support "experimental-vm" pool
53
53
async setupVM() {
54
54
const vm =awaitimport('node:vm')
@@ -74,7 +74,7 @@ export default <Environment>{
74
74
```
75
75
76
76
::: warning
77
-
Vitest requires `transformMode` option on environment object. It should be equal to `ssr` or `web`. This value determines how plugins will transform source code. If it's set to `ssr`, plugin hooks will receive `ssr: true` when transforming or resolving files. Otherwise, `ssr`is set to `false`.
77
+
Vitest requires `viteEnvironment` option on environment object (fallbacks to the Vitest environment name by default). It should be equal to `ssr`, `client` or any custom [Vite environment](https://vite.dev/guide/api-environment) name. This value determines which environment is used to process file.
78
78
:::
79
79
80
80
You also have access to default Vitest environments through `vitest/environments` entry:
Copy file name to clipboardExpand all lines: docs/guide/migration.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,15 +145,31 @@ $ pnpm run test:dev math.test.ts
145
145
```
146
146
:::
147
147
148
+
### Replacing `vite-node` with [Module Runner](https://vite.dev/guide/api-environment-runtimes.html#modulerunner)
149
+
150
+
Module Runner is a successor to `vite-node` implemented directly in Vite. Vitest now uses it directly instead of having a wrapper around Vite SSR handler. This means that certain features are no longer available:
151
+
152
+
-`VITE_NODE_DEPS_MODULE_DIRECTORIES` environment variable was replaced with `VITEST_MODULE_DIRECTORIES`
153
+
- Vitest no longer injects `__vitest_executor` into every [test runner](/advanced/runner). Instead, it injects `moduleRunner` which is an instance of [`ModuleRunner`](https://vite.dev/guide/api-environment-runtimes.html#modulerunner)
154
+
-`vitest/execute` entry point was removed. It was always meant to be internal
155
+
-[Custom environments](/guide/environment) no longer need to provide a `transformMode` property. Instead, provide `viteEnvironment`. If it is not provided, Vitest will use the environment name to transform files on the server (see [`server.environments`](https://vite.dev/guide/api-environment-instances.html))
156
+
-`vite-node` is no longer a dependency of Vitest
157
+
-`deps.optimizer.web` was renamed to [`deps.optimizer.client`](/config/#deps-optimizer-client). You can also use any custom names to apply optimizer configs when using other server environments
158
+
159
+
Vite has its own externalization mechanism, but we decided to keep using the old one to reduce the amount of breaking changes. You can keep using [`server.deps`](/config/#server-deps) to inline or externalize packages.
160
+
161
+
This update should not be noticeable unless you rely on advanced features mentioned above.
162
+
148
163
### Deprecated APIs are Removed
149
164
150
165
Vitest 4.0 removes some deprecated APIs, including:
151
166
152
167
-`poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
153
168
-`environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
154
169
-`workspace` config option. Use [`projects`](/guide/projects) instead.
170
+
-`deps.external`, `deps.inline`, `deps.fallbackCJS` config options. Use `server.deps.external`, `server.deps.inline`, or `server.deps.fallbackCJS` instead.
155
171
156
-
This release also removes all deprecated types. This finally fixes an issue where Vitest accidentally pulled in `node` types (see [#5481](https://github.com/vitest-dev/vitest/issues/5481) and [#6141](https://github.com/vitest-dev/vitest/issues/6141)).
172
+
This release also removes all deprecated types. This finally fixes an issue where Vitest accidentally pulled in `@types/node` (see [#5481](https://github.com/vitest-dev/vitest/issues/5481) and [#6141](https://github.com/vitest-dev/vitest/issues/6141)).
0 commit comments