Update checked-in dependencies

This commit is contained in:
github-actions[bot] 2025-04-02 12:43:14 +00:00
parent 4b72bef651
commit dbb232a3d8
1389 changed files with 209949 additions and 542 deletions

View file

@ -254,6 +254,7 @@ var _FetchInterceptor = class extends _chunkTIPR373Rjs.Interceptor {
this.logger.info(
"no mocked response received, performing request as-is..."
);
const requestCloneForResponseEvent = request.clone();
return pureFetch(request).then(async (response) => {
this.logger.info("original fetch performed", response);
if (this.emitter.listenerCount("response") > 0) {
@ -262,7 +263,7 @@ var _FetchInterceptor = class extends _chunkTIPR373Rjs.Interceptor {
await _chunkFGSEOIC4js.emitAsync.call(void 0, this.emitter, "response", {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId
});
}
@ -292,4 +293,4 @@ FetchInterceptor.symbol = Symbol("fetch");
exports.FetchInterceptor = FetchInterceptor;
//# sourceMappingURL=chunk-QVOTKFTB.js.map
//# sourceMappingURL=chunk-P3AXGLYB.js.map

View file

@ -254,6 +254,7 @@ var _FetchInterceptor = class extends Interceptor {
this.logger.info(
"no mocked response received, performing request as-is..."
);
const requestCloneForResponseEvent = request.clone();
return pureFetch(request).then(async (response) => {
this.logger.info("original fetch performed", response);
if (this.emitter.listenerCount("response") > 0) {
@ -262,7 +263,7 @@ var _FetchInterceptor = class extends Interceptor {
await emitAsync(this.emitter, "response", {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId
});
}
@ -292,4 +293,4 @@ FetchInterceptor.symbol = Symbol("fetch");
export {
FetchInterceptor
};
//# sourceMappingURL=chunk-XTX2SIN6.mjs.map
//# sourceMappingURL=chunk-PBC2PID2.mjs.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,11 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunkQVOTKFTBjs = require('../../chunk-QVOTKFTB.js');
var _chunkP3AXGLYBjs = require('../../chunk-P3AXGLYB.js');
require('../../chunk-FGSEOIC4.js');
require('../../chunk-BC2BLJQN.js');
require('../../chunk-PFGO5BSM.js');
require('../../chunk-TIPR373R.js');
exports.FetchInterceptor = _chunkQVOTKFTBjs.FetchInterceptor;
exports.FetchInterceptor = _chunkP3AXGLYBjs.FetchInterceptor;
//# sourceMappingURL=index.js.map

View file

@ -1,6 +1,6 @@
import {
FetchInterceptor
} from "../../chunk-XTX2SIN6.mjs";
} from "../../chunk-PBC2PID2.mjs";
import "../../chunk-H5O73WD2.mjs";
import "../../chunk-5UK33FSU.mjs";
import "../../chunk-TX5GBTFY.mjs";

View file

@ -4,7 +4,7 @@ var _chunkZIT2QX7Djs = require('../chunk-ZIT2QX7D.js');
require('../chunk-LK6DILFK.js');
var _chunkQVOTKFTBjs = require('../chunk-QVOTKFTB.js');
var _chunkP3AXGLYBjs = require('../chunk-P3AXGLYB.js');
require('../chunk-FGSEOIC4.js');
require('../chunk-BC2BLJQN.js');
require('../chunk-PFGO5BSM.js');
@ -12,7 +12,7 @@ require('../chunk-TIPR373R.js');
// src/presets/browser.ts
var browser_default = [
new (0, _chunkQVOTKFTBjs.FetchInterceptor)(),
new (0, _chunkP3AXGLYBjs.FetchInterceptor)(),
new (0, _chunkZIT2QX7Djs.XMLHttpRequestInterceptor)()
];

View file

@ -4,7 +4,7 @@ import {
import "../chunk-6HYIRFX2.mjs";
import {
FetchInterceptor
} from "../chunk-XTX2SIN6.mjs";
} from "../chunk-PBC2PID2.mjs";
import "../chunk-H5O73WD2.mjs";
import "../chunk-5UK33FSU.mjs";
import "../chunk-TX5GBTFY.mjs";

View file

@ -3,6 +3,7 @@ import { h as Interceptor, H as HttpRequestEventMap } from './Interceptor-436630
import { a as BatchInterceptor } from './BatchInterceptor-67bf41ba.js';
import { ClientRequestInterceptor } from './interceptors/ClientRequest/index.js';
import { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest/index.js';
import { FetchInterceptor } from './interceptors/fetch/index.js';
import '@open-draft/deferred-promise';
import '@open-draft/logger';
import 'strict-event-emitter';
@ -24,7 +25,8 @@ interface SerializedResponse {
}
declare class RemoteHttpInterceptor extends BatchInterceptor<[
ClientRequestInterceptor,
XMLHttpRequestInterceptor
XMLHttpRequestInterceptor,
FetchInterceptor
]> {
constructor();
protected setup(): void;

View file

@ -3,11 +3,14 @@
var _chunkYBN5MFAPjs = require('./chunk-YBN5MFAP.js');
var _chunk4IGRW7SKjs = require('./chunk-4IGRW7SK.js');
var _chunk3HCE66HZjs = require('./chunk-3HCE66HZ.js');
var _chunkLCA4FKWYjs = require('./chunk-LCA4FKWY.js');
require('./chunk-LK6DILFK.js');
var _chunkCF5C3K5Ujs = require('./chunk-CF5C3K5U.js');
require('./chunk-PFGO5BSM.js');
require('./chunk-73NOP3T5.js');
@ -25,8 +28,9 @@ var RemoteHttpInterceptor = class extends _chunkYBN5MFAPjs.BatchInterceptor {
super({
name: "remote-interceptor",
interceptors: [
new (0, _chunk4IGRW7SKjs.ClientRequestInterceptor)(),
new (0, _chunkLCA4FKWYjs.XMLHttpRequestInterceptor)()
new (0, _chunk3HCE66HZjs.ClientRequestInterceptor)(),
new (0, _chunkLCA4FKWYjs.XMLHttpRequestInterceptor)(),
new (0, _chunkCF5C3K5Ujs.FetchInterceptor)()
]
});
}

File diff suppressed because one or more lines are too long

View file

@ -3,11 +3,14 @@ import {
} from "./chunk-PJA4E426.mjs";
import {
ClientRequestInterceptor
} from "./chunk-QFFDMWKW.mjs";
} from "./chunk-FWJSC2QD.mjs";
import {
XMLHttpRequestInterceptor
} from "./chunk-OMWE7UVM.mjs";
import "./chunk-6HYIRFX2.mjs";
import {
FetchInterceptor
} from "./chunk-ZSYLU3GR.mjs";
import "./chunk-TX5GBTFY.mjs";
import "./chunk-6YM4PLBI.mjs";
import {
@ -26,7 +29,8 @@ var RemoteHttpInterceptor = class extends BatchInterceptor {
name: "remote-interceptor",
interceptors: [
new ClientRequestInterceptor(),
new XMLHttpRequestInterceptor()
new XMLHttpRequestInterceptor(),
new FetchInterceptor()
]
});
}

File diff suppressed because one or more lines are too long

View file

@ -630,12 +630,16 @@ var MockAgent = class extends _http2.default.Agent {
this.onResponse = options.onResponse;
}
createConnection(options, callback) {
const createConnection = this.customAgent instanceof _http2.default.Agent && this.customAgent.createConnection || super.createConnection;
const createConnection = this.customAgent instanceof _http2.default.Agent ? this.customAgent.createConnection : super.createConnection;
const createConnectionOptions = this.customAgent instanceof _http2.default.Agent ? {
...options,
...this.customAgent.options
} : options;
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -652,12 +656,16 @@ var MockHttpsAgent = class extends _https2.default.Agent {
this.onResponse = options.onResponse;
}
createConnection(options, callback) {
const createConnection = this.customAgent instanceof _https2.default.Agent && this.customAgent.createConnection || super.createConnection;
const createConnection = this.customAgent instanceof _https2.default.Agent ? this.customAgent.createConnection : super.createConnection;
const createConnectionOptions = this.customAgent instanceof _https2.default.Agent ? {
...options,
...this.customAgent.options
} : options;
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -903,7 +911,10 @@ function normalizeClientRequestArgs(defaultProtocol, args) {
options.method = options.method || "GET";
if (typeof options.agent === "undefined") {
const agent = options.protocol === "https:" ? new (0, _https.Agent)({
rejectUnauthorized: options.rejectUnauthorized
// Any other value other than false is considered as true, so we don't add this property if undefined.
..."rejectUnauthorized" in options && {
rejectUnauthorized: options.rejectUnauthorized
}
}) : new (0, _http.Agent)();
options.agent = agent;
logger3.info("resolved fallback agent:", agent);
@ -1050,4 +1061,4 @@ ClientRequestInterceptor.symbol = Symbol("client-request-interceptor");
exports.ClientRequestInterceptor = ClientRequestInterceptor;
//# sourceMappingURL=chunk-4IGRW7SK.js.map
//# sourceMappingURL=chunk-3HCE66HZ.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -269,6 +269,7 @@ var _FetchInterceptor = class extends _chunkWZTE4PCOjs.Interceptor {
this.logger.info(
"no mocked response received, performing request as-is..."
);
const requestCloneForResponseEvent = request.clone();
return pureFetch(request).then(async (response) => {
this.logger.info("original fetch performed", response);
if (this.emitter.listenerCount("response") > 0) {
@ -277,7 +278,7 @@ var _FetchInterceptor = class extends _chunkWZTE4PCOjs.Interceptor {
await _chunk6L3PFBGTjs.emitAsync.call(void 0, this.emitter, "response", {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId
});
}
@ -307,4 +308,4 @@ FetchInterceptor.symbol = Symbol("fetch");
exports.FetchInterceptor = FetchInterceptor;
//# sourceMappingURL=chunk-LEA3MUU3.js.map
//# sourceMappingURL=chunk-CF5C3K5U.js.map

File diff suppressed because one or more lines are too long

View file

@ -630,12 +630,16 @@ var MockAgent = class extends http.Agent {
this.onResponse = options.onResponse;
}
createConnection(options, callback) {
const createConnection = this.customAgent instanceof http.Agent && this.customAgent.createConnection || super.createConnection;
const createConnection = this.customAgent instanceof http.Agent ? this.customAgent.createConnection : super.createConnection;
const createConnectionOptions = this.customAgent instanceof http.Agent ? {
...options,
...this.customAgent.options
} : options;
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -652,12 +656,16 @@ var MockHttpsAgent = class extends https.Agent {
this.onResponse = options.onResponse;
}
createConnection(options, callback) {
const createConnection = this.customAgent instanceof https.Agent && this.customAgent.createConnection || super.createConnection;
const createConnection = this.customAgent instanceof https.Agent ? this.customAgent.createConnection : super.createConnection;
const createConnectionOptions = this.customAgent instanceof https.Agent ? {
...options,
...this.customAgent.options
} : options;
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -903,7 +911,10 @@ function normalizeClientRequestArgs(defaultProtocol, args) {
options.method = options.method || "GET";
if (typeof options.agent === "undefined") {
const agent = options.protocol === "https:" ? new HttpsAgent({
rejectUnauthorized: options.rejectUnauthorized
// Any other value other than false is considered as true, so we don't add this property if undefined.
..."rejectUnauthorized" in options && {
rejectUnauthorized: options.rejectUnauthorized
}
}) : new HttpAgent();
options.agent = agent;
logger3.info("resolved fallback agent:", agent);
@ -1050,4 +1061,4 @@ ClientRequestInterceptor.symbol = Symbol("client-request-interceptor");
export {
ClientRequestInterceptor
};
//# sourceMappingURL=chunk-QFFDMWKW.mjs.map
//# sourceMappingURL=chunk-FWJSC2QD.mjs.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -269,6 +269,7 @@ var _FetchInterceptor = class extends Interceptor {
this.logger.info(
"no mocked response received, performing request as-is..."
);
const requestCloneForResponseEvent = request.clone();
return pureFetch(request).then(async (response) => {
this.logger.info("original fetch performed", response);
if (this.emitter.listenerCount("response") > 0) {
@ -277,7 +278,7 @@ var _FetchInterceptor = class extends Interceptor {
await emitAsync(this.emitter, "response", {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId
});
}
@ -307,4 +308,4 @@ FetchInterceptor.symbol = Symbol("fetch");
export {
FetchInterceptor
};
//# sourceMappingURL=chunk-CTGTMEFD.mjs.map
//# sourceMappingURL=chunk-ZSYLU3GR.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk4IGRW7SKjs = require('../../chunk-4IGRW7SK.js');
var _chunk3HCE66HZjs = require('../../chunk-3HCE66HZ.js');
require('../../chunk-6L3PFBGT.js');
require('../../chunk-WZTE4PCO.js');
exports.ClientRequestInterceptor = _chunk4IGRW7SKjs.ClientRequestInterceptor;
exports.ClientRequestInterceptor = _chunk3HCE66HZjs.ClientRequestInterceptor;
//# sourceMappingURL=index.js.map

View file

@ -1,6 +1,6 @@
import {
ClientRequestInterceptor
} from "../../chunk-QFFDMWKW.mjs";
} from "../../chunk-FWJSC2QD.mjs";
import "../../chunk-5KMS5CTP.mjs";
import "../../chunk-I7HQIBT7.mjs";
export {

View file

@ -1,11 +1,11 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunkLEA3MUU3js = require('../../chunk-LEA3MUU3.js');
var _chunkCF5C3K5Ujs = require('../../chunk-CF5C3K5U.js');
require('../../chunk-PFGO5BSM.js');
require('../../chunk-73NOP3T5.js');
require('../../chunk-6L3PFBGT.js');
require('../../chunk-WZTE4PCO.js');
exports.FetchInterceptor = _chunkLEA3MUU3js.FetchInterceptor;
exports.FetchInterceptor = _chunkCF5C3K5Ujs.FetchInterceptor;
//# sourceMappingURL=index.js.map

View file

@ -1,6 +1,6 @@
import {
FetchInterceptor
} from "../../chunk-CTGTMEFD.mjs";
} from "../../chunk-ZSYLU3GR.mjs";
import "../../chunk-TX5GBTFY.mjs";
import "../../chunk-6YM4PLBI.mjs";
import "../../chunk-5KMS5CTP.mjs";

View file

@ -1,13 +1,13 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
var _chunk4IGRW7SKjs = require('../chunk-4IGRW7SK.js');
var _chunk3HCE66HZjs = require('../chunk-3HCE66HZ.js');
var _chunkLCA4FKWYjs = require('../chunk-LCA4FKWY.js');
require('../chunk-LK6DILFK.js');
var _chunkLEA3MUU3js = require('../chunk-LEA3MUU3.js');
var _chunkCF5C3K5Ujs = require('../chunk-CF5C3K5U.js');
require('../chunk-PFGO5BSM.js');
require('../chunk-73NOP3T5.js');
require('../chunk-6L3PFBGT.js');
@ -15,9 +15,9 @@ require('../chunk-WZTE4PCO.js');
// src/presets/node.ts
var node_default = [
new (0, _chunk4IGRW7SKjs.ClientRequestInterceptor)(),
new (0, _chunk3HCE66HZjs.ClientRequestInterceptor)(),
new (0, _chunkLCA4FKWYjs.XMLHttpRequestInterceptor)(),
new (0, _chunkLEA3MUU3js.FetchInterceptor)()
new (0, _chunkCF5C3K5Ujs.FetchInterceptor)()
];

View file

@ -1,13 +1,13 @@
import {
ClientRequestInterceptor
} from "../chunk-QFFDMWKW.mjs";
} from "../chunk-FWJSC2QD.mjs";
import {
XMLHttpRequestInterceptor
} from "../chunk-OMWE7UVM.mjs";
import "../chunk-6HYIRFX2.mjs";
import {
FetchInterceptor
} from "../chunk-CTGTMEFD.mjs";
} from "../chunk-ZSYLU3GR.mjs";
import "../chunk-TX5GBTFY.mjs";
import "../chunk-6YM4PLBI.mjs";
import "../chunk-5KMS5CTP.mjs";

View file

@ -1,7 +1,7 @@
{
"name": "@mswjs/interceptors",
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
"version": "0.37.5",
"version": "0.38.0",
"main": "./lib/node/index.js",
"module": "./lib/node/index.mjs",
"types": "./lib/node/index.d.ts",
@ -110,60 +110,57 @@
"url": "https://github.com/mswjs/interceptors"
},
"devDependencies": {
"@commitlint/cli": "^16.0.2",
"@commitlint/config-conventional": "^16.0.0",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@open-draft/test-server": "^0.5.1",
"@ossjs/release": "^0.8.1",
"@playwright/test": "^1.37.1",
"@playwright/test": "^1.51.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express": "^5.0.0",
"@types/express-fileupload": "^1.5.0",
"@types/express-rate-limit": "^6.0.0",
"@types/follow-redirects": "^1.14.1",
"@types/jest": "^27.0.3",
"@types/node": "^18.19.31",
"@types/node-fetch": "2.5.12",
"@types/node": "^22.13.9",
"@types/node-fetch": "2.6.12",
"@types/superagent": "^8.1.9",
"@types/supertest": "^2.0.11",
"@types/ws": "^8.5.10",
"axios": "^1.6.0",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.18.0",
"axios": "^1.8.2",
"body-parser": "^1.19.0",
"commitizen": "^4.2.4",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "3.3.0",
"engine.io-parser": "^5.2.1",
"express": "^4.17.3",
"express": "^4.21.2",
"express-fileupload": "^1.5.1",
"express-rate-limit": "^6.3.0",
"express-rate-limit": "^7.5.0",
"follow-redirects": "^1.15.1",
"got": "^11.8.3",
"happy-dom": "^12.10.3",
"jest": "^27.4.3",
"node-fetch": "2.6.7",
"rimraf": "^3.0.2",
"got": "^14.4.6",
"happy-dom": "^17.3.0",
"node-fetch": "3.3.2",
"rimraf": "^6.0.1",
"simple-git-hooks": "^2.7.0",
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"socket.io-parser": "^4.2.4",
"superagent": "^10.1.1",
"supertest": "^6.1.6",
"ts-jest": "^27.1.1",
"supertest": "^7.0.0",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"undici": "^6.6.2",
"vitest": "^1.2.2",
"typescript": "^5.8.2",
"undici": "^7.4.0",
"vitest": "^3.0.8",
"vitest-environment-miniflare": "^2.14.1",
"wait-for-expect": "^3.0.2",
"web-encoding": "^1.1.5",
"webpack-http-server": "^0.5.0",
"ws": "^8.16.0"
"ws": "^8.18.1"
},
"dependencies": {
"@open-draft/deferred-promise": "^2.2.0",
"@open-draft/logger": "^0.3.0",
"@open-draft/until": "^2.0.0",
"is-node-process": "^1.2.0",
"jsdom": "^26.0.0",
"outvariant": "^1.4.3",
"strict-event-emitter": "^0.5.1"
},

View file

@ -4,6 +4,7 @@ import { Interceptor } from './Interceptor'
import { BatchInterceptor } from './BatchInterceptor'
import { ClientRequestInterceptor } from './interceptors/ClientRequest'
import { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest'
import { FetchInterceptor } from './interceptors/fetch'
import { handleRequest } from './utils/handleRequest'
import { RequestController } from './RequestController'
import { FetchResponse } from './utils/fetchUtils'
@ -30,7 +31,7 @@ export interface SerializedResponse {
}
export class RemoteHttpInterceptor extends BatchInterceptor<
[ClientRequestInterceptor, XMLHttpRequestInterceptor]
[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]
> {
constructor() {
super({
@ -38,6 +39,7 @@ export class RemoteHttpInterceptor extends BatchInterceptor<
interceptors: [
new ClientRequestInterceptor(),
new XMLHttpRequestInterceptor(),
new FetchInterceptor(),
],
})
}

View file

@ -9,6 +9,7 @@ import {
declare module 'node:http' {
interface Agent {
options?: http.AgentOptions
createConnection(options: any, callback: any): net.Socket
}
}
@ -33,15 +34,23 @@ export class MockAgent extends http.Agent {
public createConnection(options: any, callback: any): net.Socket {
const createConnection =
(this.customAgent instanceof http.Agent &&
this.customAgent.createConnection) ||
super.createConnection
this.customAgent instanceof http.Agent
? this.customAgent.createConnection
: super.createConnection
const createConnectionOptions =
this.customAgent instanceof http.Agent
? {
...options,
...this.customAgent.options,
}
: options
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),
@ -66,15 +75,23 @@ export class MockHttpsAgent extends https.Agent {
public createConnection(options: any, callback: any): net.Socket {
const createConnection =
(this.customAgent instanceof https.Agent &&
this.customAgent.createConnection) ||
super.createConnection
this.customAgent instanceof https.Agent
? this.customAgent.createConnection
: super.createConnection
const createConnectionOptions =
this.customAgent instanceof https.Agent
? {
...options,
...this.customAgent.options,
}
: options
const socket = new MockHttpSocket({
connectionOptions: options,
createConnection: createConnection.bind(
this.customAgent || this,
options,
createConnectionOptions,
callback
),
onRequest: this.onRequest.bind(this),

View file

@ -341,6 +341,50 @@ it('sets fallback Agent based on the URL protocol', () => {
expect(agent).toHaveProperty('protocol', url.protocol)
})
it('preserves `requestUnauthorized` option set to undefined', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: undefined },
])
expect(options.rejectUnauthorized).toBe(undefined)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(
undefined
)
})
it('preserves `requestUnauthorized` option set to true', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: true },
])
expect(options.rejectUnauthorized).toBe(true)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(true)
})
it('preserves `requestUnauthorized` option set to false', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
{ rejectUnauthorized: false },
])
expect(options.rejectUnauthorized).toBe(false)
expect((options.agent as HttpsAgent).options.rejectUnauthorized).toBe(false)
})
it('does not add `rejectUnauthorized` value if not set', () => {
const agent = new HttpsAgent()
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',
])
expect(options).not.toHaveProperty('rejectUnauthorized')
expect((options.agent as HttpsAgent).options).not.toHaveProperty(
'rejectUnauthorized'
)
})
it('does not set any fallback Agent given "agent: false" option', () => {
const [, options] = normalizeClientRequestArgs('https:', [
'https://github.com',

View file

@ -243,7 +243,10 @@ export function normalizeClientRequestArgs(
const agent =
options.protocol === 'https:'
? new HttpsAgent({
rejectUnauthorized: options.rejectUnauthorized,
// Any other value other than false is considered as true, so we don't add this property if undefined.
...('rejectUnauthorized' in options && {
rejectUnauthorized: options.rejectUnauthorized,
}),
})
: new HttpAgent()

View file

@ -144,6 +144,14 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
'no mocked response received, performing request as-is...'
)
/**
* @note Clone the request instance right before performing it.
* This preserves any modifications made to the intercepted request
* in the "request" listener. This also allows the user to read the
* request body in the "response" listener (otherwise "unusable").
*/
const requestCloneForResponseEvent = request.clone()
return pureFetch(request).then(async (response) => {
this.logger.info('original fetch performed', response)
@ -155,7 +163,7 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
await emitAsync(this.emitter, 'response', {
response: responseClone,
isMockedResponse: false,
request,
request: requestCloneForResponseEvent,
requestId,
})
}

View file

@ -90,8 +90,10 @@ it('spies on the constructor', () => {
}
const constructorCall = vi.fn<
[ConstructorParameters<typeof OriginalClass>, Function],
typeof OriginalClass
(
args: ConstructorParameters<typeof OriginalClass>,
next: () => typeof OriginalClass
) => typeof OriginalClass
>((args, next) => next())
const ProxyClass = createProxy(OriginalClass, {

View file

@ -6,7 +6,7 @@ beforeAll(() => {
})
afterEach(() => {
vi.resetAllMocks()
vi.clearAllMocks()
})
afterAll(() => {