From 09ee183a69aa02ec4eef8317a207a29df894baad Mon Sep 17 00:00:00 2001 From: hushuilong Date: Sun, 9 Jan 2022 18:10:03 +0800 Subject: [PATCH 1/3] Make got be compatible with nock --- source/core/options.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/core/options.ts b/source/core/options.ts index 1f01b47db..e1e1ae3ba 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -3,8 +3,8 @@ import {Buffer} from 'node:buffer'; import {promisify, inspect} from 'node:util'; import {URL, URLSearchParams} from 'node:url'; import {checkServerIdentity} from 'node:tls'; -import {request as httpRequest} from 'node:http'; -import {request as httpsRequest} from 'node:https'; +import http from 'node:http'; +import https from 'node:https'; import type {Readable} from 'node:stream'; import type {Socket} from 'node:net'; import type {SecureContextOptions, DetailedPeerCertificate} from 'node:tls'; @@ -2447,10 +2447,10 @@ export default class Options { return http2wrapper.auto as RequestFunction; } - return httpsRequest; + return https.request; } - return httpRequest; + return http.request; } freeze() { From 9ca37d12545be593f451cb5f72ca08d42df429c1 Mon Sep 17 00:00:00 2001 From: hushuilong Date: Sun, 9 Jan 2022 19:11:21 +0800 Subject: [PATCH 2/3] Add comments for compatibility with nock --- source/core/options.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/core/options.ts b/source/core/options.ts index e1e1ae3ba..78f9553c9 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -3,6 +3,8 @@ import {Buffer} from 'node:buffer'; import {promisify, inspect} from 'node:util'; import {URL, URLSearchParams} from 'node:url'; import {checkServerIdentity} from 'node:tls'; +// The way of destructuring is not compatible with `nock`. +// DO NOT use destructuring assignment for https.request and http.request. import http from 'node:http'; import https from 'node:https'; import type {Readable} from 'node:stream'; From d8032e2a76551285f3925759e1cb1283d07457c9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 9 Jan 2022 21:28:11 +0700 Subject: [PATCH 3/3] Update options.ts --- source/core/options.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/core/options.ts b/source/core/options.ts index 78f9553c9..ca7994f3c 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -3,8 +3,7 @@ import {Buffer} from 'node:buffer'; import {promisify, inspect} from 'node:util'; import {URL, URLSearchParams} from 'node:url'; import {checkServerIdentity} from 'node:tls'; -// The way of destructuring is not compatible with `nock`. -// DO NOT use destructuring assignment for https.request and http.request. +// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`. import http from 'node:http'; import https from 'node:https'; import type {Readable} from 'node:stream';