Skip to content

Commit d29c62b

Browse files
authored
05/01: add vitest 4.0 migration extra (#8)
1 parent 2235b5b commit d29c62b

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Migrating to Vitest 4.0
2+
3+
With [Vitest 4.0](https://github.com/vitest-dev/vitest/releases/tag/v4.0.0), the Browser Mode is out of experimental! :tada: But that's not the only thing that has changed. In this exercise, you will go through all the breaking changes related to the Browser Mode and learn how to migrate to them in your projects.
4+
5+
<callout-success>Feel free to take a look at the [Vitest 4.0 migration guide](https://vitest.dev/guide/migration.html#vitest-4) for the detailed instructions related to all the changes in the new version.</callout-success>
6+
7+
## Browser Mode Breaking changes
8+
9+
### Dependencies
10+
11+
You no longer need to install the `@vitest/browser` package. The Browser Mode comes built-in into Vitest itself.
12+
13+
```sh
14+
npm remove @vitest/browser
15+
```
16+
17+
### Imports
18+
19+
You should now import the `page` object directly from the `vitest` package (its `/browser` export):
20+
21+
```ts remove=1 add=2 nocopy
22+
-import { page } from '@vitest/browser/context'
23+
+import { page } from 'vitest/browser'
24+
```
25+
26+
### Providers
27+
28+
Browser automation providers now have to be installed as separate dependencies. This is done to simplify provider options and their type-safety.
29+
30+
For example, to use the Playwright provider, install the following package:
31+
32+
```sh
33+
npm i @vitest/browser-playwright
34+
```
35+
36+
The integration of browser providers in your `vitest.config.ts` has also changed. You should now pass the imported provider directly as the value of the `test.browser.provider` property. Any previous launch/connect/context provider options migrate from `test.browser.instances` to the provider function call.
37+
38+
```ts remove=8,12-14 add=17-21
39+
// Import the provider package directly.
40+
+import { playwright } from '@vitest/browser-playwright'
41+
42+
export default defineConfig({
43+
test: {
44+
browser: {
45+
enabled: true,
46+
provider: 'playwright',
47+
instances: [
48+
{
49+
browser: 'chromium',
50+
context: {
51+
reduceMotion: 'reduce',
52+
},
53+
},
54+
]
55+
provider: playwright({
56+
contextOptions: {
57+
reducedMotion: 'reduce',
58+
},
59+
}),
60+
},
61+
},
62+
})
63+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Migrating to Vitest 4.0
2+
3+
This completes the migration to Vitest 4.0. Don't hesitate to reach out to me in case of any questions. I will leave a few useful links related to this migration below for future reference.
4+
5+
## Useful materials
6+
7+
- [Vitest 4.0 release notes](https://github.com/vitest-dev/vitest/releases/tag/v4.0.0)
8+
- [Vitest 4.0 migration guide](https://vitest.dev/guide/migration.html#vitest-4)

exercises/05.extras/FINISHED.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Extras
2+
3+
That's it! There's no more extras for me to share. If you have any feedback on how to improve these extra exercises, please let me know by filling in and submitting the form to your right.
4+
5+
Thank you once again for completing this workshop and see you in the future exercises! Take care and write great tests :wave:.

exercises/05.extras/README.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Extras
2+
3+
Hi :wave: Artem from the future here.
4+
5+
There's been a couple of changes to some of the technologies we went through in this workshop so I decided to add this extra exercise block to help you accommodate and understand those changes. Don't worry, **everything you've learned thus far still applies**. In my workshops, you're always getting concepts, mental models, and best practices first, APIs second.
6+
7+
But those APIs still matter and these extras are here to guide you through any changes that has happened to the tools you've been using.
8+
9+
<callout-info>The extra exercises _do not have any videos_, which does not diminish their practical value in any way.</callout-info>

0 commit comments

Comments
 (0)