@mswjs/interceptors 0.25.8 → 0.25.10
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/lib/browser/{chunk-ECJJD4T6.js → chunk-5RW2GLTJ.js} +13 -1
- package/lib/browser/{chunk-XIF5PZER.mjs → chunk-KRADPSOF.mjs} +13 -1
- package/lib/browser/{chunk-QOFKGEDX.mjs → chunk-NJQK65MD.mjs} +2 -4
- package/lib/browser/{chunk-XFQ4KKVQ.js → chunk-Y4VZR7HZ.js} +2 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.js +2 -2
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +1 -1
- package/lib/browser/interceptors/fetch/index.js +2 -2
- package/lib/browser/interceptors/fetch/index.mjs +1 -1
- package/lib/browser/presets/browser.js +4 -4
- package/lib/browser/presets/browser.mjs +2 -2
- package/lib/node/RemoteHttpInterceptor.js +5 -4
- package/lib/node/RemoteHttpInterceptor.mjs +3 -2
- package/lib/node/chunk-35HEWOG7.js +13 -0
- package/lib/node/{chunk-MEGFRRJI.js → chunk-HNNMWWZ6.js} +2 -4
- package/lib/node/{chunk-W2OZTHRV.mjs → chunk-JX6GSWVV.mjs} +2 -4
- package/lib/node/chunk-MXSWCQAT.mjs +13 -0
- package/lib/node/{chunk-FWLJEVDW.js → chunk-N65JTHKK.js} +12 -1
- package/lib/node/{chunk-P4CPJLJS.mjs → chunk-Z26AUTER.mjs} +12 -1
- package/lib/node/interceptors/ClientRequest/index.js +3 -2
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -1
- package/lib/node/interceptors/XMLHttpRequest/index.js +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +1 -1
- package/lib/node/interceptors/fetch/index.js +4 -1
- package/lib/node/interceptors/fetch/index.mjs +4 -1
- package/lib/node/presets/node.js +5 -4
- package/lib/node/presets/node.mjs +3 -2
- package/package.json +4 -2
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +11 -1
- package/src/interceptors/fetch/index.ts +5 -1
- package/src/utils/createProxy.ts +4 -4
- package/src/utils/isPropertyAccessible.ts +19 -0
|
@@ -12,6 +12,18 @@ var _chunkG5ORGOKHjs = require('./chunk-G5ORGOKH.js');
|
|
|
12
12
|
var _outvariant = require('outvariant');
|
|
13
13
|
var _deferredpromise = require('@open-draft/deferred-promise');
|
|
14
14
|
var _until = require('@open-draft/until');
|
|
15
|
+
|
|
16
|
+
// src/utils/isPropertyAccessible.ts
|
|
17
|
+
function isPropertyAccessible(obj, key) {
|
|
18
|
+
try {
|
|
19
|
+
obj[key];
|
|
20
|
+
return true;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/interceptors/fetch/index.ts
|
|
15
27
|
var _FetchInterceptor = class extends _chunkG5ORGOKHjs.Interceptor {
|
|
16
28
|
constructor() {
|
|
17
29
|
super(_FetchInterceptor.symbol);
|
|
@@ -80,7 +92,7 @@ var _FetchInterceptor = class extends _chunkG5ORGOKHjs.Interceptor {
|
|
|
80
92
|
const mockedResponse = resolverResult.data;
|
|
81
93
|
if (mockedResponse && !((_a = request.signal) == null ? void 0 : _a.aborted)) {
|
|
82
94
|
this.logger.info("received mocked response:", mockedResponse);
|
|
83
|
-
if (mockedResponse.type === "error") {
|
|
95
|
+
if (isPropertyAccessible(mockedResponse, "type") && mockedResponse.type === "error") {
|
|
84
96
|
this.logger.info(
|
|
85
97
|
"received a network error response, rejecting the request promise..."
|
|
86
98
|
);
|
|
@@ -12,6 +12,18 @@ import {
|
|
|
12
12
|
import { invariant } from "outvariant";
|
|
13
13
|
import { DeferredPromise } from "@open-draft/deferred-promise";
|
|
14
14
|
import { until } from "@open-draft/until";
|
|
15
|
+
|
|
16
|
+
// src/utils/isPropertyAccessible.ts
|
|
17
|
+
function isPropertyAccessible(obj, key) {
|
|
18
|
+
try {
|
|
19
|
+
obj[key];
|
|
20
|
+
return true;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/interceptors/fetch/index.ts
|
|
15
27
|
var _FetchInterceptor = class extends Interceptor {
|
|
16
28
|
constructor() {
|
|
17
29
|
super(_FetchInterceptor.symbol);
|
|
@@ -80,7 +92,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
80
92
|
const mockedResponse = resolverResult.data;
|
|
81
93
|
if (mockedResponse && !((_a = request.signal) == null ? void 0 : _a.aborted)) {
|
|
82
94
|
this.logger.info("received mocked response:", mockedResponse);
|
|
83
|
-
if (mockedResponse.type === "error") {
|
|
95
|
+
if (isPropertyAccessible(mockedResponse, "type") && mockedResponse.type === "error") {
|
|
84
96
|
this.logger.info(
|
|
85
97
|
"received a network error response, rejecting the request promise..."
|
|
86
98
|
);
|
|
@@ -136,11 +136,9 @@ function optionsToProxyHandler(options) {
|
|
|
136
136
|
return constructorCall.call(newTarget, args, next);
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
handler.set = function(target, propertyName, nextValue
|
|
139
|
+
handler.set = function(target, propertyName, nextValue) {
|
|
140
140
|
const next = () => {
|
|
141
|
-
const propertySource = findPropertySource(target, propertyName);
|
|
142
|
-
if (propertySource === null)
|
|
143
|
-
return false;
|
|
141
|
+
const propertySource = findPropertySource(target, propertyName) || target;
|
|
144
142
|
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
145
143
|
propertySource,
|
|
146
144
|
propertyName
|
|
@@ -136,11 +136,9 @@ function optionsToProxyHandler(options) {
|
|
|
136
136
|
return constructorCall.call(newTarget, args, next);
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
handler.set = function(target, propertyName, nextValue
|
|
139
|
+
handler.set = function(target, propertyName, nextValue) {
|
|
140
140
|
const next = () => {
|
|
141
|
-
const propertySource = findPropertySource(target, propertyName);
|
|
142
|
-
if (propertySource === null)
|
|
143
|
-
return false;
|
|
141
|
+
const propertySource = findPropertySource(target, propertyName) || target;
|
|
144
142
|
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
145
143
|
propertySource,
|
|
146
144
|
propertyName
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkY4VZR7HZjs = require('../../chunk-Y4VZR7HZ.js');
|
|
4
4
|
require('../../chunk-3LFH2WCF.js');
|
|
5
5
|
require('../../chunk-X3NRJIZW.js');
|
|
6
6
|
require('../../chunk-G5ORGOKH.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.XMLHttpRequestInterceptor =
|
|
9
|
+
exports.XMLHttpRequestInterceptor = _chunkY4VZR7HZjs.XMLHttpRequestInterceptor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk5RW2GLTJjs = require('../../chunk-5RW2GLTJ.js');
|
|
4
4
|
require('../../chunk-X3NRJIZW.js');
|
|
5
5
|
require('../../chunk-G5ORGOKH.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.FetchInterceptor =
|
|
8
|
+
exports.FetchInterceptor = _chunk5RW2GLTJjs.FetchInterceptor;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkY4VZR7HZjs = require('../chunk-Y4VZR7HZ.js');
|
|
4
4
|
require('../chunk-3LFH2WCF.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk5RW2GLTJjs = require('../chunk-5RW2GLTJ.js');
|
|
8
8
|
require('../chunk-X3NRJIZW.js');
|
|
9
9
|
require('../chunk-G5ORGOKH.js');
|
|
10
10
|
|
|
11
11
|
// src/presets/browser.ts
|
|
12
12
|
var browser_default = [
|
|
13
|
-
new (0,
|
|
14
|
-
new (0,
|
|
13
|
+
new (0, _chunk5RW2GLTJjs.FetchInterceptor)(),
|
|
14
|
+
new (0, _chunkY4VZR7HZjs.XMLHttpRequestInterceptor)()
|
|
15
15
|
];
|
|
16
16
|
|
|
17
17
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
XMLHttpRequestInterceptor
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-NJQK65MD.mjs";
|
|
4
4
|
import "../chunk-7II4SWKS.mjs";
|
|
5
5
|
import {
|
|
6
6
|
FetchInterceptor
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-KRADPSOF.mjs";
|
|
8
8
|
import "../chunk-KK6APRON.mjs";
|
|
9
9
|
import "../chunk-S72SKXXQ.mjs";
|
|
10
10
|
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
var _chunkAA4NWHDYjs = require('./chunk-AA4NWHDY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkN65JTHKKjs = require('./chunk-N65JTHKK.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkHNNMWWZ6js = require('./chunk-HNNMWWZ6.js');
|
|
10
10
|
require('./chunk-3LFH2WCF.js');
|
|
11
11
|
require('./chunk-OGN3ZR35.js');
|
|
12
|
+
require('./chunk-35HEWOG7.js');
|
|
12
13
|
require('./chunk-VQ4DZOBB.js');
|
|
13
14
|
|
|
14
15
|
|
|
@@ -24,8 +25,8 @@ var RemoteHttpInterceptor = class extends _chunkAA4NWHDYjs.BatchInterceptor {
|
|
|
24
25
|
super({
|
|
25
26
|
name: "remote-interceptor",
|
|
26
27
|
interceptors: [
|
|
27
|
-
new (0,
|
|
28
|
-
new (0,
|
|
28
|
+
new (0, _chunkN65JTHKKjs.ClientRequestInterceptor)(),
|
|
29
|
+
new (0, _chunkHNNMWWZ6js.XMLHttpRequestInterceptor)()
|
|
29
30
|
]
|
|
30
31
|
});
|
|
31
32
|
}
|
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-LNYHQTKT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ClientRequestInterceptor
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z26AUTER.mjs";
|
|
7
7
|
import {
|
|
8
8
|
XMLHttpRequestInterceptor
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JX6GSWVV.mjs";
|
|
10
10
|
import "./chunk-7II4SWKS.mjs";
|
|
11
11
|
import "./chunk-3IYIKC3X.mjs";
|
|
12
|
+
import "./chunk-MXSWCQAT.mjs";
|
|
12
13
|
import "./chunk-GFH37L5D.mjs";
|
|
13
14
|
import {
|
|
14
15
|
emitAsync,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/isPropertyAccessible.ts
|
|
2
|
+
function isPropertyAccessible(obj, key) {
|
|
3
|
+
try {
|
|
4
|
+
obj[key];
|
|
5
|
+
return true;
|
|
6
|
+
} catch (e) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.isPropertyAccessible = isPropertyAccessible;
|
|
@@ -141,11 +141,9 @@ function optionsToProxyHandler(options) {
|
|
|
141
141
|
return constructorCall.call(newTarget, args, next);
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
handler.set = function(target, propertyName, nextValue
|
|
144
|
+
handler.set = function(target, propertyName, nextValue) {
|
|
145
145
|
const next = () => {
|
|
146
|
-
const propertySource = findPropertySource(target, propertyName);
|
|
147
|
-
if (propertySource === null)
|
|
148
|
-
return false;
|
|
146
|
+
const propertySource = findPropertySource(target, propertyName) || target;
|
|
149
147
|
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
150
148
|
propertySource,
|
|
151
149
|
propertyName
|
|
@@ -141,11 +141,9 @@ function optionsToProxyHandler(options) {
|
|
|
141
141
|
return constructorCall.call(newTarget, args, next);
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
handler.set = function(target, propertyName, nextValue
|
|
144
|
+
handler.set = function(target, propertyName, nextValue) {
|
|
145
145
|
const next = () => {
|
|
146
|
-
const propertySource = findPropertySource(target, propertyName);
|
|
147
|
-
if (propertySource === null)
|
|
148
|
-
return false;
|
|
146
|
+
const propertySource = findPropertySource(target, propertyName) || target;
|
|
149
147
|
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
150
148
|
propertySource,
|
|
151
149
|
propertyName
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
var _chunkOGN3ZR35js = require('./chunk-OGN3ZR35.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
var _chunk35HEWOG7js = require('./chunk-35HEWOG7.js');
|
|
7
|
+
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
var _chunk5PTPJLB7js = require('./chunk-5PTPJLB7.js');
|
|
@@ -321,7 +324,15 @@ var _NodeClientRequest = class extends _http.ClientRequest {
|
|
|
321
324
|
mockedResponse.statusText
|
|
322
325
|
);
|
|
323
326
|
this.destroyed = false;
|
|
324
|
-
if (
|
|
327
|
+
if (
|
|
328
|
+
/**
|
|
329
|
+
* @note Some environments, like Miniflare (Cloudflare) do not
|
|
330
|
+
* implement the "Response.type" property and throw on its access.
|
|
331
|
+
* Safely check if we can access "type" on "Response" before continuing.
|
|
332
|
+
* @see https://github.com/mswjs/msw/issues/1834
|
|
333
|
+
*/
|
|
334
|
+
_chunk35HEWOG7js.isPropertyAccessible.call(void 0, mockedResponse, "type") && mockedResponse.type === "error"
|
|
335
|
+
) {
|
|
325
336
|
this.logger.info(
|
|
326
337
|
"received network error response, aborting request..."
|
|
327
338
|
);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
responseStatusCodesWithoutBody
|
|
3
3
|
} from "./chunk-3IYIKC3X.mjs";
|
|
4
|
+
import {
|
|
5
|
+
isPropertyAccessible
|
|
6
|
+
} from "./chunk-MXSWCQAT.mjs";
|
|
4
7
|
import {
|
|
5
8
|
emitAsync,
|
|
6
9
|
toInteractiveRequest,
|
|
@@ -321,7 +324,15 @@ var _NodeClientRequest = class extends ClientRequest {
|
|
|
321
324
|
mockedResponse.statusText
|
|
322
325
|
);
|
|
323
326
|
this.destroyed = false;
|
|
324
|
-
if (
|
|
327
|
+
if (
|
|
328
|
+
/**
|
|
329
|
+
* @note Some environments, like Miniflare (Cloudflare) do not
|
|
330
|
+
* implement the "Response.type" property and throw on its access.
|
|
331
|
+
* Safely check if we can access "type" on "Response" before continuing.
|
|
332
|
+
* @see https://github.com/mswjs/msw/issues/1834
|
|
333
|
+
*/
|
|
334
|
+
isPropertyAccessible(mockedResponse, "type") && mockedResponse.type === "error"
|
|
335
|
+
) {
|
|
325
336
|
this.logger.info(
|
|
326
337
|
"received network error response, aborting request..."
|
|
327
338
|
);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkN65JTHKKjs = require('../../chunk-N65JTHKK.js');
|
|
4
4
|
require('../../chunk-OGN3ZR35.js');
|
|
5
|
+
require('../../chunk-35HEWOG7.js');
|
|
5
6
|
require('../../chunk-5PTPJLB7.js');
|
|
6
7
|
require('../../chunk-UZM2Y7WJ.js');
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
exports.ClientRequestInterceptor =
|
|
10
|
+
exports.ClientRequestInterceptor = _chunkN65JTHKKjs.ClientRequestInterceptor;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-Z26AUTER.mjs";
|
|
4
4
|
import "../../chunk-3IYIKC3X.mjs";
|
|
5
|
+
import "../../chunk-MXSWCQAT.mjs";
|
|
5
6
|
import "../../chunk-YQGTMMOZ.mjs";
|
|
6
7
|
import "../../chunk-JAW6F2FR.mjs";
|
|
7
8
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHNNMWWZ6js = require('../../chunk-HNNMWWZ6.js');
|
|
4
4
|
require('../../chunk-3LFH2WCF.js');
|
|
5
5
|
require('../../chunk-OGN3ZR35.js');
|
|
6
6
|
require('../../chunk-VQ4DZOBB.js');
|
|
@@ -8,4 +8,4 @@ require('../../chunk-5PTPJLB7.js');
|
|
|
8
8
|
require('../../chunk-UZM2Y7WJ.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.XMLHttpRequestInterceptor =
|
|
11
|
+
exports.XMLHttpRequestInterceptor = _chunkHNNMWWZ6js.XMLHttpRequestInterceptor;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
+
var _chunk35HEWOG7js = require('../../chunk-35HEWOG7.js');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
var _chunkVQ4DZOBBjs = require('../../chunk-VQ4DZOBB.js');
|
|
4
7
|
|
|
5
8
|
|
|
@@ -82,7 +85,7 @@ var _FetchInterceptor = class extends _chunkUZM2Y7WJjs.Interceptor {
|
|
|
82
85
|
const mockedResponse = resolverResult.data;
|
|
83
86
|
if (mockedResponse && !((_a = request.signal) == null ? void 0 : _a.aborted)) {
|
|
84
87
|
this.logger.info("received mocked response:", mockedResponse);
|
|
85
|
-
if (mockedResponse.type === "error") {
|
|
88
|
+
if (_chunk35HEWOG7js.isPropertyAccessible.call(void 0, mockedResponse, "type") && mockedResponse.type === "error") {
|
|
86
89
|
this.logger.info(
|
|
87
90
|
"received a network error response, rejecting the request promise..."
|
|
88
91
|
);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPropertyAccessible
|
|
3
|
+
} from "../../chunk-MXSWCQAT.mjs";
|
|
1
4
|
import {
|
|
2
5
|
IS_PATCHED_MODULE
|
|
3
6
|
} from "../../chunk-GFH37L5D.mjs";
|
|
@@ -82,7 +85,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
82
85
|
const mockedResponse = resolverResult.data;
|
|
83
86
|
if (mockedResponse && !((_a = request.signal) == null ? void 0 : _a.aborted)) {
|
|
84
87
|
this.logger.info("received mocked response:", mockedResponse);
|
|
85
|
-
if (mockedResponse.type === "error") {
|
|
88
|
+
if (isPropertyAccessible(mockedResponse, "type") && mockedResponse.type === "error") {
|
|
86
89
|
this.logger.info(
|
|
87
90
|
"received a network error response, rejecting the request promise..."
|
|
88
91
|
);
|
package/lib/node/presets/node.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkN65JTHKKjs = require('../chunk-N65JTHKK.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkHNNMWWZ6js = require('../chunk-HNNMWWZ6.js');
|
|
7
7
|
require('../chunk-3LFH2WCF.js');
|
|
8
8
|
require('../chunk-OGN3ZR35.js');
|
|
9
|
+
require('../chunk-35HEWOG7.js');
|
|
9
10
|
require('../chunk-VQ4DZOBB.js');
|
|
10
11
|
require('../chunk-5PTPJLB7.js');
|
|
11
12
|
require('../chunk-UZM2Y7WJ.js');
|
|
12
13
|
|
|
13
14
|
// src/presets/node.ts
|
|
14
15
|
var node_default = [
|
|
15
|
-
new (0,
|
|
16
|
-
new (0,
|
|
16
|
+
new (0, _chunkN65JTHKKjs.ClientRequestInterceptor)(),
|
|
17
|
+
new (0, _chunkHNNMWWZ6js.XMLHttpRequestInterceptor)()
|
|
17
18
|
];
|
|
18
19
|
|
|
19
20
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientRequestInterceptor
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-Z26AUTER.mjs";
|
|
4
4
|
import {
|
|
5
5
|
XMLHttpRequestInterceptor
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-JX6GSWVV.mjs";
|
|
7
7
|
import "../chunk-7II4SWKS.mjs";
|
|
8
8
|
import "../chunk-3IYIKC3X.mjs";
|
|
9
|
+
import "../chunk-MXSWCQAT.mjs";
|
|
9
10
|
import "../chunk-GFH37L5D.mjs";
|
|
10
11
|
import "../chunk-YQGTMMOZ.mjs";
|
|
11
12
|
import "../chunk-JAW6F2FR.mjs";
|
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.25.
|
|
4
|
+
"version": "0.25.10",
|
|
5
5
|
"main": "./lib/node/index.js",
|
|
6
6
|
"module": "./lib/node/index.mjs",
|
|
7
7
|
"types": "./lib/node/index.d.ts",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"@types/node": "^16.11.26",
|
|
99
99
|
"@types/node-fetch": "2.5.12",
|
|
100
100
|
"@types/supertest": "^2.0.11",
|
|
101
|
-
"axios": "^
|
|
101
|
+
"axios": "^1.6.0",
|
|
102
102
|
"body-parser": "^1.19.0",
|
|
103
103
|
"commitizen": "^4.2.4",
|
|
104
104
|
"cors": "^2.8.5",
|
|
@@ -108,6 +108,7 @@
|
|
|
108
108
|
"express-rate-limit": "^6.3.0",
|
|
109
109
|
"follow-redirects": "^1.15.1",
|
|
110
110
|
"got": "^11.8.3",
|
|
111
|
+
"happy-dom": "^12.10.3",
|
|
111
112
|
"jest": "^27.4.3",
|
|
112
113
|
"node-fetch": "2.6.7",
|
|
113
114
|
"rimraf": "^3.0.2",
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
"tsup": "^6.5.0",
|
|
119
120
|
"typescript": "^4.9.4",
|
|
120
121
|
"vitest": "^0.28.5",
|
|
122
|
+
"vitest-environment-miniflare": "^2.14.1",
|
|
121
123
|
"wait-for-expect": "^3.0.2",
|
|
122
124
|
"web-encoding": "^1.1.5",
|
|
123
125
|
"webpack-http-server": "^0.5.0"
|
|
@@ -20,6 +20,7 @@ import { toInteractiveRequest } from '../../utils/toInteractiveRequest'
|
|
|
20
20
|
import { uuidv4 } from '../../utils/uuid'
|
|
21
21
|
import { emitAsync } from '../../utils/emitAsync'
|
|
22
22
|
import { getRawFetchHeaders } from '../../utils/getRawFetchHeaders'
|
|
23
|
+
import { isPropertyAccessible } from '../../utils/isPropertyAccessible'
|
|
23
24
|
|
|
24
25
|
export type Protocol = 'http' | 'https'
|
|
25
26
|
|
|
@@ -287,7 +288,16 @@ export class NodeClientRequest extends ClientRequest {
|
|
|
287
288
|
this.destroyed = false
|
|
288
289
|
|
|
289
290
|
// Handle mocked "Response.error" network error responses.
|
|
290
|
-
if (
|
|
291
|
+
if (
|
|
292
|
+
/**
|
|
293
|
+
* @note Some environments, like Miniflare (Cloudflare) do not
|
|
294
|
+
* implement the "Response.type" property and throw on its access.
|
|
295
|
+
* Safely check if we can access "type" on "Response" before continuing.
|
|
296
|
+
* @see https://github.com/mswjs/msw/issues/1834
|
|
297
|
+
*/
|
|
298
|
+
isPropertyAccessible(mockedResponse, 'type') &&
|
|
299
|
+
mockedResponse.type === 'error'
|
|
300
|
+
) {
|
|
291
301
|
this.logger.info(
|
|
292
302
|
'received network error response, aborting request...'
|
|
293
303
|
)
|
|
@@ -6,6 +6,7 @@ import { Interceptor } from '../../Interceptor'
|
|
|
6
6
|
import { uuidv4 } from '../../utils/uuid'
|
|
7
7
|
import { toInteractiveRequest } from '../../utils/toInteractiveRequest'
|
|
8
8
|
import { emitAsync } from '../../utils/emitAsync'
|
|
9
|
+
import { isPropertyAccessible } from '../../utils/isPropertyAccessible'
|
|
9
10
|
|
|
10
11
|
export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
11
12
|
static symbol = Symbol('fetch')
|
|
@@ -103,7 +104,10 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
|
103
104
|
this.logger.info('received mocked response:', mockedResponse)
|
|
104
105
|
|
|
105
106
|
// Reject the request Promise on mocked "Response.error" responses.
|
|
106
|
-
if (
|
|
107
|
+
if (
|
|
108
|
+
isPropertyAccessible(mockedResponse, 'type') &&
|
|
109
|
+
mockedResponse.type === 'error'
|
|
110
|
+
) {
|
|
107
111
|
this.logger.info(
|
|
108
112
|
'received a network error response, rejecting the request promise...'
|
|
109
113
|
)
|
package/src/utils/createProxy.ts
CHANGED
|
@@ -44,21 +44,21 @@ function optionsToProxyHandler<T extends Record<string, any>>(
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
handler.set = function (target, propertyName, nextValue
|
|
47
|
+
handler.set = function (target, propertyName, nextValue) {
|
|
48
48
|
const next = () => {
|
|
49
|
-
const propertySource = findPropertySource(target, propertyName)
|
|
50
|
-
if (propertySource === null) return false
|
|
51
|
-
|
|
49
|
+
const propertySource = findPropertySource(target, propertyName) || target
|
|
52
50
|
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
53
51
|
propertySource,
|
|
54
52
|
propertyName
|
|
55
53
|
)
|
|
56
54
|
|
|
55
|
+
// Respect any custom setters present for this property.
|
|
57
56
|
if (typeof ownDescriptors?.set !== 'undefined') {
|
|
58
57
|
ownDescriptors.set.apply(target, [nextValue])
|
|
59
58
|
return true
|
|
60
59
|
}
|
|
61
60
|
|
|
61
|
+
// Otherwise, set the property on the source.
|
|
62
62
|
return Reflect.defineProperty(propertySource, propertyName, {
|
|
63
63
|
writable: true,
|
|
64
64
|
enumerable: true,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that validates if property access is possible on an object
|
|
3
|
+
* without throwing. It returns `true` if the property access is possible
|
|
4
|
+
* and `false` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* Environments like miniflare will throw on property access on certain objects
|
|
7
|
+
* like Request and Response, for unimplemented properties.
|
|
8
|
+
*/
|
|
9
|
+
export function isPropertyAccessible<Obj extends Record<string, any>>(
|
|
10
|
+
obj: Obj,
|
|
11
|
+
key: keyof Obj
|
|
12
|
+
) {
|
|
13
|
+
try {
|
|
14
|
+
obj[key]
|
|
15
|
+
return true
|
|
16
|
+
} catch {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|