Skip to content

Commit 1c6adc9

Browse files
committed
fix(setupServer): reference interceptors to support fast refresh
1 parent f37142d commit 1c6adc9

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/native/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import { createSetupServer } from '../node/createSetupServer'
33

44
// Provision request interception via patching the `XMLHttpRequest` class only
55
// in React Native. There is no `http`/`https` modules in that environment.
6-
export const setupServer = createSetupServer(new XMLHttpRequestInterceptor())
6+
export const setupServer = createSetupServer(XMLHttpRequestInterceptor)

src/node/createSetupServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {
2727
* Useful to generate identical API using different patches to request issuing modules.
2828
*/
2929
export function createSetupServer(
30-
...interceptors: Interceptor<HttpRequestEventMap>[]
30+
...interceptors: { new (): Interceptor<HttpRequestEventMap> }[]
3131
) {
3232
const emitter = new StrictEventEmitter<ServerLifecycleEventsMap>()
3333
const publicEmitter = new StrictEventEmitter<ServerLifecycleEventsMap>()
@@ -62,7 +62,7 @@ export function createSetupServer(
6262

6363
const interceptor = new BatchInterceptor({
6464
name: 'setup-server',
65-
interceptors,
65+
interceptors: interceptors.map((Interceptor) => new Interceptor()),
6666
})
6767

6868
interceptor.on('request', async function setupServerListener(request) {

src/node/setupServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ import { createSetupServer } from './createSetupServer'
1010
export const setupServer = createSetupServer(
1111
// List each interceptor separately instead of using the "node" preset
1212
// so that MSW wouldn't bundle the unnecessary classes (i.e. "SocketPolyfill").
13-
new ClientRequestInterceptor(),
14-
new XMLHttpRequestInterceptor(),
13+
ClientRequestInterceptor,
14+
XMLHttpRequestInterceptor,
1515
)

0 commit comments

Comments
 (0)