You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/02.vitest-browser-mode/03.solution.playwright/README.mdx
+57-1Lines changed: 57 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,4 +9,60 @@ Problem: Using the default `preview` provider in Vitest is great to try things o
9
9
10
10
---
11
11
12
-
// TODO: Mention `"types": ["@vitest/browser/providers/playwright"]` in `tsconfig.node.json` to have `.toBeVisible()` and other nice browser assertions!
12
+
Let's start from installing `playwright`:
13
+
14
+
```sh
15
+
npm i -D playwright
16
+
```
17
+
18
+
Playwright needs browser executables to be present on your machine to run. In this workshop, I am using Chromium as my browser of choice, so I can install just that particular browser by running the following command:
19
+
20
+
```sh
21
+
npx playwright install --with-dewps chromium
22
+
```
23
+
24
+
> 🦉 You can provide the Playwright CLI with the explicit browsers you want to be installed. This reduces its footprint in the system by fetching only the browsers you need.
25
+
26
+
The next step is to tell Vitest to use Playwright as the browser provider for component tests. In `vite.config.ts`, set the `test.browser.provider` option to `'playwright'`:
27
+
28
+
```ts filename=vite.config.ts add=11
29
+
/// <referencetypes="vitest" />
30
+
import { defineConfig } from'vite'
31
+
importreactfrom'@vitejs/plugin-react'
32
+
33
+
exportdefaultdefineConfig({
34
+
plugins: [react()],
35
+
test: {
36
+
globals: true,
37
+
browser: {
38
+
enabled: true,
39
+
provider: 'playwright',
40
+
instances: [
41
+
{
42
+
browser: 'chromium',
43
+
},
44
+
],
45
+
},
46
+
},
47
+
})
48
+
```
49
+
50
+
And, finally, let's update the type definitions for the assertion matchers to be those from Playwright in `tsconfig.test.json`:
0 commit comments