File tree Expand file tree Collapse file tree 5 files changed +34
-4
lines changed
Expand file tree Collapse file tree 5 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 11import { setupWorker } from 'msw/browser'
22import { handlers } from './handlers'
33
4- window . worker = setupWorker ( ...handlers )
4+ export const worker = setupWorker ( ...handlers )
Original file line number Diff line number Diff line change 77 < script >
88 globalThis . process = { env : { } }
99 </ script >
10- < script type ="module " src ="/browser.js "> </ script >
1110 < script type ="module ">
12- await window . worker . start ( )
11+ if ( process . env . NODE_ENV === 'development' ) {
12+ const { worker } = await import ( './browser.js' )
13+ await worker . start ( )
14+ }
1315
1416 async function main ( ) {
1517 fetch ( '/user' )
Original file line number Diff line number Diff line change @@ -11,4 +11,16 @@ export default defineConfig({
1111 devtools : true ,
1212 } ,
1313 } ,
14+ testDir : 'tests' ,
15+ projects : [
16+ // Setup file following https://playwright.dev/docs/test-global-setup-teardown
17+ {
18+ name : 'setup' ,
19+ testMatch : 'playwright.setup.ts' ,
20+ } ,
21+ {
22+ name : 'tests' ,
23+ dependencies : [ 'setup' ] ,
24+ } ,
25+ ] ,
1426} )
Original file line number Diff line number Diff line change 1+ import { test as testBase } from '@playwright/test'
2+ import { createNetworkFixture , type NetworkFixture } from '@msw/playwright'
3+ import { handlers } from './app/handlers.js'
4+
5+ interface Fixtures {
6+ network : NetworkFixture
7+ }
8+
9+ // Set up `test` with the msw playwright binding following https://github.com/mswjs/playwright
10+ export const test = testBase . extend < Fixtures > ( {
11+ // Create a fixture that will control the network in your tests.
12+ network : createNetworkFixture ( {
13+ initialHandlers : handlers ,
14+ } ) ,
15+ } )
Original file line number Diff line number Diff line change 1- import { test , expect } from '@playwright/test'
1+ import { expect } from '@playwright/test'
2+ import { test } from '../playwright.setup.js'
23
34test ( 'receives a mocked response to a REST API request' , async ( { page } ) => {
45 await page . goto ( '/' , { waitUntil : 'networkidle' } )
You can’t perform that action at this time.
0 commit comments