@vitest-agent/mcp 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/bin/vitest-agent-mcp.js +1 -17
- package/index.d.ts +324 -315
- package/index.js +2 -4
- package/middleware/idempotency.js +1 -1
- package/package.json +2 -2
- package/server.js +2 -4
- package/tools/acceptance-metrics.js +1 -1
- package/tools/cache-health.js +1 -1
- package/tools/commit-changes.js +1 -1
- package/tools/configure.js +1 -1
- package/tools/coverage.js +1 -1
- package/tools/errors.js +1 -1
- package/tools/failure-signature-get.js +1 -1
- package/tools/file-coverage.js +1 -1
- package/tools/history.js +1 -1
- package/tools/inventory.js +1 -1
- package/tools/overview.js +1 -1
- package/tools/run-tests.js +15 -3
- package/tools/settings-list.js +1 -1
- package/tools/status.js +1 -1
- package/tools/tdd-artifact.js +1 -1
- package/tools/tdd-task.js +1 -1
- package/tools/test.js +1 -1
- package/tools/trends.js +1 -1
- package/tools/turn-search.js +1 -1
- package/public/patterns/_meta.json +0 -67
- package/public/patterns/authoring-a-custom-vitest-agent-reporter.md +0 -82
- package/public/patterns/known-issues-and-caveats.md +0 -52
- package/public/patterns/operating-vitest-agent-as-an-agent.md +0 -53
- package/public/patterns/running-tests-via-mcp.md +0 -58
- package/public/patterns/silencing-leaking-output-in-tests.md +0 -91
- package/public/patterns/testing-effect-schema-definitions.md +0 -71
- package/public/patterns/testing-effect-services-with-mock-layers.md +0 -63
- package/public/vendor/vitest-docs/ATTRIBUTION.md +0 -5
- package/public/vendor/vitest-docs/api/advanced/artifacts.md +0 -189
- package/public/vendor/vitest-docs/api/advanced/metadata.md +0 -68
- package/public/vendor/vitest-docs/api/advanced/plugin.md +0 -168
- package/public/vendor/vitest-docs/api/advanced/reporters.md +0 -342
- package/public/vendor/vitest-docs/api/advanced/runner.md +0 -334
- package/public/vendor/vitest-docs/api/advanced/test-case.md +0 -302
- package/public/vendor/vitest-docs/api/advanced/test-collection.md +0 -89
- package/public/vendor/vitest-docs/api/advanced/test-module.md +0 -140
- package/public/vendor/vitest-docs/api/advanced/test-project.md +0 -321
- package/public/vendor/vitest-docs/api/advanced/test-specification.md +0 -96
- package/public/vendor/vitest-docs/api/advanced/test-suite.md +0 -230
- package/public/vendor/vitest-docs/api/advanced/vitest.md +0 -684
- package/public/vendor/vitest-docs/api/assert-type.md +0 -22
- package/public/vendor/vitest-docs/api/assert.md +0 -1960
- package/public/vendor/vitest-docs/api/browser/assertions.md +0 -1277
- package/public/vendor/vitest-docs/api/browser/commands.md +0 -154
- package/public/vendor/vitest-docs/api/browser/context.md +0 -338
- package/public/vendor/vitest-docs/api/browser/interactivity.md +0 -681
- package/public/vendor/vitest-docs/api/browser/locators.md +0 -1171
- package/public/vendor/vitest-docs/api/browser/react.md +0 -346
- package/public/vendor/vitest-docs/api/browser/svelte.md +0 -292
- package/public/vendor/vitest-docs/api/browser/vue.md +0 -222
- package/public/vendor/vitest-docs/api/describe.md +0 -374
- package/public/vendor/vitest-docs/api/expect-typeof.md +0 -571
- package/public/vendor/vitest-docs/api/expect.md +0 -2304
- package/public/vendor/vitest-docs/api/hooks.md +0 -463
- package/public/vendor/vitest-docs/api/mock.md +0 -701
- package/public/vendor/vitest-docs/api/test.md +0 -926
- package/public/vendor/vitest-docs/api/vi.md +0 -1372
- package/public/vendor/vitest-docs/config/alias.md +0 -13
- package/public/vendor/vitest-docs/config/allowonly.md +0 -32
- package/public/vendor/vitest-docs/config/api.md +0 -27
- package/public/vendor/vitest-docs/config/attachmentsdir.md +0 -6
- package/public/vendor/vitest-docs/config/bail.md +0 -9
- package/public/vendor/vitest-docs/config/benchmark.md +0 -65
- package/public/vendor/vitest-docs/config/browser/api.md +0 -23
- package/public/vendor/vitest-docs/config/browser/commands.md +0 -6
- package/public/vendor/vitest-docs/config/browser/connecttimeout.md +0 -10
- package/public/vendor/vitest-docs/config/browser/detailspanelposition.md +0 -38
- package/public/vendor/vitest-docs/config/browser/enabled.md +0 -40
- package/public/vendor/vitest-docs/config/browser/expect.md +0 -250
- package/public/vendor/vitest-docs/config/browser/headless.md +0 -7
- package/public/vendor/vitest-docs/config/browser/instances.md +0 -47
- package/public/vendor/vitest-docs/config/browser/isolate.md +0 -11
- package/public/vendor/vitest-docs/config/browser/locators.md +0 -24
- package/public/vendor/vitest-docs/config/browser/orchestratorscripts.md +0 -39
- package/public/vendor/vitest-docs/config/browser/playwright.md +0 -214
- package/public/vendor/vitest-docs/config/browser/preview.md +0 -32
- package/public/vendor/vitest-docs/config/browser/provider.md +0 -79
- package/public/vendor/vitest-docs/config/browser/screenshotdirectory.md +0 -6
- package/public/vendor/vitest-docs/config/browser/screenshotfailures.md +0 -6
- package/public/vendor/vitest-docs/config/browser/testerhtmlpath.md +0 -5
- package/public/vendor/vitest-docs/config/browser/trace.md +0 -43
- package/public/vendor/vitest-docs/config/browser/trackunhandlederrors.md +0 -10
- package/public/vendor/vitest-docs/config/browser/ui.md +0 -7
- package/public/vendor/vitest-docs/config/browser/viewport.md +0 -6
- package/public/vendor/vitest-docs/config/browser/webdriverio.md +0 -64
- package/public/vendor/vitest-docs/config/cache.md +0 -26
- package/public/vendor/vitest-docs/config/chaiconfig.md +0 -29
- package/public/vendor/vitest-docs/config/clearmocks.md +0 -22
- package/public/vendor/vitest-docs/config/coverage.md +0 -455
- package/public/vendor/vitest-docs/config/css.md +0 -47
- package/public/vendor/vitest-docs/config/dangerouslyignoreunhandlederrors.md +0 -23
- package/public/vendor/vitest-docs/config/deps.md +0 -127
- package/public/vendor/vitest-docs/config/detectasyncleaks.md +0 -39
- package/public/vendor/vitest-docs/config/diff.md +0 -96
- package/public/vendor/vitest-docs/config/dir.md +0 -7
- package/public/vendor/vitest-docs/config/disableconsoleintercept.md +0 -15
- package/public/vendor/vitest-docs/config/env.md +0 -5
- package/public/vendor/vitest-docs/config/environment.md +0 -96
- package/public/vendor/vitest-docs/config/environmentoptions.md +0 -30
- package/public/vendor/vitest-docs/config/exclude.md +0 -49
- package/public/vendor/vitest-docs/config/execargv.md +0 -10
- package/public/vendor/vitest-docs/config/expandsnapshotdiff.md +0 -7
- package/public/vendor/vitest-docs/config/expect.md +0 -38
- package/public/vendor/vitest-docs/config/experimental.md +0 -510
- package/public/vendor/vitest-docs/config/faketimers.md +0 -51
- package/public/vendor/vitest-docs/config/fileparallelism.md +0 -11
- package/public/vendor/vitest-docs/config/forcereruntriggers.md +0 -19
- package/public/vendor/vitest-docs/config/globals.md +0 -42
- package/public/vendor/vitest-docs/config/globalsetup.md +0 -72
- package/public/vendor/vitest-docs/config/hideskippedtests.md +0 -7
- package/public/vendor/vitest-docs/config/hooktimeout.md +0 -7
- package/public/vendor/vitest-docs/config/include-source.md +0 -115
- package/public/vendor/vitest-docs/config/include.md +0 -71
- package/public/vendor/vitest-docs/config/includetasklocation.md +0 -17
- package/public/vendor/vitest-docs/config/index.md +0 -85
- package/public/vendor/vitest-docs/config/isolate.md +0 -13
- package/public/vendor/vitest-docs/config/logheapusage.md +0 -7
- package/public/vendor/vitest-docs/config/maxconcurrency.md +0 -9
- package/public/vendor/vitest-docs/config/maxworkers.md +0 -49
- package/public/vendor/vitest-docs/config/mockreset.md +0 -22
- package/public/vendor/vitest-docs/config/mode.md +0 -7
- package/public/vendor/vitest-docs/config/name.md +0 -111
- package/public/vendor/vitest-docs/config/onconsolelog.md +0 -25
- package/public/vendor/vitest-docs/config/onstacktrace.md +0 -32
- package/public/vendor/vitest-docs/config/onunhandlederror.md +0 -35
- package/public/vendor/vitest-docs/config/open.md +0 -7
- package/public/vendor/vitest-docs/config/outputfile.md +0 -7
- package/public/vendor/vitest-docs/config/passwithnotests.md +0 -7
- package/public/vendor/vitest-docs/config/pool.md +0 -45
- package/public/vendor/vitest-docs/config/printconsoletrace.md +0 -6
- package/public/vendor/vitest-docs/config/projects.md +0 -6
- package/public/vendor/vitest-docs/config/provide.md +0 -45
- package/public/vendor/vitest-docs/config/reporters.md +0 -69
- package/public/vendor/vitest-docs/config/resolvesnapshotpath.md +0 -36
- package/public/vendor/vitest-docs/config/restoremocks.md +0 -22
- package/public/vendor/vitest-docs/config/retry.md +0 -140
- package/public/vendor/vitest-docs/config/root.md +0 -6
- package/public/vendor/vitest-docs/config/runner.md +0 -6
- package/public/vendor/vitest-docs/config/sequence.md +0 -158
- package/public/vendor/vitest-docs/config/server.md +0 -68
- package/public/vendor/vitest-docs/config/setupfiles.md +0 -40
- package/public/vendor/vitest-docs/config/silent.md +0 -9
- package/public/vendor/vitest-docs/config/slowtestthreshold.md +0 -7
- package/public/vendor/vitest-docs/config/snapshotenvironment.md +0 -27
- package/public/vendor/vitest-docs/config/snapshotformat.md +0 -28
- package/public/vendor/vitest-docs/config/snapshotserializers.md +0 -6
- package/public/vendor/vitest-docs/config/stricttags.md +0 -30
- package/public/vendor/vitest-docs/config/tags.md +0 -141
- package/public/vendor/vitest-docs/config/teardowntimeout.md +0 -7
- package/public/vendor/vitest-docs/config/testnamepattern.md +0 -21
- package/public/vendor/vitest-docs/config/testtimeout.md +0 -7
- package/public/vendor/vitest-docs/config/typecheck.md +0 -77
- package/public/vendor/vitest-docs/config/ui.md +0 -15
- package/public/vendor/vitest-docs/config/unstubenvs.md +0 -20
- package/public/vendor/vitest-docs/config/unstubglobals.md +0 -20
- package/public/vendor/vitest-docs/config/update.md +0 -16
- package/public/vendor/vitest-docs/config/vmmemorylimit.md +0 -30
- package/public/vendor/vitest-docs/config/watch.md +0 -11
- package/public/vendor/vitest-docs/config/watchtriggerpatterns.md +0 -29
- package/public/vendor/vitest-docs/guide/advanced/index.md +0 -147
- package/public/vendor/vitest-docs/guide/advanced/pool.md +0 -148
- package/public/vendor/vitest-docs/guide/advanced/reporters.md +0 -93
- package/public/vendor/vitest-docs/guide/advanced/tests.md +0 -125
- package/public/vendor/vitest-docs/guide/browser/aria-snapshots.md +0 -470
- package/public/vendor/vitest-docs/guide/browser/component-testing.md +0 -571
- package/public/vendor/vitest-docs/guide/browser/index.md +0 -630
- package/public/vendor/vitest-docs/guide/browser/multiple-setups.md +0 -121
- package/public/vendor/vitest-docs/guide/browser/trace-view.md +0 -126
- package/public/vendor/vitest-docs/guide/browser/visual-regression-testing.md +0 -734
- package/public/vendor/vitest-docs/guide/cli-generated.md +0 -972
- package/public/vendor/vitest-docs/guide/cli.md +0 -234
- package/public/vendor/vitest-docs/guide/common-errors.md +0 -163
- package/public/vendor/vitest-docs/guide/coverage.md +0 -515
- package/public/vendor/vitest-docs/guide/debugging.md +0 -127
- package/public/vendor/vitest-docs/guide/environment.md +0 -101
- package/public/vendor/vitest-docs/guide/extending-matchers.md +0 -160
- package/public/vendor/vitest-docs/guide/features.md +0 -310
- package/public/vendor/vitest-docs/guide/filtering.md +0 -175
- package/public/vendor/vitest-docs/guide/ide.md +0 -43
- package/public/vendor/vitest-docs/guide/improving-performance.md +0 -245
- package/public/vendor/vitest-docs/guide/in-source.md +0 -159
- package/public/vendor/vitest-docs/guide/index.md +0 -128
- package/public/vendor/vitest-docs/guide/learn/async.md +0 -147
- package/public/vendor/vitest-docs/guide/learn/debugging-tests.md +0 -210
- package/public/vendor/vitest-docs/guide/learn/matchers.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/mock-functions.md +0 -277
- package/public/vendor/vitest-docs/guide/learn/setup-teardown.md +0 -240
- package/public/vendor/vitest-docs/guide/learn/snapshots.md +0 -166
- package/public/vendor/vitest-docs/guide/learn/testing-in-practice.md +0 -430
- package/public/vendor/vitest-docs/guide/learn/writing-tests-with-ai.md +0 -127
- package/public/vendor/vitest-docs/guide/learn/writing-tests.md +0 -231
- package/public/vendor/vitest-docs/guide/lifecycle.md +0 -379
- package/public/vendor/vitest-docs/guide/migration.md +0 -863
- package/public/vendor/vitest-docs/guide/mocking/classes.md +0 -158
- package/public/vendor/vitest-docs/guide/mocking/dates.md +0 -52
- package/public/vendor/vitest-docs/guide/mocking/file-system.md +0 -74
- package/public/vendor/vitest-docs/guide/mocking/functions.md +0 -61
- package/public/vendor/vitest-docs/guide/mocking/globals.md +0 -20
- package/public/vendor/vitest-docs/guide/mocking/modules.md +0 -414
- package/public/vendor/vitest-docs/guide/mocking/requests.md +0 -114
- package/public/vendor/vitest-docs/guide/mocking/timers.md +0 -48
- package/public/vendor/vitest-docs/guide/mocking.md +0 -239
- package/public/vendor/vitest-docs/guide/open-telemetry.md +0 -156
- package/public/vendor/vitest-docs/guide/parallelism.md +0 -82
- package/public/vendor/vitest-docs/guide/profiling-test-performance.md +0 -243
- package/public/vendor/vitest-docs/guide/projects.md +0 -291
- package/public/vendor/vitest-docs/guide/recipes.md +0 -59
- package/public/vendor/vitest-docs/guide/reporters.md +0 -723
- package/public/vendor/vitest-docs/guide/snapshot.md +0 -620
- package/public/vendor/vitest-docs/guide/test-annotations.md +0 -103
- package/public/vendor/vitest-docs/guide/test-context.md +0 -902
- package/public/vendor/vitest-docs/guide/test-tags.md +0 -314
- package/public/vendor/vitest-docs/guide/testing-types.md +0 -149
- package/public/vendor/vitest-docs/guide/ui.md +0 -160
- package/public/vendor/vitest-docs/guide/using-plugins.md +0 -5
- package/public/vendor/vitest-docs/manifest.json +0 -1691
- package/resources/index.js +0 -166
- package/resources/indexes.js +0 -77
- package/resources/manifest-schema.js +0 -46
- package/resources/paths.js +0 -20
- package/resources/patterns.js +0 -22
- package/resources/upstream-docs.js +0 -22
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
# experimental
|
|
2
|
-
|
|
3
|
-
## experimental.fsModuleCache <Version type="experimental">4.0.11</Version> {#experimental-fsmodulecache}
|
|
4
|
-
|
|
5
|
-
::: tip FEEDBACK
|
|
6
|
-
Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9221).
|
|
7
|
-
:::
|
|
8
|
-
|
|
9
|
-
- **Type:** `boolean`
|
|
10
|
-
- **Default:** `false`
|
|
11
|
-
|
|
12
|
-
Enabling this option allows Vitest to keep cached modules on the file system, making tests run faster between reruns.
|
|
13
|
-
|
|
14
|
-
You can delete the old cache by running [`vitest --clearCache`](/guide/cli#clearcache).
|
|
15
|
-
|
|
16
|
-
::: warning BROWSER SUPPORT
|
|
17
|
-
At the moment, this option does not affect [the browser](/guide/browser/).
|
|
18
|
-
:::
|
|
19
|
-
|
|
20
|
-
You can debug if your modules are cached by running vitest with a `DEBUG=vitest:cache:fs` environment variable:
|
|
21
|
-
|
|
22
|
-
```shell
|
|
23
|
-
DEBUG=vitest:cache:fs vitest --experimental.fsModuleCache
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Known Issues
|
|
27
|
-
|
|
28
|
-
Vitest creates a persistent file hash based on file content, its id, Vite's environment configuration and coverage status. Vitest tries to use as much information as it has about the configuration, but it is still incomplete. At the moment, it is not possible to track your plugin options because there is no standard interface for it.
|
|
29
|
-
|
|
30
|
-
If you have a plugin that relies on things outside the file content or the public configuration (like reading another file or a folder), it's possible that the cache will get stale. To work around that, you can define a [cache key generator](/api/advanced/plugin#definecachekeygenerator) to specify a dynamic option or to opt out of caching for that module:
|
|
31
|
-
|
|
32
|
-
```js [vitest.config.js]
|
|
33
|
-
import { defineConfig } from 'vitest/config'
|
|
34
|
-
|
|
35
|
-
export default defineConfig({
|
|
36
|
-
plugins: [
|
|
37
|
-
{
|
|
38
|
-
name: 'vitest-cache',
|
|
39
|
-
configureVitest({ experimental_defineCacheKeyGenerator }) {
|
|
40
|
-
experimental_defineCacheKeyGenerator(({ id, sourceCode }) => {
|
|
41
|
-
// never cache this id
|
|
42
|
-
if (id.includes('do-not-cache')) {
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// cache this file based on the value of a dynamic variable
|
|
47
|
-
if (sourceCode.includes('myDynamicVar')) {
|
|
48
|
-
return process.env.DYNAMIC_VAR_VALUE
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
test: {
|
|
55
|
-
experimental: {
|
|
56
|
-
fsModuleCache: true,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
If you are a plugin author, consider defining a [cache key generator](/api/advanced/plugin#definecachekeygenerator) in your plugin if it can be registered with different options that affect the transform result.
|
|
63
|
-
|
|
64
|
-
On the other hand, if your plugin should not affect the cache key, you can opt out by setting `api.vitest.experimental.ignoreFsModuleCache` to `true`:
|
|
65
|
-
|
|
66
|
-
```js [vitest.config.js]
|
|
67
|
-
import { defineConfig } from 'vitest/config'
|
|
68
|
-
|
|
69
|
-
export default defineConfig({
|
|
70
|
-
plugins: [
|
|
71
|
-
{
|
|
72
|
-
name: 'vitest-cache',
|
|
73
|
-
api: {
|
|
74
|
-
vitest: {
|
|
75
|
-
experimental: {
|
|
76
|
-
ignoreFsModuleCache: true,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
test: {
|
|
83
|
-
experimental: {
|
|
84
|
-
fsModuleCache: true,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Note that you can still define the cache key generator even if the plugin opts out of module caching.
|
|
91
|
-
|
|
92
|
-
## experimental.fsModuleCachePath <Version type="experimental">4.0.11</Version> {#experimental-fsmodulecachepath}
|
|
93
|
-
|
|
94
|
-
- **Type:** `string`
|
|
95
|
-
- **Default:** `'node_modules/.experimental-vitest-cache'`
|
|
96
|
-
|
|
97
|
-
Directory where the file system cache is located.
|
|
98
|
-
|
|
99
|
-
By default, Vitest will try to find the workspace root and store the cache inside the `node_modules` folder. The root is based on your package manager's lockfile (for example, `.package-lock.json`, `.yarn-state.yml`, `.pnpm/lock.yaml` and so on).
|
|
100
|
-
|
|
101
|
-
At the moment, Vitest ignores the [test.cache.dir](/config/cache) or [cacheDir](https://vite.dev/config/shared-options#cachedir) options completely and creates a separate folder.
|
|
102
|
-
|
|
103
|
-
## experimental.openTelemetry <Version type="experimental">4.0.11</Version> {#experimental-opentelemetry}
|
|
104
|
-
|
|
105
|
-
::: tip FEEDBACK
|
|
106
|
-
Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9222).
|
|
107
|
-
:::
|
|
108
|
-
|
|
109
|
-
- **Type:**
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
interface OpenTelemetryOptions {
|
|
113
|
-
enabled: boolean
|
|
114
|
-
/**
|
|
115
|
-
* A path to a file that exposes an OpenTelemetry SDK for Node.js.
|
|
116
|
-
*/
|
|
117
|
-
sdkPath?: string
|
|
118
|
-
/**
|
|
119
|
-
* A path to a file that exposes an OpenTelemetry SDK for the browser.
|
|
120
|
-
*/
|
|
121
|
-
browserSdkPath?: string
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
- **Default:** `{ enabled: false }`
|
|
126
|
-
|
|
127
|
-
This option controls [OpenTelemetry](https://opentelemetry.io/) support. Vitest imports the SDK file in the main thread and before every test file, if `enabled` is set to `true`.
|
|
128
|
-
|
|
129
|
-
::: danger PERFORMANCE CONCERNS
|
|
130
|
-
OpenTelemetry may significantly impact Vitest performance; enable it only for local debugging.
|
|
131
|
-
:::
|
|
132
|
-
|
|
133
|
-
You can use a [custom service](/guide/open-telemetry) together with Vitest to pinpoint which tests or files are slowing down your test suite.
|
|
134
|
-
|
|
135
|
-
For browser mode, see the [Browser Mode](/guide/open-telemetry#browser-mode) section of the OpenTelemetry guide.
|
|
136
|
-
|
|
137
|
-
An `sdkPath` is resolved relative to the [`root`](/config/root) of the project and should point to a module that exposes a started SDK instance as a default export. For example:
|
|
138
|
-
|
|
139
|
-
::: code-group
|
|
140
|
-
```js [otel.js]
|
|
141
|
-
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
|
|
142
|
-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
|
|
143
|
-
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
144
|
-
|
|
145
|
-
const sdk = new NodeSDK({
|
|
146
|
-
serviceName: 'vitest',
|
|
147
|
-
traceExporter: new OTLPTraceExporter(),
|
|
148
|
-
instrumentations: [getNodeAutoInstrumentations()],
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
sdk.start()
|
|
152
|
-
export default sdk
|
|
153
|
-
```
|
|
154
|
-
```js [vitest.config.js]
|
|
155
|
-
import { defineConfig } from 'vitest/config'
|
|
156
|
-
|
|
157
|
-
export default defineConfig({
|
|
158
|
-
test: {
|
|
159
|
-
experimental: {
|
|
160
|
-
openTelemetry: {
|
|
161
|
-
enabled: true,
|
|
162
|
-
sdkPath: './otel.js',
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
})
|
|
167
|
-
```
|
|
168
|
-
:::
|
|
169
|
-
|
|
170
|
-
::: warning
|
|
171
|
-
It's important that Node can process `sdkPath` content because it is not transformed by Vitest. See [the guide](/guide/open-telemetry) on how to work with OpenTelemetry inside of Vitest.
|
|
172
|
-
:::
|
|
173
|
-
|
|
174
|
-
## experimental.importDurations <Version type="experimental">4.1.0</Version> {#experimental-importdurations}
|
|
175
|
-
|
|
176
|
-
::: tip FEEDBACK
|
|
177
|
-
Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9224).
|
|
178
|
-
:::
|
|
179
|
-
|
|
180
|
-
- **Type:**
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
interface ImportDurationsOptions {
|
|
184
|
-
/**
|
|
185
|
-
* When to print import breakdown to CLI terminal.
|
|
186
|
-
* - false: Never print (default)
|
|
187
|
-
* - true: Always print
|
|
188
|
-
* - 'on-warn': Print only when any import exceeds warn threshold
|
|
189
|
-
*/
|
|
190
|
-
print?: boolean | 'on-warn'
|
|
191
|
-
/**
|
|
192
|
-
* Fail the test run if any import exceeds the danger threshold.
|
|
193
|
-
* When enabled and threshold exceeded, breakdown is always printed.
|
|
194
|
-
* @default false
|
|
195
|
-
*/
|
|
196
|
-
failOnDanger?: boolean
|
|
197
|
-
/**
|
|
198
|
-
* Maximum number of imports to collect and display.
|
|
199
|
-
*/
|
|
200
|
-
limit?: number
|
|
201
|
-
/**
|
|
202
|
-
* Duration thresholds in milliseconds for coloring and warnings.
|
|
203
|
-
*/
|
|
204
|
-
thresholds?: {
|
|
205
|
-
/** Threshold for yellow/warning color. @default 100 */
|
|
206
|
-
warn?: number
|
|
207
|
-
/** Threshold for red/danger color and failOnDanger. @default 500 */
|
|
208
|
-
danger?: number
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
- **Default:** `{ print: false, failOnDanger: false, limit: 0, thresholds: { warn: 100, danger: 500 } }` (`limit` is 10 if `print` or UI is enabled)
|
|
214
|
-
|
|
215
|
-
Configure import duration collection and display.
|
|
216
|
-
|
|
217
|
-
The `print` option controls CLI terminal output. The `limit` option controls how many imports to collect and display. [Vitest UI](/guide/ui#import-breakdown) can always toggle the breakdown display regardless of the `print` setting.
|
|
218
|
-
|
|
219
|
-
- Self: the time it took to import the module, excluding static imports;
|
|
220
|
-
- Total: the time it took to import the module, including static imports. Note that this does not include `transform` time of the current module.
|
|
221
|
-
|
|
222
|
-
<img alt="An example of import breakdown in the terminal" src="/reporter-import-breakdown.png" img-dark />
|
|
223
|
-
<img alt="An example of import breakdown in the terminal" src="/reporter-import-breakdown-light.png" img-light />
|
|
224
|
-
|
|
225
|
-
Note that if the file path is too long, Vitest will truncate it at the start until it fits 45 character limit.
|
|
226
|
-
|
|
227
|
-
### experimental.importDurations.print {#experimental-importdurationsprint}
|
|
228
|
-
|
|
229
|
-
- **Type:** `boolean | 'on-warn'`
|
|
230
|
-
- **Default:** `false`
|
|
231
|
-
|
|
232
|
-
Controls when to print import breakdown to CLI terminal after tests finish. This only works with [`default`](/guide/reporters#default), [`verbose`](/guide/reporters#verbose), or [`tree`](/guide/reporters#tree) reporters.
|
|
233
|
-
|
|
234
|
-
- `false`: Never print breakdown
|
|
235
|
-
- `true`: Always print breakdown
|
|
236
|
-
- `'on-warn'`: Print only when any import exceeds the `thresholds.warn` value
|
|
237
|
-
|
|
238
|
-
### experimental.importDurations.failOnDanger {#experimental-importdurationsfailondanger}
|
|
239
|
-
|
|
240
|
-
- **Type:** `boolean`
|
|
241
|
-
- **Default:** `false`
|
|
242
|
-
|
|
243
|
-
Fail the test run if any import exceeds the `thresholds.danger` value. When enabled and the threshold is exceeded, the breakdown is always printed regardless of the `print` setting.
|
|
244
|
-
|
|
245
|
-
This is useful for enforcing import performance budgets in CI:
|
|
246
|
-
|
|
247
|
-
```bash
|
|
248
|
-
vitest --experimental.importDurations.failOnDanger
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### experimental.importDurations.limit {#experimental-importdurationslimit}
|
|
252
|
-
|
|
253
|
-
- **Type:** `number`
|
|
254
|
-
- **Default:** `0` (or `10` if `print`, `failOnDanger`, or UI is enabled)
|
|
255
|
-
|
|
256
|
-
Maximum number of imports to collect and display in CLI output, [Vitest UI](/guide/ui#import-breakdown), and third-party reporters.
|
|
257
|
-
|
|
258
|
-
### experimental.importDurations.thresholds {#experimental-importdurationsthresholds}
|
|
259
|
-
|
|
260
|
-
- **Type:** `{ warn?: number; danger?: number }`
|
|
261
|
-
- **Default:** `{ warn: 100, danger: 500 }`
|
|
262
|
-
|
|
263
|
-
Duration thresholds in milliseconds for coloring and warnings:
|
|
264
|
-
|
|
265
|
-
- `warn`: Threshold for yellow/warning color (default: 100ms)
|
|
266
|
-
- `danger`: Threshold for red/danger color and `failOnDanger` (default: 500ms)
|
|
267
|
-
|
|
268
|
-
::: info
|
|
269
|
-
[Vitest UI](/guide/ui#import-breakdown) shows a breakdown of imports automatically if at least one file took longer than the `danger` threshold to load.
|
|
270
|
-
:::
|
|
271
|
-
|
|
272
|
-
## experimental.viteModuleRunner <Version type="experimental">4.1.0</Version> {#experimental-vitemodulerunner}
|
|
273
|
-
|
|
274
|
-
::: tip FEEDBACK
|
|
275
|
-
Please leave feedback regarding this feature in a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions/9501).
|
|
276
|
-
:::
|
|
277
|
-
|
|
278
|
-
- **Type:** `boolean`
|
|
279
|
-
- **Default:** `true`
|
|
280
|
-
|
|
281
|
-
Controls whether Vitest uses Vite's [module runner](https://vite.dev/guide/api-environment-runtimes#modulerunner) to run the code or fallback to the native `import`.
|
|
282
|
-
|
|
283
|
-
If this option is defined in the root config, all [projects](/guide/projects) will inherit it automatically.
|
|
284
|
-
|
|
285
|
-
Consider disabling the module runner if you are running tests in the same environment as your code (server backend or simple scripts, for example). However, we still recommend running `jsdom`/`happy-dom` tests with Vite's module runner or in [the browser](/guide/browser/) since it doesn't require any additional configuration.
|
|
286
|
-
|
|
287
|
-
Disabling this flag will disable _all_ file transforms:
|
|
288
|
-
|
|
289
|
-
- test files and your source code are not processed by Vite
|
|
290
|
-
- your global setup files are not processed
|
|
291
|
-
- your custom runner/pool/environment files are not processed
|
|
292
|
-
- your config file is still processed by Vite (this happens before Vitest knows the `viteModuleRunner` flag)
|
|
293
|
-
|
|
294
|
-
::: warning
|
|
295
|
-
At the moment, Vitest still requires Vite for certain functionality like the module graph or watch mode.
|
|
296
|
-
|
|
297
|
-
Also note that this option only works with `forks` or `threads` [pools](/config/pool).
|
|
298
|
-
:::
|
|
299
|
-
|
|
300
|
-
### Module Runner
|
|
301
|
-
|
|
302
|
-
By default, Vitest runs tests in a very permissive module runner sandbox powered by Vite's [Environment API](https://vite.dev/guide/api-environment.html#environment-api). Every file is categorized as either an "inline" module or an "external" module.
|
|
303
|
-
|
|
304
|
-
Module runner runs all "inlined" modules. It provides `import.meta.env`, `require`, `__dirname`, `__filename`, static `import`, and has its own module resolution mechanism. This makes it very easy to run code when you don't want to configure the environment and just need to test that the bare JavaScript logic you wrote works as intended.
|
|
305
|
-
|
|
306
|
-
All "external" modules run in native mode, meaning they are executed outside of the module runner sandbox. If you are running tests in Node.js, these files are imported with the native `import` keyword and processed by Node.js directly.
|
|
307
|
-
|
|
308
|
-
While running JSDOM/happy-dom tests in a permissive fake environment might be justified, running Node.js tests in a non-Node.js environment can hide and silence potential errors you may encounter in production, especially if your code doesn't require any additional transformations provided by Vite plugins.
|
|
309
|
-
|
|
310
|
-
### Known Limitations
|
|
311
|
-
|
|
312
|
-
Some Vitest features rely on files being transformed. Vitest uses synchronous [Node.js Loaders API](https://nodejs.org/api/module.html#customization-hooks) to transform test files and setup files to support these features:
|
|
313
|
-
|
|
314
|
-
- [`import.meta.vitest`](/guide/in-source)
|
|
315
|
-
- [`vi.mock`](/api/vi#vi-mock)
|
|
316
|
-
- [`vi.hoisted`](/api/vi#vi-hoisted)
|
|
317
|
-
|
|
318
|
-
::: warning
|
|
319
|
-
This means that Vitest requires at least Node 22.15 for those features to work. At the moment, they also do not work in Deno or Bun.
|
|
320
|
-
|
|
321
|
-
Vitest will only detect `vi.mock` and `vi.hoisted` inside of test files, they will not be hoisted inside imported modules.
|
|
322
|
-
:::
|
|
323
|
-
|
|
324
|
-
This could affect performance because Vitest needs to read the file and process it. If you do not use these features, you can disable the transforms by setting `experimental.nodeLoader` to `false`. Vitest only reads test files and setup files while looking for `vi.mock` or `vi.hoisted`. Using these in other files won't hoist them to the top of the file and can lead to unexpected behavior.
|
|
325
|
-
|
|
326
|
-
Some features will not work due to the nature of `viteModuleRunner`, including:
|
|
327
|
-
|
|
328
|
-
- no `import.meta.env`: `import.meta.env` is a Vite feature, use `process.env` instead
|
|
329
|
-
- no `plugins`: plugins are not applied because there is no transformation phase, use [customization hooks](https://nodejs.org/api/module.html#customization-hooks) via [`execArgv`](/config/execargv) instead
|
|
330
|
-
- no `alias`: aliases are not applied because there is no transformation phase
|
|
331
|
-
- `istanbul` coverage provider doesn't work because there is no transformation phase, use `v8` instead
|
|
332
|
-
- `vi.resetModules()`: there is no API to invalidate ES modules from the module cache
|
|
333
|
-
|
|
334
|
-
::: warning Coverage Support
|
|
335
|
-
At the moment Vitest supports coverage via `v8` provider as long as files can be transformed into JavaScript. To transform TypeScript, Vitest uses [`module.stripTypeScriptTypes`](https://nodejs.org/api/module.html#modulestriptypescripttypescode-options) which is available in Node.js since v22.13. If you are using a custom [module loader](https://nodejs.org/api/module.html#customization-hooks), Vitest is not able to reuse it to transform files for analysis.
|
|
336
|
-
:::
|
|
337
|
-
|
|
338
|
-
With regards to mocking, it is also important to point out that ES modules do not support property override. This means that code like this won't work anymore:
|
|
339
|
-
|
|
340
|
-
```ts
|
|
341
|
-
import * as fs from 'node:fs'
|
|
342
|
-
import { vi } from 'vitest'
|
|
343
|
-
|
|
344
|
-
vi.spyOn(fs, 'readFileSync').mockImplementation(() => '42') // ❌
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
However, Vitest supports auto-spying on modules without overriding their implementation. When `vi.mock` is called with a `spy: true` argument, the module is mocked in a way that preserves original implementations, but all exported functions are wrapped in a `vi.fn()` spy:
|
|
348
|
-
|
|
349
|
-
```ts
|
|
350
|
-
import * as fs from 'node:fs'
|
|
351
|
-
import { vi } from 'vitest'
|
|
352
|
-
|
|
353
|
-
vi.mock('node:fs', { spy: true })
|
|
354
|
-
|
|
355
|
-
fs.readFileSync.mockImplementation(() => '42') // ✅
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
Factory mocking is implemented using a top-level await. This means that mocked modules cannot be loaded with `require()` in your source code:
|
|
359
|
-
|
|
360
|
-
```ts
|
|
361
|
-
vi.mock('node:fs', async (importOriginal) => {
|
|
362
|
-
return {
|
|
363
|
-
...await importOriginal(),
|
|
364
|
-
readFileSync: vi.fn(),
|
|
365
|
-
}
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
const fs = require('node:fs') // throws an error
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
This limitation exists because factories can be asynchronous. This should not be a problem because Vitest doesn't mock builtin modules inside `node_modules`, which is similar to how Vitest works by default.
|
|
372
|
-
|
|
373
|
-
### TypeScript
|
|
374
|
-
|
|
375
|
-
If you are using Node.js 22.18/23.6 or higher, TypeScript will be [transformed natively](https://nodejs.org/en/learn/typescript/run-natively) by Node.js.
|
|
376
|
-
|
|
377
|
-
::: warning TypeScript with Node.js 22.6-22.18
|
|
378
|
-
If you are using Node.js version between 22.6 and 22.18, you can also enable native TypeScript support via `--experimental-strip-types` flag:
|
|
379
|
-
|
|
380
|
-
```shell
|
|
381
|
-
NODE_OPTIONS="--experimental-strip-types" vitest
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
If you are using TypeScript and Node.js version lower than 22.6, then you will need to either:
|
|
385
|
-
|
|
386
|
-
- build your test files and source code and run those files directly
|
|
387
|
-
- import a [custom loader](https://nodejs.org/api/module.html#customization-hooks) via `execArgv` flag
|
|
388
|
-
|
|
389
|
-
```ts
|
|
390
|
-
import { defineConfig } from 'vitest/config'
|
|
391
|
-
|
|
392
|
-
const tsxApi = import.meta.resolve('tsx/esm/api')
|
|
393
|
-
|
|
394
|
-
export default defineConfig({
|
|
395
|
-
test: {
|
|
396
|
-
execArgv: [
|
|
397
|
-
`--import=data:text/javascript,import * as tsx from "${tsxApi}";tsx.register()`,
|
|
398
|
-
],
|
|
399
|
-
experimental: {
|
|
400
|
-
viteModuleRunner: false,
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
})
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
If you are running tests in Deno, TypeScript files are processed by the runtime without any additional configurations.
|
|
407
|
-
:::
|
|
408
|
-
|
|
409
|
-
## experimental.vcsProvider <Version type="experimental">4.1.1</Version> {#experimental-vcsprovider}
|
|
410
|
-
|
|
411
|
-
- **Type:** `VCSProvider | string`
|
|
412
|
-
|
|
413
|
-
```ts
|
|
414
|
-
interface VCSProvider {
|
|
415
|
-
findChangedFiles(options: VCSProviderOptions): Promise<string[]>
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
interface VCSProviderOptions {
|
|
419
|
-
root: string
|
|
420
|
-
changedSince?: string | boolean
|
|
421
|
-
}
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
- **Default:** `'git'`
|
|
425
|
-
|
|
426
|
-
Custom provider for detecting changed files. Used with the [`--changed`](/guide/cli#changed) flag to determine which files have been modified.
|
|
427
|
-
|
|
428
|
-
By default, Vitest uses Git to detect changed files. You can provide a custom implementation of the `VCSProvider` interface to use a different version control system:
|
|
429
|
-
|
|
430
|
-
```ts [vitest.config.ts]
|
|
431
|
-
import { defineConfig } from 'vitest/config'
|
|
432
|
-
|
|
433
|
-
export default defineConfig({
|
|
434
|
-
test: {
|
|
435
|
-
experimental: {
|
|
436
|
-
vcsProvider: {
|
|
437
|
-
async findChangedFiles({ root, changedSince }) {
|
|
438
|
-
// return paths of changed files
|
|
439
|
-
return []
|
|
440
|
-
},
|
|
441
|
-
},
|
|
442
|
-
},
|
|
443
|
-
},
|
|
444
|
-
})
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
You can also pass a string path to a module with a default export that implements the `VCSProvider` interface:
|
|
448
|
-
|
|
449
|
-
```js [vitest.config.js]
|
|
450
|
-
import { defineConfig } from 'vitest/config'
|
|
451
|
-
|
|
452
|
-
export default defineConfig({
|
|
453
|
-
test: {
|
|
454
|
-
experimental: {
|
|
455
|
-
vcsProvider: './my-vcs-provider.js',
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
})
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
```js [my-vcs-provider.js]
|
|
462
|
-
export default {
|
|
463
|
-
async findChangedFiles({ root, changedSince }) {
|
|
464
|
-
// return paths of changed files
|
|
465
|
-
return []
|
|
466
|
-
},
|
|
467
|
-
}
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
## experimental.nodeLoader <Version type="experimental">4.1.0</Version> {#experimental-nodeloader}
|
|
471
|
-
|
|
472
|
-
- **Type:** `boolean`
|
|
473
|
-
- **Default:** `true`
|
|
474
|
-
|
|
475
|
-
If module runner is disabled, Vitest uses a native [Node.js module loader](https://nodejs.org/api/module.html#customization-hooks) to transform files to support `import.meta.vitest`, `vi.mock` and `vi.hoisted`.
|
|
476
|
-
|
|
477
|
-
If you don't use these features, you can disable this to improve performance.
|
|
478
|
-
|
|
479
|
-
## experimental.preParse <Version type="experimental">4.1.3</Version> {#experimental-preparse}
|
|
480
|
-
|
|
481
|
-
- **Type:** `boolean`
|
|
482
|
-
- **Default:** `false`
|
|
483
|
-
|
|
484
|
-
Parses test specifications before running them. This applies the [`.only`](/api/test#test-only) modifier, the [`-t`](/config/testnamepattern) test name pattern, [`--tags-filter`](/guide/test-tags#syntax), [test lines](/api/advanced/test-specification#testlines), and [test IDs](/api/advanced/test-specification#testids) across all files without executing them. For example, if only a single test is marked with `.only`, Vitest will skip all other tests in all files.
|
|
485
|
-
|
|
486
|
-
::: tip
|
|
487
|
-
This option is recommended when using [`.only`](/api/test#test-only), the [`-t`](/config/testnamepattern) flag, or [`--tags-filter`](/guide/test-tags#syntax).
|
|
488
|
-
|
|
489
|
-
Enabling it unconditionally may slow down your test runs due to the additional parsing step.
|
|
490
|
-
:::
|
|
491
|
-
|
|
492
|
-
::: warning
|
|
493
|
-
Pre-parsing uses static analysis (AST parsing) instead of executing your test files. This means that test names, tags, and modifiers (`.only`, `.skip`, `.todo`) must be statically analyzable. Dynamic test names (e.g., names stored in variables or returned from function calls) and non-literal tags will not be resolved correctly.
|
|
494
|
-
|
|
495
|
-
```ts
|
|
496
|
-
// ✅ works — static string literal
|
|
497
|
-
test('adds numbers', () => {})
|
|
498
|
-
|
|
499
|
-
// ✅ works — static tags
|
|
500
|
-
test('my test', { tags: ['unit'] }, () => {})
|
|
501
|
-
|
|
502
|
-
// ❌ won't match correctly — dynamic name
|
|
503
|
-
const name = getName()
|
|
504
|
-
test(name, () => {})
|
|
505
|
-
|
|
506
|
-
// ❌ won't match correctly — dynamic tags
|
|
507
|
-
const tags = getTags()
|
|
508
|
-
test('my test', { tags }, () => {})
|
|
509
|
-
```
|
|
510
|
-
:::
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# fakeTimers
|
|
2
|
-
|
|
3
|
-
- **Type:** `FakeTimerInstallOpts`
|
|
4
|
-
|
|
5
|
-
Options that Vitest will pass down to [`@sinon/fake-timers`](https://npmx.dev/package/@sinonjs/fake-timers) when using [`vi.useFakeTimers()`](/api/vi#vi-usefaketimers).
|
|
6
|
-
|
|
7
|
-
## fakeTimers.now
|
|
8
|
-
|
|
9
|
-
- **Type:** `number | Date`
|
|
10
|
-
- **Default:** `Date.now()`
|
|
11
|
-
|
|
12
|
-
Installs fake timers with the specified Unix epoch.
|
|
13
|
-
|
|
14
|
-
## fakeTimers.toFake
|
|
15
|
-
|
|
16
|
-
- **Type:** `('setTimeout' | 'clearTimeout' | 'setImmediate' | 'clearImmediate' | 'setInterval' | 'clearInterval' | 'Date' | 'nextTick' | 'hrtime' | 'requestAnimationFrame' | 'cancelAnimationFrame' | 'requestIdleCallback' | 'cancelIdleCallback' | 'performance' | 'queueMicrotask')[]`
|
|
17
|
-
- **Default:** everything available globally except `nextTick` and `queueMicrotask`
|
|
18
|
-
|
|
19
|
-
An array with names of global methods and APIs to fake.
|
|
20
|
-
|
|
21
|
-
To only mock `setTimeout()` and `nextTick()`, specify this property as `['setTimeout', 'nextTick']`.
|
|
22
|
-
|
|
23
|
-
Mocking `nextTick` is not supported when running Vitest inside `node:child_process` by using `--pool=forks`. NodeJS uses `process.nextTick` internally in `node:child_process` and hangs when it is mocked. Mocking `nextTick` is supported when running Vitest with `--pool=threads`.
|
|
24
|
-
|
|
25
|
-
## fakeTimers.loopLimit
|
|
26
|
-
|
|
27
|
-
- **Type:** `number`
|
|
28
|
-
- **Default:** `10_000`
|
|
29
|
-
|
|
30
|
-
The maximum number of timers that will be run when calling [`vi.runAllTimers()`](/api/vi#vi-runalltimers).
|
|
31
|
-
|
|
32
|
-
## fakeTimers.shouldAdvanceTime
|
|
33
|
-
|
|
34
|
-
- **Type:** `boolean`
|
|
35
|
-
- **Default:** `false`
|
|
36
|
-
|
|
37
|
-
Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by 20ms for every 20ms change in the real system time).
|
|
38
|
-
|
|
39
|
-
## fakeTimers.advanceTimeDelta
|
|
40
|
-
|
|
41
|
-
- **Type:** `number`
|
|
42
|
-
- **Default:** `20`
|
|
43
|
-
|
|
44
|
-
Relevant only when using with `shouldAdvanceTime: true`. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change in the real system time.
|
|
45
|
-
|
|
46
|
-
## fakeTimers.shouldClearNativeTimers
|
|
47
|
-
|
|
48
|
-
- **Type:** `boolean`
|
|
49
|
-
- **Default:** `true`
|
|
50
|
-
|
|
51
|
-
Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# fileParallelism
|
|
2
|
-
|
|
3
|
-
- **Type:** `boolean`
|
|
4
|
-
- **Default:** `true`
|
|
5
|
-
- **CLI:** `--no-file-parallelism`, `--fileParallelism=false`
|
|
6
|
-
|
|
7
|
-
Should all test files run in parallel. Setting this to `false` will override `maxWorkers` option to `1`.
|
|
8
|
-
|
|
9
|
-
::: tip
|
|
10
|
-
This option doesn't affect tests running in the same file. If you want to run those in parallel, use `concurrent` option on [describe](/api/describe#describe-concurrent) or via [a config](/config/sequence#sequence-concurrent).
|
|
11
|
-
:::
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# forceRerunTriggers <CRoot />
|
|
2
|
-
|
|
3
|
-
- **Type:** `string[]`
|
|
4
|
-
- **Default:** `['**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**']`
|
|
5
|
-
|
|
6
|
-
Glob pattern of file paths that will trigger the whole suite rerun. When paired with the `--changed` argument will run the whole test suite if the trigger is found in the git diff.
|
|
7
|
-
|
|
8
|
-
Useful if you are testing calling CLI commands, because Vite cannot construct a module graph:
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
test('execute a script', async () => {
|
|
12
|
-
// Vitest cannot rerun this test, if content of `dist/index.js` changes
|
|
13
|
-
await execa('node', ['dist/index.js'])
|
|
14
|
-
})
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
::: tip
|
|
18
|
-
Make sure that your files are not excluded by [`server.watch.ignored`](https://vitejs.dev/config/server-options.html#server-watch).
|
|
19
|
-
:::
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# globals
|
|
2
|
-
|
|
3
|
-
- **Type:** `boolean`
|
|
4
|
-
- **Default:** `false`
|
|
5
|
-
- **CLI:** `--globals`, `--no-globals`, `--globals=false`
|
|
6
|
-
|
|
7
|
-
By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--globals` option to CLI or add `globals: true` in the config.
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import { defineConfig } from 'vitest/config'
|
|
11
|
-
|
|
12
|
-
export default defineConfig({
|
|
13
|
-
test: {
|
|
14
|
-
globals: true,
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
::: tip
|
|
20
|
-
Note that some libraries, e.g., `@testing-library/react`, rely on globals being present to perform auto cleanup.
|
|
21
|
-
:::
|
|
22
|
-
|
|
23
|
-
To get TypeScript working with the global APIs, add `vitest/globals` to the `types` field in your `tsconfig.json`:
|
|
24
|
-
|
|
25
|
-
```json [tsconfig.json]
|
|
26
|
-
{
|
|
27
|
-
"compilerOptions": {
|
|
28
|
-
"types": ["vitest/globals"]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
If you have redefined your [`typeRoots`](https://www.typescriptlang.org/tsconfig/#typeRoots) to include additional types in your compilation, you will need to add back the `node_modules` to make `vitest/globals` discoverable:
|
|
34
|
-
|
|
35
|
-
```json [tsconfig.json]
|
|
36
|
-
{
|
|
37
|
-
"compilerOptions": {
|
|
38
|
-
"typeRoots": ["./types", "./node_modules/@types", "./node_modules"],
|
|
39
|
-
"types": ["vitest/globals"]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
```
|