msw 0.27.0 → 0.28.1
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 +2 -2
- package/lib/esm/RequestHandler-deps.js +10 -15
- package/lib/esm/errors-deps.js +1 -1
- package/lib/esm/fetch-deps.js +404 -113
- package/lib/esm/graphql-deps.js +3 -7
- package/lib/esm/index-deps.js +1 -1
- package/lib/esm/index.js +34 -17
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +19 -17
- package/lib/esm/rest-deps.js +2 -2
- package/lib/iife/index.js +4 -4
- package/lib/iife/mockServiceWorker.js +19 -17
- package/lib/types/context/body.d.ts +1 -1
- package/lib/types/context/delay.d.ts +2 -2
- package/lib/types/context/fetch.d.ts +1 -1
- package/lib/types/graphql.d.ts +7 -7
- package/lib/types/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/types/handlers/RequestHandler.d.ts +6 -6
- package/lib/types/index.d.ts +1 -1
- package/lib/types/node/createSetupServer.d.ts +1 -1
- package/lib/types/node/glossary.d.ts +3 -3
- package/lib/types/node/setupServer.d.ts +1 -1
- package/lib/types/utils/internal/compose.d.ts +9 -8
- package/lib/types/utils/internal/isNodeProcess.d.ts +1 -1
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -1
- package/lib/umd/index.js +447 -147
- package/lib/umd/mockServiceWorker.js +19 -17
- package/native/lib/index.js +592 -283
- package/node/lib/index.js +598 -286
- package/package.json +7 -10
package/README.md
CHANGED
|
@@ -95,12 +95,12 @@ Performing a `GET https://github.com/octocat` request in your application will r
|
|
|
95
95
|
|
|
96
96
|
## Node
|
|
97
97
|
|
|
98
|
-
- [Learn more about the
|
|
98
|
+
- [Learn more about the Node.js integration](https://mswjs.io/docs/getting-started/integrate/node)
|
|
99
99
|
- [`setupServer` API](https://mswjs.io/docs/api/setup-server)
|
|
100
100
|
|
|
101
101
|
### How does it work?
|
|
102
102
|
|
|
103
|
-
Although Service Worker is a browser-specific API, this library allows to reuse the same mock definition to have API mocking in
|
|
103
|
+
Although Service Worker is a browser-specific API, this library allows to reuse the same mock definition to have API mocking in Node.js through augmenting native request issuing modules.
|
|
104
104
|
|
|
105
105
|
### How is it different?
|
|
106
106
|
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
|
|
3
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4
|
-
|
|
5
|
-
function createCommonjsModule(fn) {
|
|
6
|
-
var module = { exports: {} };
|
|
7
|
-
return fn(module, module.exports), module.exports;
|
|
8
|
-
}
|
|
1
|
+
import { c as createCommonjsModule, a as commonjsGlobal, l as lib, j as jsonParse, s as status, b as set, d as delay, f as fetch } from './fetch-deps.js';
|
|
9
2
|
|
|
10
3
|
/*! *****************************************************************************
|
|
11
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1427,12 +1420,12 @@ function getTimestamp() {
|
|
|
1427
1420
|
* Formats a mocked request for introspection in browser's console.
|
|
1428
1421
|
*/
|
|
1429
1422
|
function prepareRequest(request) {
|
|
1430
|
-
return Object.assign(Object.assign({}, request), { headers: request.headers.
|
|
1423
|
+
return Object.assign(Object.assign({}, request), { headers: request.headers.all() });
|
|
1431
1424
|
}
|
|
1432
1425
|
|
|
1433
1426
|
function parseContentHeaders(headersString) {
|
|
1434
1427
|
var _a, _b;
|
|
1435
|
-
const headers = stringToHeaders(headersString);
|
|
1428
|
+
const headers = lib.stringToHeaders(headersString);
|
|
1436
1429
|
const contentType = headers.get('content-type') || 'text/plain';
|
|
1437
1430
|
const disposition = headers.get('content-disposition');
|
|
1438
1431
|
if (!disposition) {
|
|
@@ -1460,7 +1453,7 @@ function parseMultipartData(data, headers) {
|
|
|
1460
1453
|
if (!contentType) {
|
|
1461
1454
|
return undefined;
|
|
1462
1455
|
}
|
|
1463
|
-
const [, ...directives] = contentType.split(
|
|
1456
|
+
const [, ...directives] = contentType.split(/; */);
|
|
1464
1457
|
const boundary = directives
|
|
1465
1458
|
.filter((d) => d.startsWith('boundary='))
|
|
1466
1459
|
.map((s) => s.replace(/^boundary=/, ''))[0];
|
|
@@ -1531,7 +1524,7 @@ function parseBody(body, headers) {
|
|
|
1531
1524
|
* Formats a mocked response for introspection in browser's console.
|
|
1532
1525
|
*/
|
|
1533
1526
|
function prepareResponse(res) {
|
|
1534
|
-
const responseHeaders = listToHeaders(res.headers);
|
|
1527
|
+
const responseHeaders = lib.listToHeaders(res.headers);
|
|
1535
1528
|
return Object.assign(Object.assign({}, res), {
|
|
1536
1529
|
// Parse a response JSON body for preview in the logs
|
|
1537
1530
|
body: parseBody(res.body, responseHeaders) });
|
|
@@ -1678,7 +1671,7 @@ const defaultResponseTransformers = [];
|
|
|
1678
1671
|
function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
|
|
1679
1672
|
return (...transformers) => __awaiter(this, void 0, void 0, function* () {
|
|
1680
1673
|
const initialResponse = Object.assign({}, defaultResponse, {
|
|
1681
|
-
headers: new Headers({
|
|
1674
|
+
headers: new lib.Headers({
|
|
1682
1675
|
'x-powered-by': 'msw',
|
|
1683
1676
|
}),
|
|
1684
1677
|
}, responseOverrides);
|
|
@@ -1703,7 +1696,9 @@ const response = Object.assign(createResponseComposition(), {
|
|
|
1703
1696
|
* Return the stack trace frame of a function's invocation.
|
|
1704
1697
|
*/
|
|
1705
1698
|
function getCallFrame() {
|
|
1706
|
-
|
|
1699
|
+
// In <IE11, new Error may return an undefined stack
|
|
1700
|
+
const stack = (new Error().stack || '');
|
|
1701
|
+
const frames = stack.split('\n');
|
|
1707
1702
|
// Get the first frame that doesn't reference the library's internal trace.
|
|
1708
1703
|
// Assume that frame is the invocation frame.
|
|
1709
1704
|
const ignoreFrameRegExp = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
@@ -1786,4 +1781,4 @@ class RequestHandler {
|
|
|
1786
1781
|
}
|
|
1787
1782
|
}
|
|
1788
1783
|
|
|
1789
|
-
export { NetworkError as N, RequestHandler as R, __awaiter as _,
|
|
1784
|
+
export { NetworkError as N, RequestHandler as R, __awaiter as _, defaultContext as a, compose as b, createResponseComposition as c, defaultResponse as d, getUrlByMask as e, prepareRequest as f, getPublicUrlFromRequest as g, prepareResponse as h, getTimestamp as i, getStatusCodeColor as j, __rest as k, matchRequestUrl as m, parseBody as p, response as r };
|
package/lib/esm/errors-deps.js
CHANGED