Skip to content

Commit

Permalink
fix(setupServer): reference interceptors to support fast refresh (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jun 21, 2022
1 parent f37142d commit 72f0b25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
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,
)

0 comments on commit 72f0b25

Please sign in to comment.