-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
039a02f
commit 1938858
Showing
11 changed files
with
278 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
![Private](https://img.shields.io/badge/status-private-red?) | ||
### Start dev server | ||
|
||
```bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
### @msw-devtools/json-config | ||
![Private](https://img.shields.io/badge/status-private-red?) | ||
## @msw-devtools/json-config | ||
|
||
JSON config used by the extension to configure the responses. | ||
|
||
### Example config | ||
```json | ||
{ | ||
"version": 1, | ||
"name": "example", | ||
"handlers": { | ||
"/profile": { | ||
"method": "GET", | ||
"body": { | ||
"name": "Valentin", | ||
"surname": "Kruglikov", | ||
"location": "World" | ||
}, | ||
"init": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
}, | ||
"/forbidden": { | ||
"method": "GET", | ||
"body": "403 Forbidden", | ||
"init": { | ||
"status": 403, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### ZOD Schema | ||
[MSW JSON Config reference](./docs/README.md) | ||
|
||
### Create your own config | ||
[DEMO page](https://vkruglikov.github.io/msw-devtools-extension/) | ||
|
||
WIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# MSW JSON Config reference | ||
|
||
## JsonConfigHandler | ||
|
||
Response configuration. | ||
|
||
_Object containing the following properties:_ | ||
|
||
| Property | Description | Type | | ||
| :---------------- | :------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| **`method`** (\*) | HTTP method to intercept. | `'GET' \| 'POST' \| 'PUT' \| 'DELETE' \| 'PATCH' \| 'HEAD' \| 'OPTIONS'` | | ||
| **`body`** (\*) | Response's body. Can be a string or a JSON object. | _Object with properties:_<ul></ul> _or_ `string` | | ||
| **`init`** (\*) | Response init object. | _Object with properties:_<ul><li>`headers`: _Object with properties:_<ul><li>`Content-Type`: `string`</li></ul> - Response headers.</li><li>`status`: `number` (_int, ≥100, ≤599_) - Response status code.</li></ul> | | ||
|
||
_(\*) Required._ | ||
|
||
## JsonConfig | ||
|
||
JSON configuration schema. | ||
|
||
_Object containing the following properties:_ | ||
|
||
| Property | Description | Type | | ||
| :------------------ | :--------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------- | | ||
| **`version`** (\*) | Major version of the config. If it changes, the config should not be compatible with the previous version. | `1` | | ||
| **`name`** (\*) | Name of the config. This name displayed in the extension's list of configs. Should be unique per host. | `string` (_min length: 3, max length: 50_) | | ||
| **`handlers`** (\*) | List of handlers to intercept. | _Object with dynamic keys of type_ `string` _and values of type_ [JsonConfigHandler](#jsonconfighandler) | | ||
|
||
_(\*) Required._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { z } from 'zod' | ||
|
||
const MAJOR_CONFIG_VERSION = 1 | ||
|
||
export type JsonConfig = z.infer<typeof jsonConfigSchema> | ||
|
||
/** | ||
* Every time, don't forget to run `npm run docs` | ||
*/ | ||
export const jsonConfigHandler = z | ||
.object({ | ||
method: z | ||
.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']) | ||
.describe('HTTP method to intercept.'), | ||
body: z | ||
.union([z.object({}).catchall(z.any()), z.string()]) | ||
.describe("Response's body. Can be a string or a JSON object."), | ||
init: z | ||
.object({ | ||
headers: z | ||
.object({ | ||
'Content-Type': z.string() | ||
}) | ||
.catchall(z.union([z.string(), z.null()])) | ||
.describe('Response headers.'), | ||
status: z | ||
.number() | ||
.int() | ||
.min(100) | ||
.max(599) | ||
.optional() | ||
.describe('Response status code.') | ||
}) | ||
.describe('Response init object.') | ||
}) | ||
.describe('Response configuration.') | ||
|
||
export const jsonConfigSchema = z | ||
.object({ | ||
version: z | ||
.literal(MAJOR_CONFIG_VERSION) | ||
.describe( | ||
'Major version of the config. If it changes, the config should ' + | ||
'not be compatible with the previous version.' | ||
), | ||
name: z | ||
.string() | ||
.min(3) | ||
.max(50) | ||
.describe( | ||
"Name of the config. This name displayed in the extension's list " + | ||
'of configs. Should be unique per host.' | ||
), | ||
handlers: z | ||
.record( | ||
z | ||
.string() | ||
.describe( | ||
'Url path or full URL to intercept. ' + | ||
'Example: "/api", "http://localhost:3000/api"' | ||
), | ||
jsonConfigHandler | ||
) | ||
.describe('List of handlers to intercept.') | ||
}) | ||
.describe('JSON configuration schema.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.