Skip to content
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

fix(setupServer): reference interceptors to support fast refresh #1299

Merged
merged 1 commit into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/native/index.ts
Expand Up @@ -3,4 +3,4 @@ import { createSetupServer } from '../node/createSetupServer'

// Provision request interception via patching the `XMLHttpRequest` class only
// in React Native. There is no `http`/`https` modules in that environment.
export const setupServer = createSetupServer(new XMLHttpRequestInterceptor())
export const setupServer = createSetupServer(XMLHttpRequestInterceptor)
4 changes: 2 additions & 2 deletions src/node/createSetupServer.ts
Expand Up @@ -27,7 +27,7 @@ const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
* Useful to generate identical API using different patches to request issuing modules.
*/
export function createSetupServer(
...interceptors: Interceptor<HttpRequestEventMap>[]
...interceptors: { new (): Interceptor<HttpRequestEventMap> }[]
) {
const emitter = new StrictEventEmitter<ServerLifecycleEventsMap>()
const publicEmitter = new StrictEventEmitter<ServerLifecycleEventsMap>()
Expand Down Expand Up @@ -62,7 +62,7 @@ export function createSetupServer(

const interceptor = new BatchInterceptor({
name: 'setup-server',
interceptors,
interceptors: interceptors.map((Interceptor) => new Interceptor()),
})

interceptor.on('request', async function setupServerListener(request) {
Expand Down
4 changes: 2 additions & 2 deletions src/node/setupServer.ts
Expand Up @@ -10,6 +10,6 @@ import { createSetupServer } from './createSetupServer'
export const setupServer = createSetupServer(
// List each interceptor separately instead of using the "node" preset
// so that MSW wouldn't bundle the unnecessary classes (i.e. "SocketPolyfill").
new ClientRequestInterceptor(),
new XMLHttpRequestInterceptor(),
ClientRequestInterceptor,
XMLHttpRequestInterceptor,
)