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
Define custom aliases when running inside tests. They will be merged with aliases from `resolve.alias`.
320
346
347
+
::: warning
348
+
Vitest uses Vite SSR primitives to run tests which has [certain pitfalls](https://vitejs.dev/guide/ssr.html#ssr-externals).
349
+
350
+
1. Aliases affect only modules imported directly with an `import` keyword by an [inlined](#server-deps-inline) module (all source code is inlined by default).
351
+
2. Vitest does not support aliasing `require` calls.
352
+
3. If you are aliasing an external dependency (e.g., `react` -> `preact`), you may want to alias the actual `node_modules` packages instead to make it work for externalized dependencies. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.io/aliases/) support aliasing via the `npm:` prefix.
353
+
:::
354
+
321
355
### globals
322
356
323
357
-**Type:**`boolean`
@@ -1094,7 +1128,7 @@ List of files included in coverage as glob patterns
Custom scripts that should be injected into the index HTML before test iframes are initiated. This HTML document only sets up iframes and doesn't actually import your code.
1647
+
1648
+
The script `src` and `content` will be processed by Vite plugins. Script should be provided in the following shape:
1649
+
1650
+
```ts
1651
+
exportinterfaceBrowserScript {
1652
+
/**
1653
+
* If "content" is provided and type is "module", this will be its identifier.
1654
+
*
1655
+
* If you are using TypeScript, you can add `.ts` extension here for example.
1656
+
* @default`injected-${index}.js`
1657
+
*/
1658
+
id?:string
1659
+
/**
1660
+
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
1661
+
*
1662
+
* You can use `id` to give Vite a hint about the file extension.
1663
+
*/
1664
+
content?:string
1665
+
/**
1666
+
* Path to the script. This value is resolved by Vite so it can be a node module or a file path.
Custom scripts that should be injected into the tester HTML before the tests environment is initiated. This is useful to inject polyfills required for Vitest browser implementation. It is recommended to use [`setupFiles`](#setupfiles) in almost all cases instead of this.
1687
+
1688
+
The script `src` and `content` will be processed by Vite plugins.
1689
+
1607
1690
### clearMocks
1608
1691
1609
1692
-**Type:**`boolean`
@@ -2192,3 +2275,31 @@ The `location` property has `column` and `line` values that correspond to the `t
2192
2275
::: tip
2193
2276
This option has no effect if you do not use custom code that relies on this.
Path to a custom snapshot environment implementation. This is useful if you are running your tests in an environment that doesn't support Node.js APIs. This option doesn't have any effect on a browser runner.
2284
+
2285
+
This object should have the shape of `SnapshotEnvironment` and is used to resolve and read/write snapshot files:
Copy file name to clipboardExpand all lines: docs/guide/cli-table.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@
25
25
|`--coverage.cleanOnRerun`| Clean coverage report on watch rerun (default: true) |
26
26
|`--coverage.reportsDirectory <path>`| Directory to write coverage report to (default: ./coverage) |
27
27
|`--coverage.reporter <name>`| Coverage reporters to use. Visit [`coverage.reporter`](https://vitest.dev/config/#coverage-reporter) for more information (default: `["text", "html", "clover", "json"]`) |
28
-
|`--coverage.reportOnFailure`| Generate coverage report even when tests fail (default: false) |
29
-
|`--coverage.allowExternal`| Collect coverage of files outside the project root (default: false) |
30
-
|`--coverage.skipFull`| Do not show files with 100% statement, branch, and function coverage (default: false) |
28
+
|`--coverage.reportOnFailure`| Generate coverage report even when tests fail (default: `false`) |
29
+
|`--coverage.allowExternal`| Collect coverage of files outside the project root (default: `false`) |
30
+
|`--coverage.skipFull`| Do not show files with 100% statement, branch, and function coverage (default: `false`) |
31
31
|`--coverage.thresholds.100`| Shortcut to set all coverage thresholds to 100 (default: `false`) |
32
32
|`--coverage.thresholds.perFile`| Check thresholds per file. See `--coverage.thresholds.lines`, `--coverage.thresholds.functions`, `--coverage.thresholds.branches` and `--coverage.thresholds.statements` for the actual thresholds (default: `false`) |
33
33
|`--coverage.thresholds.autoUpdate`| Update threshold values: "lines", "functions", "branches" and "statements" to configuration file when current coverage is above the configured thresholds (default: `false`) |
@@ -119,3 +119,4 @@
119
119
|`--segfaultRetry <times>`| Retry the test suite if it crashes due to a segfault (default: `true`) |
120
120
|`--no-color`| Removes colors from the console output |
121
121
|`--clearScreen`| Clear terminal screen when re-running tests during watch mode (default: `true`) |
122
+
|`--standalone`| Start Vitest without running tests. File filters will be ignored, tests will be running only on change (default: `false`) |
## Type Testing <Badgetype="warning">Experimental</Badge> {#type-testing}
214
217
215
218
Since Vitest 0.25.0 you can [write tests](/guide/testing-types) to catch type regressions. Vitest comes with [`expect-type`](https://github.com/mmkal/expect-type) package to provide you with a similar and easy to understand API.
Where Jest does it by default, when mocking a module and wanting this mocking to be extended to other external libraries that use the same module, you should explicitly tell which 3rd-party library you want to be mocked, so the external library would be part of your source code, by using [server.deps.inline](https://vitest.dev/config/#server-deps-inline).
200
+
201
+
```
202
+
server.deps.inline: ["lib-name"]
203
+
```
204
+
197
205
### Accessing the Return Values of a Mocked Promise
198
206
199
207
Both Jest and Vitest store the results of all mock calls in the [`mock.results`](/api/mock.html#mock-results) array, where the return values of each call are stored in the `value` property.
0 commit comments