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
Run Vitest tests in a browser. We use [WebdriverIO](https://webdriver.io/) for running tests by default, but it can be configured with [browser.provider](#browser-provider) option.
1764
-
1765
-
::: tip NOTE
1766
-
Read more about testing in a real browser in the [guide page](/guide/browser/).
1767
-
:::
1762
+
Configuration for running browser tests. Please, refer to the ["Browser Config Reference"](/guide/browser/config) article.
1768
1763
1769
1764
::: warning
1770
1765
This is an experimental feature. Breaking changes might not follow SemVer, please pin Vitest's version when using it.
1771
1766
:::
1772
1767
1773
-
#### browser.enabled
1774
-
1775
-
-**Type:**`boolean`
1776
-
-**Default:**`false`
1777
-
-**CLI:**`--browser`, `--browser.enabled=false`
1778
-
1779
-
Run all tests inside a browser by default.
1780
-
1781
-
#### browser.name
1782
-
1783
-
-**Type:**`string`
1784
-
-**CLI:**`--browser=safari`
1785
-
1786
-
Run all tests in a specific browser. Possible options in different providers:
A path to the HTML entry point. Can be relative to the root of the project. This file will be processed with [`transformIndexHtml`](https://vite.dev/guide/api-plugin#transformindexhtml) hook.
Configure options for Vite server that serves code in the browser. Does not affect [`test.api`](#api) option. By default, Vitest assigns port `63315` to avoid conflicts with the development server, allowing you to run both in parallel.
Path to a provider that will be used when running browser tests. Vitest provides three providers which are `preview` (default), `webdriverio` and `playwright`. Custom providers should be exported using `default` export and have this shape:
Options that will be passed down to provider when calling `provider.initialize`.
1850
-
1851
-
```ts
1852
-
import { defineConfig } from'vitest/config'
1853
-
1854
-
exportdefaultdefineConfig({
1855
-
test: {
1856
-
browser: {
1857
-
providerOptions: {
1858
-
launch: {
1859
-
devtools: true,
1860
-
},
1861
-
},
1862
-
},
1863
-
},
1864
-
})
1865
-
```
1866
-
1867
-
::: tip
1868
-
To have a better type safety when using built-in providers, you should reference one of these types (for provider that you are using) in your [config file](/config/):
Custom scripts that should be injected into the orchestrator HTML before test iframes are initiated. This HTML document only sets up iframes and doesn't actually import your code.
1922
-
1923
-
The script `src` and `content` will be processed by Vite plugins. Script should be provided in the following shape:
1924
-
1925
-
```ts
1926
-
exportinterfaceBrowserScript {
1927
-
/**
1928
-
* If "content" is provided and type is "module", this will be its identifier.
1929
-
*
1930
-
* If you are using TypeScript, you can add `.ts` extension here for example.
1931
-
* @default`injected-${index}.js`
1932
-
*/
1933
-
id?:string
1934
-
/**
1935
-
* JavaScript content to be injected. This string is processed by Vite plugins if type is "module".
1936
-
*
1937
-
* You can use `id` to give Vite a hint about the file extension.
1938
-
*/
1939
-
content?:string
1940
-
/**
1941
-
* 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.
1962
-
1963
-
The script `src` and `content` will be processed by Vite plugins.
1964
-
1965
-
#### browser.commands {#browser-commands}
1966
-
1967
-
-**Type:**`Record<string, BrowserCommand>`
1968
-
-**Default:**`{ readFile, writeFile, ... }`
1969
-
1970
-
Custom [commands](/guide/browser/commands) that can be imported during browser tests from `@vitest/browser/commands`.
Copy file name to clipboardExpand all lines: docs/guide/browser/commands.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ CDP session works only with `playwright` provider and only when using `chromium`
61
61
62
62
## Custom Commands
63
63
64
-
You can also add your own commands via [`browser.commands`](/config/#browser-commands) config option. If you develop a library, you can provide them via a `config` hook inside a plugin:
64
+
You can also add your own commands via [`browser.commands`](/guide/browser/config#browser-commands) config option. If you develop a library, you can provide them via a `config` hook inside a plugin:
0 commit comments