@mswjs/interceptors 0.13.3 → 0.13.4
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.
|
@@ -56,30 +56,30 @@ var interceptFetch = function (observer, resolver) {
|
|
|
56
56
|
var pureFetch = window.fetch;
|
|
57
57
|
debug('replacing "window.fetch"...');
|
|
58
58
|
window.fetch = function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
-
var
|
|
59
|
+
var request, url, method, isoRequest, response, isomorphicResponse;
|
|
60
60
|
var _a;
|
|
61
61
|
return __generator(this, function (_b) {
|
|
62
62
|
switch (_b.label) {
|
|
63
63
|
case 0:
|
|
64
|
-
|
|
64
|
+
request = new Request(input, init);
|
|
65
65
|
url = typeof input === 'string' ? input : input.url;
|
|
66
|
-
method =
|
|
66
|
+
method = request.method;
|
|
67
67
|
debug('[%s] %s', method, url);
|
|
68
68
|
_a = {
|
|
69
69
|
id: uuid_1.uuidv4(),
|
|
70
70
|
url: new URL(url, location.origin),
|
|
71
71
|
method: method,
|
|
72
|
-
headers: new headers_polyfill_1.Headers(
|
|
73
|
-
credentials:
|
|
72
|
+
headers: new headers_polyfill_1.Headers(request.headers),
|
|
73
|
+
credentials: request.credentials
|
|
74
74
|
};
|
|
75
|
-
return [4 /*yield*/,
|
|
75
|
+
return [4 /*yield*/, request.clone().text()];
|
|
76
76
|
case 1:
|
|
77
77
|
isoRequest = (_a.body = _b.sent(),
|
|
78
78
|
_a);
|
|
79
79
|
debug('isomorphic request', isoRequest);
|
|
80
80
|
observer.emit('request', isoRequest);
|
|
81
81
|
debug('awaiting for the mocked response...');
|
|
82
|
-
return [4 /*yield*/, resolver(isoRequest,
|
|
82
|
+
return [4 /*yield*/, resolver(isoRequest, request)];
|
|
83
83
|
case 2:
|
|
84
84
|
response = _b.sent();
|
|
85
85
|
debug('mocked response', response);
|
|
@@ -94,7 +94,7 @@ var interceptFetch = function (observer, resolver) {
|
|
|
94
94
|
headers: headers_polyfill_1.flattenHeadersObject(response.headers || {}) }))];
|
|
95
95
|
}
|
|
96
96
|
debug('no mocked response found, bypassing...');
|
|
97
|
-
return [2 /*return*/, pureFetch(
|
|
97
|
+
return [2 /*return*/, pureFetch(request).then(function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
98
|
var cloneResponse, _a, _b, _c;
|
|
99
99
|
return __generator(this, function (_d) {
|
|
100
100
|
switch (_d.label) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/fetch/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAKyB;AAMzB,2DAAyD;AACzD,yCAAyC;AAEzC,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;AAEhC,IAAM,cAAc,GAAgB,UAAC,QAAQ,EAAE,QAAQ;IAC5D,IAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAA;IAE9B,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAEpC,MAAM,CAAC,KAAK,GAAG,UAAO,KAAK,EAAE,IAAI;;;;;;oBACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/fetch/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAKyB;AAMzB,2DAAyD;AACzD,yCAAyC;AAEzC,IAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;AAEhC,IAAM,cAAc,GAAgB,UAAC,QAAQ,EAAE,QAAQ;IAC5D,IAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAA;IAE9B,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAEpC,MAAM,CAAC,KAAK,GAAG,UAAO,KAAK,EAAE,IAAI;;;;;;oBACzB,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CAC1E,qCAAqC;gCACrC,OAAO,EAAE,uCAAoB,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,IACrD,EAAA;qBACH;oBAED,KAAK,CAAC,wCAAwC,CAAC,CAAA;oBAE/C,sBAAO,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAO,QAAQ;;;;;wCACtC,aAAa,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;wCACtC,KAAK,CAAC,0BAA0B,EAAE,aAAa,CAAC,CAAA;wCAEhD,KAAA,CAAA,KAAA,QAAQ,CAAA,CAAC,IAAI,CAAA;8CACX,UAAU;4CACV,UAAU;wCACV,qBAAM,sBAAsB,CAAC,aAAa,CAAC,EAAA;;wCAH7C,wBAGE,SAA2C,GAC5C,CAAA;wCACD,sBAAO,QAAQ,EAAA;;;6BAChB,CAAC,EAAA;;;SACH,CAAA;IAED,OAAO;QACL,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAC7B,MAAM,CAAC,KAAK,GAAG,SAAS,CAAA;IAC1B,CAAC,CAAA;AACH,CAAC,CAAA;AA7DY,QAAA,cAAc,kBA6D1B;AAED,SAAe,sBAAsB,CACnC,QAAkB;;;;;;;wBAGhB,MAAM,EAAE,QAAQ,CAAC,MAAM;wBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;wBAC/B,OAAO,EAAE,kCAAe,CAAC,kCAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;;oBACrD,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;wBAJ7B,uBAIE,OAAI,GAAE,SAAqB;6BAC5B;;;;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mswjs/interceptors",
|
|
3
3
|
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.4",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"author": "Artem Zakharchenko",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"express-rate-limit": "^5.5.1",
|
|
52
52
|
"got": "^11.8.3",
|
|
53
53
|
"jest": "^27.4.3",
|
|
54
|
-
"node-fetch": "2.6.
|
|
54
|
+
"node-fetch": "2.6.7",
|
|
55
55
|
"page-with": "^0.5.1",
|
|
56
56
|
"rimraf": "^3.0.2",
|
|
57
57
|
"simple-git-hooks": "^2.7.0",
|
|
@@ -20,9 +20,9 @@ export const interceptFetch: Interceptor = (observer, resolver) => {
|
|
|
20
20
|
debug('replacing "window.fetch"...')
|
|
21
21
|
|
|
22
22
|
window.fetch = async (input, init) => {
|
|
23
|
-
const
|
|
23
|
+
const request = new Request(input, init)
|
|
24
24
|
const url = typeof input === 'string' ? input : input.url
|
|
25
|
-
const method =
|
|
25
|
+
const method = request.method
|
|
26
26
|
|
|
27
27
|
debug('[%s] %s', method, url)
|
|
28
28
|
|
|
@@ -30,15 +30,15 @@ export const interceptFetch: Interceptor = (observer, resolver) => {
|
|
|
30
30
|
id: uuidv4(),
|
|
31
31
|
url: new URL(url, location.origin),
|
|
32
32
|
method: method,
|
|
33
|
-
headers: new Headers(
|
|
34
|
-
credentials:
|
|
35
|
-
body: await
|
|
33
|
+
headers: new Headers(request.headers),
|
|
34
|
+
credentials: request.credentials,
|
|
35
|
+
body: await request.clone().text(),
|
|
36
36
|
}
|
|
37
37
|
debug('isomorphic request', isoRequest)
|
|
38
38
|
observer.emit('request', isoRequest)
|
|
39
39
|
|
|
40
40
|
debug('awaiting for the mocked response...')
|
|
41
|
-
const response = await resolver(isoRequest,
|
|
41
|
+
const response = await resolver(isoRequest, request)
|
|
42
42
|
debug('mocked response', response)
|
|
43
43
|
|
|
44
44
|
if (response) {
|
|
@@ -58,7 +58,7 @@ export const interceptFetch: Interceptor = (observer, resolver) => {
|
|
|
58
58
|
|
|
59
59
|
debug('no mocked response found, bypassing...')
|
|
60
60
|
|
|
61
|
-
return pureFetch(
|
|
61
|
+
return pureFetch(request).then(async (response) => {
|
|
62
62
|
const cloneResponse = response.clone()
|
|
63
63
|
debug('original fetch performed', cloneResponse)
|
|
64
64
|
|