-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: isolate parent and child frames when handling requests (#2324)
- Loading branch information
1 parent
c949d19
commit a1a81ba
Showing
9 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/browser/msw-api/setup-worker/scenarios/iframe/multiple-workers/child.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { http } from 'msw' | ||
import { setupWorker } from 'msw/browser' | ||
|
||
const worker = setupWorker( | ||
http.get('/resource', () => { | ||
return new Response('hello world') | ||
}), | ||
) | ||
|
||
worker.start() |
33 changes: 33 additions & 0 deletions
33
...er/msw-api/setup-worker/scenarios/iframe/multiple-workers/iframe-multiple-workers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test, expect } from '../../../../../playwright.extend' | ||
|
||
test('intercepts a request issued by child frame when both child and parent have MSW', async ({ | ||
webpackServer, | ||
page, | ||
}) => { | ||
const parentCompilation = await webpackServer.compile([ | ||
require.resolve('./parent.mocks.ts'), | ||
]) | ||
const childCompilation = await webpackServer.compile([ | ||
require.resolve('./child.mocks.ts'), | ||
]) | ||
|
||
await page.goto(parentCompilation.previewUrl, { waitUntil: 'networkidle' }) | ||
|
||
await page.evaluate((childFrameUrl) => { | ||
const iframe = document.createElement('iframe') | ||
iframe.setAttribute('id', 'child-frame') | ||
iframe.setAttribute('src', childFrameUrl) | ||
document.body.appendChild(iframe) | ||
}, childCompilation.previewUrl) | ||
|
||
const childFrameElement = await page.locator('#child-frame').elementHandle() | ||
const childFrame = await childFrameElement!.contentFrame() | ||
await childFrame!.waitForLoadState('networkidle') | ||
|
||
const responseText = await childFrame!.evaluate(async () => { | ||
const response = await fetch('/resource') | ||
return response.text() | ||
}) | ||
|
||
expect(responseText).toBe('hello world') | ||
}) |
7 changes: 7 additions & 0 deletions
7
test/browser/msw-api/setup-worker/scenarios/iframe/multiple-workers/parent.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { setupWorker } from 'msw/browser' | ||
|
||
// The parent frame has a worker without any handlers. | ||
const worker = setupWorker() | ||
|
||
// This registration is awaited by the `loadExample` command in the test. | ||
worker.start() |