Skip to content

Commit 5060e7b

Browse files
committed
Hold on to reference to MSW worker start promise
1 parent 36fbe40 commit 5060e7b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

lib/msw-config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type SetupWorkerApi,
77
MockedRequest,
88
} from 'msw';
9+
import { StartReturnType } from 'msw/lib/types/setupWorker/glossary';
910
import PassthroughRegistry from './passthrough-registry';
1011
import type { Server } from 'miragejs';
1112
import type { HTTPVerb, RouteHandler, ServerConfig } from 'miragejs/server';
@@ -67,6 +68,10 @@ type RouteOptions = {
6768
timing?: boolean | number;
6869
};
6970

71+
type SetupWorkerApiWithStartPromise = SetupWorkerApi & {
72+
_startPromise: StartReturnType;
73+
};
74+
7075
const defaultRouteOptions = {
7176
coalesce: false,
7277
timing: undefined,
@@ -127,7 +132,7 @@ export default class MswConfig {
127132

128133
timing?: number;
129134

130-
msw?: SetupWorkerApi;
135+
msw?: SetupWorkerApiWithStartPromise;
131136

132137
mirageServer?: MirageServer;
133138

@@ -447,10 +452,10 @@ export default class MswConfig {
447452
}
448453

449454
start() {
450-
this.msw = setupWorker(...this.handlers);
455+
this.msw = setupWorker(...this.handlers) as SetupWorkerApiWithStartPromise;
451456

452457
let logging = this.mirageConfig?.logging || false;
453-
this.msw.start({
458+
this.msw._startPromise = this.msw.start({
454459
quiet: !logging,
455460
onUnhandledRequest: (req) => {
456461
const verb = req.method.toUpperCase();

0 commit comments

Comments
 (0)