@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,214 +0,0 @@
|
|
|
1
|
-
# Configuring Playwright
|
|
2
|
-
|
|
3
|
-
To run tests using playwright, you need to install the [`@vitest/browser-playwright`](https://npmx.dev/package/@vitest/browser-playwright) npm package and specify its `playwright` export in the `test.browser.provider` property of your config:
|
|
4
|
-
|
|
5
|
-
```ts [vitest.config.js]
|
|
6
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
7
|
-
import { defineConfig } from 'vitest/config'
|
|
8
|
-
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
test: {
|
|
11
|
-
browser: {
|
|
12
|
-
provider: playwright(),
|
|
13
|
-
instances: [{ browser: 'chromium' }]
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
You can configure the [`launchOptions`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch), [`connectOptions`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect) and [`contextOptions`](https://playwright.dev/docs/api/class-browser#browser-new-context) when calling `playwright` at the top level or inside instances:
|
|
20
|
-
|
|
21
|
-
```ts{7-14,21-26} [vitest.config.js]
|
|
22
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
23
|
-
import { defineConfig } from 'vitest/config'
|
|
24
|
-
|
|
25
|
-
export default defineConfig({
|
|
26
|
-
test: {
|
|
27
|
-
browser: {
|
|
28
|
-
// shared provider options between all instances
|
|
29
|
-
provider: playwright({
|
|
30
|
-
launchOptions: {
|
|
31
|
-
slowMo: 50,
|
|
32
|
-
channel: 'chrome-beta',
|
|
33
|
-
},
|
|
34
|
-
actionTimeout: 5_000,
|
|
35
|
-
}),
|
|
36
|
-
instances: [
|
|
37
|
-
{ browser: 'chromium' },
|
|
38
|
-
{
|
|
39
|
-
browser: 'firefox',
|
|
40
|
-
// overriding options only for a single instance
|
|
41
|
-
// this will NOT merge options with the parent one
|
|
42
|
-
provider: playwright({
|
|
43
|
-
launchOptions: {
|
|
44
|
-
firefoxUserPrefs: {
|
|
45
|
-
'browser.startup.homepage': 'https://example.com',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
})
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
::: warning
|
|
57
|
-
Unlike Playwright test runner, Vitest opens a _single_ page to run all tests that are defined in the same file. This means that isolation is restricted to a single test file, not to every individual test.
|
|
58
|
-
:::
|
|
59
|
-
|
|
60
|
-
## launchOptions
|
|
61
|
-
|
|
62
|
-
These options are directly passed down to `playwright[browser].launch` command. You can read more about the command and available arguments in the [Playwright documentation](https://playwright.dev/docs/api/class-browsertype#browser-type-launch).
|
|
63
|
-
|
|
64
|
-
::: warning
|
|
65
|
-
Vitest will ignore `launch.headless` option. Instead, use [`test.browser.headless`](/config/browser/headless).
|
|
66
|
-
|
|
67
|
-
Note that Vitest will push debugging flags to `launch.args` if [`--inspect`](/guide/cli#inspect) is enabled.
|
|
68
|
-
:::
|
|
69
|
-
|
|
70
|
-
::: tip Enabling new Chromium headless mode
|
|
71
|
-
Playwright supports a [new headless mode](https://playwright.dev/docs/browsers#chromium-new-headless-mode) for Chromium that uses the real Chrome browser instead of the dedicated headless shell. This provides more authentic, reliable test execution and removes the need to install a separate headless Chromium build.
|
|
72
|
-
|
|
73
|
-
To opt in, set `channel` to `'chromium'` in `launchOptions`:
|
|
74
|
-
|
|
75
|
-
```ts [vitest.config.ts]
|
|
76
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
77
|
-
import { defineConfig } from 'vitest/config'
|
|
78
|
-
|
|
79
|
-
export default defineConfig({
|
|
80
|
-
test: {
|
|
81
|
-
browser: {
|
|
82
|
-
headless: true,
|
|
83
|
-
provider: playwright({
|
|
84
|
-
launchOptions: {
|
|
85
|
-
channel: 'chromium',
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
instances: [{ browser: 'chromium' }],
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
})
|
|
92
|
-
```
|
|
93
|
-
:::
|
|
94
|
-
|
|
95
|
-
## connectOptions
|
|
96
|
-
|
|
97
|
-
These options are directly passed down to `playwright[browser].connect` command. You can read more about the command and available arguments in the [Playwright documentation](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
|
|
98
|
-
|
|
99
|
-
Use `connectOptions.wsEndpoint` to connect to an existing Playwright server instead of launching browsers locally. This is useful for running browsers in Docker, in CI, or on a remote machine.
|
|
100
|
-
|
|
101
|
-
::: warning
|
|
102
|
-
|
|
103
|
-
Vitest forwards `launchOptions` to Playwright server via the `x-playwright-launch-options` header. This works only if the remote Playwright server supports this header, for example when using the `playwright run-server` CLI.
|
|
104
|
-
|
|
105
|
-
:::
|
|
106
|
-
|
|
107
|
-
::: details Example: Running a Playwright Server in Docker
|
|
108
|
-
To run browsers in a Docker container (see [Playwright Docker guide](https://playwright.dev/docs/docker#remote-connection)):
|
|
109
|
-
|
|
110
|
-
Start a Playwright server using Docker Compose:
|
|
111
|
-
|
|
112
|
-
```yaml [docker-compose.yml]
|
|
113
|
-
services:
|
|
114
|
-
playwright:
|
|
115
|
-
image: mcr.microsoft.com/playwright:v1.58.1-noble
|
|
116
|
-
command: /bin/sh -c "npx -y playwright@1.58.1 run-server --port 6677 --host 0.0.0.0"
|
|
117
|
-
init: true
|
|
118
|
-
ipc: host
|
|
119
|
-
user: pwuser
|
|
120
|
-
ports:
|
|
121
|
-
- '6677:6677'
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
```sh
|
|
125
|
-
docker compose up -d
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Then configure Vitest to connect to it. The [`exposeNetwork`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-option-expose-network) option lets the containerized browser reach Vitest's dev server on the host:
|
|
129
|
-
|
|
130
|
-
```ts [vitest.config.ts]
|
|
131
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
132
|
-
import { defineConfig } from 'vitest/config'
|
|
133
|
-
|
|
134
|
-
export default defineConfig({
|
|
135
|
-
test: {
|
|
136
|
-
browser: {
|
|
137
|
-
provider: playwright({
|
|
138
|
-
connectOptions: {
|
|
139
|
-
wsEndpoint: 'ws://127.0.0.1:6677/',
|
|
140
|
-
exposeNetwork: '<loopback>',
|
|
141
|
-
},
|
|
142
|
-
}),
|
|
143
|
-
instances: [
|
|
144
|
-
{ browser: 'chromium' },
|
|
145
|
-
{ browser: 'firefox' },
|
|
146
|
-
{ browser: 'webkit' },
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
```
|
|
152
|
-
:::
|
|
153
|
-
|
|
154
|
-
## contextOptions
|
|
155
|
-
|
|
156
|
-
Vitest creates a new context for every test file by calling [`browser.newContext()`](https://playwright.dev/docs/api/class-browsercontext). You can configure this behaviour by specifying [custom arguments](https://playwright.dev/docs/api/class-browser#browser-new-context).
|
|
157
|
-
|
|
158
|
-
::: tip
|
|
159
|
-
Note that the context is created for every _test file_, not every _test_ like in playwright test runner.
|
|
160
|
-
:::
|
|
161
|
-
|
|
162
|
-
::: warning
|
|
163
|
-
Vitest always sets `ignoreHTTPSErrors` to `true` in case your server is served via HTTPS and `serviceWorkers` to `'allow'` to support module mocking via [MSW](https://mswjs.io).
|
|
164
|
-
|
|
165
|
-
It is also recommended to use [`test.browser.viewport`](/config/browser/headless) instead of specifying it here as it will be lost when tests are running in headless mode.
|
|
166
|
-
:::
|
|
167
|
-
|
|
168
|
-
## `actionTimeout`
|
|
169
|
-
|
|
170
|
-
- **Default:** no timeout
|
|
171
|
-
|
|
172
|
-
This value configures the default timeout it takes for Playwright to wait until all accessibility checks pass and [the action](/api/browser/interactivity) is actually done.
|
|
173
|
-
|
|
174
|
-
You can also configure the action timeout per-action:
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
import { page, userEvent } from 'vitest/browser'
|
|
178
|
-
|
|
179
|
-
await userEvent.click(page.getByRole('button'), {
|
|
180
|
-
timeout: 1_000,
|
|
181
|
-
})
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## `persistentContext` <Version>4.1.0</Version> {#persistentcontext}
|
|
185
|
-
|
|
186
|
-
- **Type:** `boolean | string`
|
|
187
|
-
- **Default:** `false`
|
|
188
|
-
|
|
189
|
-
When enabled, Vitest uses Playwright's [persistent context](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context) instead of a regular browser context. This allows browser state (cookies, localStorage, DevTools settings, etc.) to persist between test runs.
|
|
190
|
-
|
|
191
|
-
::: warning
|
|
192
|
-
This option is ignored when running tests in parallel (e.g. when headless with [`fileParallelism`](/config/fileparallelism) enabled) since persistent context cannot be shared across parallel sessions.
|
|
193
|
-
:::
|
|
194
|
-
|
|
195
|
-
- When set to `true`, the user data is stored in `./node_modules/.cache/vitest-playwright-user-data`
|
|
196
|
-
- When set to a string, the value is used as the path to the user data directory
|
|
197
|
-
|
|
198
|
-
```ts [vitest.config.js]
|
|
199
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
200
|
-
import { defineConfig } from 'vitest/config'
|
|
201
|
-
|
|
202
|
-
export default defineConfig({
|
|
203
|
-
test: {
|
|
204
|
-
browser: {
|
|
205
|
-
provider: playwright({
|
|
206
|
-
persistentContext: true,
|
|
207
|
-
// or specify a custom directory:
|
|
208
|
-
// persistentContext: './my-browser-data',
|
|
209
|
-
}),
|
|
210
|
-
instances: [{ browser: 'chromium' }],
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
```
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Configuring Preview
|
|
2
|
-
|
|
3
|
-
::: warning
|
|
4
|
-
The `preview` provider's main functionality is to show tests in a real browser environment. However, it does not support advanced browser automation features like multiple browser instances or headless mode. For more complex scenarios, consider using [Playwright](/config/browser/playwright) or [WebdriverIO](/config/browser/webdriverio).
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
To see your tests running in a real browser, you need to install the [`@vitest/browser-preview`](https://npmx.dev/package/@vitest/browser-preview) npm package and specify its `preview` export in the `test.browser.provider` property of your config:
|
|
8
|
-
|
|
9
|
-
```ts [vitest.config.js]
|
|
10
|
-
import { preview } from '@vitest/browser-preview'
|
|
11
|
-
import { defineConfig } from 'vitest/config'
|
|
12
|
-
|
|
13
|
-
export default defineConfig({
|
|
14
|
-
test: {
|
|
15
|
-
browser: {
|
|
16
|
-
provider: preview(),
|
|
17
|
-
instances: [{ browser: 'chromium' }]
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
This will open a new browser window using your default browser to run the tests. You can configure which browser to use by setting the `browser` property in the `instances` array. Vitest will try to open that browser automatically, but it might not work in some environments. In that case, you can manually open the provided URL in your desired browser.
|
|
24
|
-
|
|
25
|
-
## Differences with Other Providers
|
|
26
|
-
|
|
27
|
-
The preview provider has some limitations compared to other providers like [Playwright](/config/browser/playwright) or [WebdriverIO](/config/browser/webdriverio):
|
|
28
|
-
|
|
29
|
-
- It does not support headless mode; the browser window will always be visible.
|
|
30
|
-
- It does not support multiple instances of the same browser; each instance must use a different browser.
|
|
31
|
-
- It does not support advanced browser capabilities or options; you can only specify the browser name.
|
|
32
|
-
- It does not support CDP (Chrome DevTools Protocol) commands or other low-level browser interactions. Unlike Playwright or WebdriverIO, the [`userEvent`](/api/browser/interactivity) API is just re-exported from [`@testing-library/user-event`](https://npmx.dev/package/@testing-library/user-event) and does not have any special integration with the browser.
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# browser.provider {#browser-provider}
|
|
2
|
-
|
|
3
|
-
- **Type:** `BrowserProviderOption`
|
|
4
|
-
|
|
5
|
-
The return value of the provider factory. You can import the factory from `@vitest/browser-<provider-name>` or make your own provider:
|
|
6
|
-
|
|
7
|
-
```ts{8-10}
|
|
8
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
9
|
-
import { webdriverio } from '@vitest/browser-webdriverio'
|
|
10
|
-
import { preview } from '@vitest/browser-preview'
|
|
11
|
-
|
|
12
|
-
export default defineConfig({
|
|
13
|
-
test: {
|
|
14
|
-
browser: {
|
|
15
|
-
provider: playwright(),
|
|
16
|
-
provider: webdriverio(),
|
|
17
|
-
provider: preview(),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
To configure how provider initializes the browser, you can pass down options to the factory function:
|
|
24
|
-
|
|
25
|
-
```ts{7-13,20-26}
|
|
26
|
-
import { playwright } from '@vitest/browser-playwright'
|
|
27
|
-
|
|
28
|
-
export default defineConfig({
|
|
29
|
-
test: {
|
|
30
|
-
browser: {
|
|
31
|
-
// shared provider options between all instances
|
|
32
|
-
provider: playwright({
|
|
33
|
-
launchOptions: {
|
|
34
|
-
slowMo: 50,
|
|
35
|
-
channel: 'chrome-beta',
|
|
36
|
-
},
|
|
37
|
-
actionTimeout: 5_000,
|
|
38
|
-
}),
|
|
39
|
-
instances: [
|
|
40
|
-
{ browser: 'chromium' },
|
|
41
|
-
{
|
|
42
|
-
browser: 'firefox',
|
|
43
|
-
// overriding options only for a single instance
|
|
44
|
-
// this will NOT merge options with the parent one
|
|
45
|
-
provider: playwright({
|
|
46
|
-
launchOptions: {
|
|
47
|
-
firefoxUserPrefs: {
|
|
48
|
-
'browser.startup.homepage': 'https://example.com',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Custom Provider <Badge type="danger">advanced</Badge> {#custom-provider}
|
|
60
|
-
|
|
61
|
-
::: danger ADVANCED API
|
|
62
|
-
The custom provider API is highly experimental and can change between patches. If you just need to run tests in a browser, use the [`browser.instances`](/config/browser/instances) option instead.
|
|
63
|
-
:::
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
export interface BrowserProvider {
|
|
67
|
-
name: string
|
|
68
|
-
mocker?: BrowserModuleMocker
|
|
69
|
-
readonly initScripts?: string[]
|
|
70
|
-
/**
|
|
71
|
-
* @experimental opt-in into file parallelisation
|
|
72
|
-
*/
|
|
73
|
-
supportsParallelism: boolean
|
|
74
|
-
getCommandsContext: (sessionId: string) => Record<string, unknown>
|
|
75
|
-
openPage: (sessionId: string, url: string) => Promise<void>
|
|
76
|
-
getCDPSession?: (sessionId: string) => Promise<CDPSession>
|
|
77
|
-
close: () => Awaitable<void>
|
|
78
|
-
}
|
|
79
|
-
```
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# browser.trace
|
|
2
|
-
|
|
3
|
-
- **Type:** `'on' | 'off' | 'on-first-retry' | 'on-all-retries' | 'retain-on-failure' | object`
|
|
4
|
-
- **CLI:** `--browser.trace=on`, `--browser.trace=retain-on-failure`
|
|
5
|
-
- **Default:** `'off'`
|
|
6
|
-
|
|
7
|
-
Capture a trace of your browser test runs. You can preview traces with [Playwright Trace Viewer](https://trace.playwright.dev/).
|
|
8
|
-
|
|
9
|
-
This options supports the following values:
|
|
10
|
-
|
|
11
|
-
- `'on'` - capture trace for all tests. (not recommended as it's performance heavy)
|
|
12
|
-
- `'off'` - do not capture traces.
|
|
13
|
-
- `'on-first-retry'` - capture trace only when retrying the test for the first time.
|
|
14
|
-
- `'on-all-retries'` - capture trace on every retry of the test.
|
|
15
|
-
- `'retain-on-failure'` - capture trace only for tests that fail. This will automatically delete traces for tests that pass.
|
|
16
|
-
- `object` - an object with the following shape:
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
interface TraceOptions {
|
|
20
|
-
mode: 'on' | 'off' | 'on-first-retry' | 'on-all-retries' | 'retain-on-failure'
|
|
21
|
-
/**
|
|
22
|
-
* The directory where all traces will be stored. By default, Vitest
|
|
23
|
-
* stores all traces in `__traces__` folder close to the test file.
|
|
24
|
-
*/
|
|
25
|
-
tracesDir?: string
|
|
26
|
-
/**
|
|
27
|
-
* Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.
|
|
28
|
-
* @default true
|
|
29
|
-
*/
|
|
30
|
-
screenshots?: boolean
|
|
31
|
-
/**
|
|
32
|
-
* If this option is true tracing will
|
|
33
|
-
* - capture DOM snapshot on every action
|
|
34
|
-
* - record network activity
|
|
35
|
-
* @default true
|
|
36
|
-
*/
|
|
37
|
-
snapshots?: boolean
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
::: danger WARNING
|
|
42
|
-
This option is supported only by the [**playwright**](/config/browser/playwright) provider.
|
|
43
|
-
:::
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# browser.trackUnhandledErrors
|
|
2
|
-
|
|
3
|
-
- **Type:** `boolean`
|
|
4
|
-
- **Default:** `true`
|
|
5
|
-
|
|
6
|
-
Enables tracking uncaught errors and exceptions so they can be reported by Vitest.
|
|
7
|
-
|
|
8
|
-
If you need to hide certain errors, it is recommended to use [`onUnhandledError`](/config/onunhandlederror) option instead.
|
|
9
|
-
|
|
10
|
-
Disabling this will completely remove all Vitest error handlers, which can help debugging with the "Pause on exceptions" checkbox turned on.
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# Configuring WebdriverIO
|
|
2
|
-
|
|
3
|
-
::: info Playwright vs WebdriverIO
|
|
4
|
-
If you do not already use WebdriverIO in your project, we recommend starting with [Playwright](/config/browser/playwright) as it is easier to configure and has more flexible API.
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
To run tests using WebdriverIO, you need to install the [`@vitest/browser-webdriverio`](https://npmx.dev/package/@vitest/browser-webdriverio) npm package and specify its `webdriverio` export in the `test.browser.provider` property of your config:
|
|
8
|
-
|
|
9
|
-
```ts [vitest.config.js]
|
|
10
|
-
import { webdriverio } from '@vitest/browser-webdriverio'
|
|
11
|
-
import { defineConfig } from 'vitest/config'
|
|
12
|
-
|
|
13
|
-
export default defineConfig({
|
|
14
|
-
test: {
|
|
15
|
-
browser: {
|
|
16
|
-
provider: webdriverio(),
|
|
17
|
-
instances: [{ browser: 'chrome' }]
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
You can configure all the parameters that [`remote`](https://webdriver.io/docs/api/modules/#remoteoptions-modifier) function accepts:
|
|
24
|
-
|
|
25
|
-
```ts{8-12,19-25} [vitest.config.js]
|
|
26
|
-
import { webdriverio } from '@vitest/browser-webdriverio'
|
|
27
|
-
import { defineConfig } from 'vitest/config'
|
|
28
|
-
|
|
29
|
-
export default defineConfig({
|
|
30
|
-
test: {
|
|
31
|
-
browser: {
|
|
32
|
-
// shared provider options between all instances
|
|
33
|
-
provider: webdriverio({
|
|
34
|
-
capabilities: {
|
|
35
|
-
browserVersion: '82',
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
instances: [
|
|
39
|
-
{ browser: 'chrome' },
|
|
40
|
-
{
|
|
41
|
-
browser: 'firefox',
|
|
42
|
-
// overriding options only for a single instance
|
|
43
|
-
// this will NOT merge options with the parent one
|
|
44
|
-
provider: webdriverio({
|
|
45
|
-
capabilities: {
|
|
46
|
-
'moz:firefoxOptions': {
|
|
47
|
-
args: ['--disable-gpu'],
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
})
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
You can find most available options in the [WebdriverIO documentation](https://webdriver.io/docs/configuration/). Note that Vitest will ignore all test runner options because we only use `webdriverio`'s browser capabilities.
|
|
59
|
-
|
|
60
|
-
::: tip
|
|
61
|
-
Most useful options are located on `capabilities` object. WebdriverIO allows nested capabilities, but Vitest will ignore those options because we rely on a different mechanism to spawn several browsers.
|
|
62
|
-
|
|
63
|
-
Note that Vitest will ignore `capabilities.browserName` — use [`test.browser.instances.browser`](/config/browser/instances#browser) instead.
|
|
64
|
-
:::
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# cache <CRoot />
|
|
2
|
-
|
|
3
|
-
- **Type:** `false`
|
|
4
|
-
- **CLI:** `--no-cache`, `--cache=false`
|
|
5
|
-
|
|
6
|
-
Use this option if you want to disable the cache feature. At the moment Vitest stores cache for test results to run the longer and failed tests first.
|
|
7
|
-
|
|
8
|
-
The cache directory is controlled by the Vite's [`cacheDir`](https://vitejs.dev/config/shared-options.html#cachedir) option:
|
|
9
|
-
|
|
10
|
-
```ts
|
|
11
|
-
import { defineConfig } from 'vitest/config'
|
|
12
|
-
|
|
13
|
-
export default defineConfig({
|
|
14
|
-
cacheDir: 'custom-folder/.vitest'
|
|
15
|
-
})
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
You can limit the directory only for Vitest by using `process.env.VITEST`:
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { defineConfig } from 'vitest/config'
|
|
22
|
-
|
|
23
|
-
export default defineConfig({
|
|
24
|
-
cacheDir: process.env.VITEST ? 'custom-folder/.vitest' : undefined
|
|
25
|
-
})
|
|
26
|
-
```
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# chaiConfig
|
|
2
|
-
|
|
3
|
-
- **Type:** `{ includeStack?, showDiff?, truncateThreshold? }`
|
|
4
|
-
- **Default:** `{ includeStack: false, showDiff: true, truncateThreshold: 40 }`
|
|
5
|
-
|
|
6
|
-
Equivalent to [Chai config](https://github.com/chaijs/chai/blob/4.x.x/lib/chai/config.js).
|
|
7
|
-
|
|
8
|
-
## chaiConfig.includeStack
|
|
9
|
-
|
|
10
|
-
- **Type:** `boolean`
|
|
11
|
-
- **Default:** `false`
|
|
12
|
-
|
|
13
|
-
Influences whether stack trace is included in Assertion error message. Default of false suppresses stack trace in the error message.
|
|
14
|
-
|
|
15
|
-
## chaiConfig.showDiff
|
|
16
|
-
|
|
17
|
-
- **Type:** `boolean`
|
|
18
|
-
- **Default:** `true`
|
|
19
|
-
|
|
20
|
-
Influences whether or not the `showDiff` flag should be included in the thrown AssertionErrors. `false` will always be `false`; `true` will be true when the assertion has requested a diff to be shown.
|
|
21
|
-
|
|
22
|
-
## chaiConfig.truncateThreshold
|
|
23
|
-
|
|
24
|
-
- **Type:** `number`
|
|
25
|
-
- **Default:** `40`
|
|
26
|
-
|
|
27
|
-
Sets length threshold for actual and expected values in assertion errors. If this threshold is exceeded, for example for large data structures, the value is replaced with something like `[ Array(3) ]` or `{ Object (prop1, prop2) }`. Set it to `0` if you want to disable truncating altogether.
|
|
28
|
-
|
|
29
|
-
This config option affects truncating values in `test.each` titles and inside the assertion error message.
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# clearMocks
|
|
2
|
-
|
|
3
|
-
- **Type:** `boolean`
|
|
4
|
-
- **Default:** `false`
|
|
5
|
-
|
|
6
|
-
Should Vitest automatically call [`vi.clearAllMocks()`](/api/vi#vi-clearallmocks) before each test.
|
|
7
|
-
|
|
8
|
-
This will clear mock history without affecting mock implementations.
|
|
9
|
-
|
|
10
|
-
```js [vitest.config.js]
|
|
11
|
-
import { defineConfig } from 'vitest/config'
|
|
12
|
-
|
|
13
|
-
export default defineConfig({
|
|
14
|
-
test: {
|
|
15
|
-
clearMocks: true,
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
::: warning
|
|
21
|
-
Be aware that this option may cause problems with async [concurrent tests](/api/test#test-concurrent). If enabled, the completion of one test will clear the mock history for all mocks, including those currently being used by other tests in progress.
|
|
22
|
-
:::
|