Skip to content

Commit aa36669

Browse files
authored
fix: stop relying on worker.context (#184)
* fix: stop relying on `worker.context` * chore: use explicit prettier config
1 parent ae7ce4d commit aa36669

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "none"
5+
}

packages/msw-addon/src/initialize.browser.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ type SetupWorker = ReturnType<typeof setupWorker>
66

77
export let api: SetupWorker
88

9-
type ContextfulWorker = SetupWorker & {
10-
context: { isMockingEnabled: boolean; activationPromise?: any }
11-
}
12-
139
export type InitializeOptions = Parameters<SetupWorker['start']>[0]
1410

11+
let activationPromise: Promise<void>
12+
1513
export function initialize(
1614
options?: InitializeOptions,
1715
initialHandlers: RequestHandler[] = []
1816
): SetupWorker {
19-
const worker = setupWorker(...initialHandlers) as ContextfulWorker
20-
worker.context.activationPromise = worker.start(
21-
augmentInitializeOptions(options)
22-
)
17+
const worker = setupWorker(...initialHandlers)
18+
activationPromise = worker
19+
.start(augmentInitializeOptions(options))
20+
.then(() => {})
2321
api = worker
2422
return worker
2523
}
2624

2725
export async function waitForMswReady() {
28-
const msw = getWorker() as ContextfulWorker
29-
await msw.context.activationPromise
26+
getWorker()
27+
await activationPromise
3028
}
3129

3230
export function getWorker(): SetupWorker {

0 commit comments

Comments
 (0)