Skip to content

Commit 3533f85

Browse files
committed
02/04: add @msw/playwright setup
1 parent f5148c2 commit 3533f85

File tree

9 files changed

+869
-1
lines changed

9 files changed

+869
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
# API mocking
2+
3+
1. Install `msw` and `@msw/playwright`.
4+
1. Create `test-extend.ts` and a `network` fixture there.
5+
1. Note: `createWorkerFixture()` _automatically_ comes with `auto: true`.
6+
7+
## Materials
8+
9+
- [`@msw/playwright`](https://github.com/mswjs/playwright)
10+
- [Mock Service Worker](https://mswjs.io)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { http } from 'msw'
2+
import { test } from '../test-extend'
3+
4+
test('...', async ({ network, page }) => {
5+
network.use(http.get('/resource', () => {}))
6+
7+
await page.goto('/')
8+
9+
// ...
10+
})
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"name": "exercises_02.setup_04.solution.api-mocking"
2+
"name": "exercises_02.setup_04.solution.api-mocking",
3+
"scripts": {
4+
"test": "playwright test"
5+
},
6+
"devDependencies": {
7+
"@msw/playwright": "^0.4.0",
8+
"@playwright/test": "^1.53.1",
9+
"msw": "^2.10.2"
10+
}
311
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
export default defineConfig({
4+
projects: [
5+
{
6+
name: 'Chromium',
7+
use: devices['Desktop Chrome'],
8+
},
9+
],
10+
use: {
11+
screenshot: 'only-on-failure',
12+
},
13+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { test as testBase } from '@playwright/test'
2+
import { createNetworkFixture, type NetworkFixture } from '@msw/playwright'
3+
4+
interface Fixtures {
5+
network: NetworkFixture
6+
}
7+
8+
export const test = testBase.extend<Fixtures>({
9+
network: createNetworkFixture(),
10+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"noUnusedLocals": false,
5+
"noUnusedParameters": false,
6+
"noFallthroughCasesInSwitch": true,
7+
"noUncheckedSideEffectImports": true,
8+
"target": "es2022",
9+
"module": "esnext",
10+
"moduleResolution": "node",
11+
"isolatedModules": true
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./tsconfig.node.json"
6+
}
7+
]
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["./playwright.config.ts", "./e2e"]
4+
}

0 commit comments

Comments
 (0)