- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
- Recipes
- Cookies
- Query parameters
- Response patching
- Polling
- Streaming
- Network errors
- File uploads
- Responding with binary
- Custom worker script location
- Global response delay
- GraphQL query batching
- Higher-order resolver
- Keeping mocks in sync
- Merging Service Workers
- Mock GraphQL schema
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
init
Copy the worker script into the given directory.
Usage
npx msw init <PUBLIC_DIR> [options]
Arguments
PUBLIC_DIR
A relative path to the public directory of your application.
For example, when using NextJS, the public directory is located in /public
, and that’s the path you should provide to this command:
npx msw init ./public
Flags
--save
Save the given PUBLIC_DIR
in package.json
for future automatic updates of the worker script.
npx msw init ./public --save
Running this command will save the ./public
directory in your package.json
:
{
"name": "my-app",
"msw": {
"workerDirectory": "./public"
}
}
If this property is present, whenever you install the msw
package, the worker script will be copied to the msw.workerDirectory
destination automatically. This ensures the worker script being in sync with the currently installed version of the library.