-
-
Notifications
You must be signed in to change notification settings - Fork 551
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
feat(SetupServerApi): allow using custom interceptors #2464
base: main
Are you sure you want to change the base?
feat(SetupServerApi): allow using custom interceptors #2464
Conversation
Make sure Playwright chromium has been installed before running browser tests. | ||
|
||
```sh | ||
pnpm playwright install chromium |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of implied by using playwright
(it won't run without browsers) and isn't really specific to MSW. I would rather not include this step here. With it here, we need to make sure it reflects any possible future changes to playwright
, its browser usage, or its CLI.
import { FetchInterceptor } from '@mswjs/interceptors/fetch' | ||
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest' | ||
|
||
const fetchInterceptorSpy = vi.spyOn(FetchInterceptor.prototype, 'apply') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop these spies and instead:
- Declare a request handler as you normally would.
- Assert that the matching request receives the mocked response.
This will give us assurance that the custom interceptor indeed works.
) | ||
constructor( | ||
handlers: Array<RequestHandler | WebSocketHandler>, | ||
customInterceptors: Array<{ new (): Interceptor<HttpRequestEventMap> }> = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, technically, we can accept interceptors of any event map, like WebSocket. I need to think on this one... I am tempted to say we should do Interceptor<any>
here as the end event map is defined by the MSW usage of particular interceptors, but this may have unexpected repercussions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But probably a better solution would be to limit the supported event maps as we only have two at the moment:
Interceptor<HttpRequestEventMap | WebSocketEventMap>
Both types are available from the @mswjs/interceptors
package.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this one, @tastypackets!
I left a few suggestions, let me know your thoughts about them. Excited to see this landing in MSW soon!
SetupServerApi
SetupServerApi
, if no interceptors are passed the default 3 node.js interceptors are used.resolves #2460