@mswjs/interceptors 0.25.9 → 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/interceptors/fetch/index.js +2 -2
- package/lib/browser/interceptors/fetch/index.mjs +1 -1
- package/lib/browser/presets/browser.js +2 -2
- package/lib/browser/presets/browser.mjs +1 -1
- package/lib/node/RemoteHttpInterceptor.js +3 -2
- package/lib/node/RemoteHttpInterceptor.mjs +2 -1
- package/lib/node/chunk-35HEWOG7.js +13 -0
- 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/fetch/index.js +4 -1
- package/lib/node/interceptors/fetch/index.mjs +4 -1
- package/lib/node/presets/node.js +3 -2
- package/lib/node/presets/node.mjs +2 -1
- package/package.json +2 -1
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +11 -1
- package/src/interceptors/fetch/index.ts +5 -1
- 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
|
);
|
|
@@ -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;
|
|
@@ -4,13 +4,13 @@ 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,
|
|
13
|
+
new (0, _chunk5RW2GLTJjs.FetchInterceptor)(),
|
|
14
14
|
new (0, _chunkY4VZR7HZjs.XMLHttpRequestInterceptor)()
|
|
15
15
|
];
|
|
16
16
|
|
|
@@ -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
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,7 +25,7 @@ var RemoteHttpInterceptor = class extends _chunkAA4NWHDYjs.BatchInterceptor {
|
|
|
24
25
|
super({
|
|
25
26
|
name: "remote-interceptor",
|
|
26
27
|
interceptors: [
|
|
27
|
-
new (0,
|
|
28
|
+
new (0, _chunkN65JTHKKjs.ClientRequestInterceptor)(),
|
|
28
29
|
new (0, _chunkHNNMWWZ6js.XMLHttpRequestInterceptor)()
|
|
29
30
|
]
|
|
30
31
|
});
|
|
@@ -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
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;
|
|
@@ -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,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,18 +1,19 @@
|
|
|
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
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, _chunkN65JTHKKjs.ClientRequestInterceptor)(),
|
|
16
17
|
new (0, _chunkHNNMWWZ6js.XMLHttpRequestInterceptor)()
|
|
17
18
|
];
|
|
18
19
|
|
|
@@ -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
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",
|
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
"tsup": "^6.5.0",
|
|
120
120
|
"typescript": "^4.9.4",
|
|
121
121
|
"vitest": "^0.28.5",
|
|
122
|
+
"vitest-environment-miniflare": "^2.14.1",
|
|
122
123
|
"wait-for-expect": "^3.0.2",
|
|
123
124
|
"web-encoding": "^1.1.5",
|
|
124
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
|
)
|
|
@@ -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
|
+
}
|