Skip to content

Commit 43dca2a

Browse files
authored
Merge pull request #10453 from smeng9/add-vitest-tutorial
Add vitest tutorial
2 parents 555c856 + f2d961a commit 43dca2a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/Vite.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,43 @@ const App = () => (
147147
export default App;
148148
```
149149

150+
## Unit Test Your App with Vitest
151+
152+
Vitest is a fast and efficient unit testing framework designed specifically for the Vite ecosystem.
153+
154+
To enable it, start by adding the dependencies:
155+
156+
```sh
157+
yarn add -D vitest @vitest/browser playwright
158+
```
159+
160+
Then modify and use the following configs:
161+
162+
```diff
163+
// in vite.config.ts
164+
165+
+/// <reference types="vitest" />
166+
import { defineConfig } from 'vite';
167+
import react from '@vitejs/plugin-react-swc';
168+
169+
// https://vitejs.dev/config/
170+
export default defineConfig({
171+
plugins: [react()],
172+
+ test: {
173+
+ browser: {
174+
+ enabled: true,
175+
+ provider: "playwright",
176+
+ instances: [
177+
+ {
178+
+ browser: "chromium",
179+
+ },
180+
+ ],
181+
+ },
182+
+ globals: true,
183+
+ },
184+
});
185+
```
186+
150187
## Troubleshooting
151188

152189
### Error about `global` Being `undefined`

0 commit comments

Comments
 (0)