mockaton 8.0.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ api/user(default).GET.200.json
|
|
|
102
102
|
|
|
103
103
|
## You can write JSON mocks in JavaScript or TypeScript
|
|
104
104
|
|
|
105
|
-
An Object, Array, or String is sent as JSON.
|
|
105
|
+
**Option A:** An Object, Array, or String is sent as JSON.
|
|
106
106
|
|
|
107
107
|
`api/foo.GET.200.js`
|
|
108
108
|
```js
|
|
@@ -111,29 +111,32 @@ export default [
|
|
|
111
111
|
]
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
response status and the default JSON content type. But don’t call
|
|
116
|
-
`response.end()`, just return a `string`, `Buffer`, or `Uint8Array`.
|
|
114
|
+
**Option B:** Function
|
|
117
115
|
|
|
118
116
|
Think of this as an HTTP handler. You can read or write to a
|
|
119
|
-
database, or pull data from a backend.
|
|
120
|
-
|
|
121
|
-
`response
|
|
117
|
+
database, or pull data from a backend.
|
|
118
|
+
|
|
119
|
+
Don’t call `response.end()`, just return a `string | Buffer | Uint8Array`.
|
|
120
|
+
|
|
122
121
|
```js
|
|
123
122
|
export default function optionalName(request, response) {
|
|
124
123
|
globalThis.myDatabase ??= { count: 0 }
|
|
125
124
|
globalThis.myDatabase.count++
|
|
126
125
|
|
|
126
|
+
// Optinally, you can override these two:
|
|
127
|
+
repsonse.statusCode = 200
|
|
128
|
+
response.setHeader('Content-Type', 'application/json')
|
|
129
|
+
|
|
127
130
|
return JSON.stringify({ a: 1 })
|
|
128
131
|
}
|
|
129
132
|
```
|
|
130
133
|
|
|
131
|
-
If you need to serve a static `.js` file, put it in your
|
|
134
|
+
If you need to serve a static `.js` file, put it in your
|
|
135
|
+
`Config.staticDir` without the mock filename convention.
|
|
132
136
|
|
|
133
137
|
---
|
|
134
138
|
|
|
135
|
-
## File Name Convention
|
|
136
|
-
This convention is only for files within your `Config.mocksDir`.
|
|
139
|
+
## Mock File Name Convention
|
|
137
140
|
|
|
138
141
|
### Extension
|
|
139
142
|
|
|
@@ -274,7 +277,7 @@ Config.extraMimes = {
|
|
|
274
277
|
}
|
|
275
278
|
```
|
|
276
279
|
|
|
277
|
-
### `plugins?: [filenameTester: RegExp, plugin: Plugin][]
|
|
280
|
+
### `plugins?: [filenameTester: RegExp, plugin: Plugin][]`
|
|
278
281
|
```ts
|
|
279
282
|
type Plugin = (
|
|
280
283
|
filePath: string,
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
File without changes
|