14 lines
689 B
TypeScript
14 lines
689 B
TypeScript
// Start of the mock network in a browser. Separate from the handlers so that tests, which run
|
|
// without a service worker, import the handlers and nothing else.
|
|
|
|
import { setupWorker } from 'msw/browser';
|
|
|
|
import { scenarioOf } from '../api/scenarios';
|
|
import { handlersFor } from './handlers';
|
|
|
|
export async function startWorker(pathname: string): Promise<void> {
|
|
const worker = setupWorker(...handlersFor(scenarioOf(pathname)));
|
|
// `bypass` and not `error`: fonts, the app's own assets and the worker script itself are real
|
|
// requests, and turning them into failures would only report the fixture as broken.
|
|
await worker.start({ quiet: true, onUnhandledRequest: 'bypass' });
|
|
}
|