-
-
Notifications
You must be signed in to change notification settings - Fork 7
#18 - add onUnhandledRequest #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,11 @@ import { | |
| WebSocketServerConnectionProtocol, | ||
| } from '@mswjs/interceptors/WebSocket' | ||
|
|
||
| /** @todo `Import from msw/core`? */ | ||
| type UnhandledRequestStrategy = (request: Request) => void; | ||
| export interface CreateNetworkFixtureArgs { | ||
| initialHandlers: Array<RequestHandler | WebSocketHandler> | ||
| onUnhandledRequest?: UnhandledRequestStrategy | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -48,7 +51,8 @@ export interface CreateNetworkFixtureArgs { | |
| */ | ||
| export function createNetworkFixture( | ||
| args?: CreateNetworkFixtureArgs, | ||
| /** @todo `onUnhandledRequest`? */ | ||
| onUnhandledRequest?: UnhandledRequestStrategy, | ||
zachatrocity marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** @todo `startOptions`? */ | ||
| ): [ | ||
| TestFixture<NetworkFixture, PlaywrightTestArgs & PlaywrightWorkerArgs>, | ||
| { auto: boolean }, | ||
|
|
@@ -60,7 +64,7 @@ export function createNetworkFixture( | |
| initialHandlers: args?.initialHandlers || [], | ||
| }) | ||
|
|
||
| await worker.start() | ||
| await worker.start({onUnhandledRequest: onUnhandledRequest}) | ||
| await use(worker) | ||
| await worker.stop() | ||
| }, | ||
|
|
@@ -79,7 +83,7 @@ export class NetworkFixture extends SetupApi<LifeCycleEventsMap> { | |
| this.#page = args.page | ||
| } | ||
|
|
||
| public async start() { | ||
| public async start({ onUnhandledRequest }: { onUnhandledRequest?: UnhandledRequestStrategy } = {}) { | ||
| // Handle HTTP requests. | ||
| await this.#page.route(/.+/, async (route, request) => { | ||
| const fetchRequest = new Request(request.url(), { | ||
|
|
@@ -112,6 +116,11 @@ export class NetworkFixture extends SetupApi<LifeCycleEventsMap> { | |
| : undefined, | ||
| }) | ||
| return | ||
| } else { | ||
| if (onUnhandledRequest) { | ||
| onUnhandledRequest(fetchRequest) | ||
|
||
| return | ||
| } | ||
| } | ||
|
|
||
| route.continue() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.