From 987d26f8cdb138edcc1624b8074d85499b8051a6 Mon Sep 17 00:00:00 2001
From: Nicholas Lim <18374483+niclim@users.noreply.github.com>
Date: Thu, 18 Jan 2024 14:25:36 -0500
Subject: [PATCH] Fix/tests for node 20 (#2669)

---
 .github/workflows/test.yaml                   |  2 +-
 projects/optic/package.json                   |  1 -
 .../src/commands/oas/captures/proxy.test.ts   | 24 ++++++++++++-----
 yarn.lock                                     | 26 -------------------
 4 files changed, 18 insertions(+), 35 deletions(-)

diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 727c75003e..6d91d3a2f1 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -12,7 +12,7 @@ jobs:
     runs-on: ubuntu-latest-16-core
     strategy:
       matrix:
-        node_version: [16, 18] # todo: get 20 passing
+        node_version: [16, 18, 20]
     env:
       YARN_IGNORE_NODE: 1 # silence node 16 complaints
     steps:
diff --git a/projects/optic/package.json b/projects/optic/package.json
index 5a7dc6ee7c..ab9166492f 100644
--- a/projects/optic/package.json
+++ b/projects/optic/package.json
@@ -47,7 +47,6 @@
     "@types/url-join": "^4.0.1",
     "babel-jest": "^29.3.1",
     "babel-plugin-transform-inline-environment-variables": "^0.4.3",
-    "bent": "^7.3.12",
     "jest": "^29.3.1",
     "prettier": "^3.0.0",
     "ts-jest": "^29.0.3",
diff --git a/projects/optic/src/commands/oas/captures/proxy.test.ts b/projects/optic/src/commands/oas/captures/proxy.test.ts
index ac725c5bc6..4bc92e6e68 100644
--- a/projects/optic/src/commands/oas/captures/proxy.test.ts
+++ b/projects/optic/src/commands/oas/captures/proxy.test.ts
@@ -1,13 +1,13 @@
 import { it, describe, expect, beforeAll, afterAll } from '@jest/globals';
 
 import * as mockttp from 'mockttp';
-import bent from 'bent';
 import { collect } from '../lib/async-tools';
 import fetch from 'node-fetch';
 import https from 'https';
 import UrlJoin from 'url-join';
 import { httpsOverHttp } from 'tunnel';
 import { ProxyInteractions, ProxyCertAuthority } from './proxy';
+import portfinder from 'portfinder';
 
 describe('ProxyInteractions', () => {
   let target: mockttp.Mockttp;
@@ -27,11 +27,16 @@ describe('ProxyInteractions', () => {
     const [interactions, proxyUrl] = await ProxyInteractions.create(
       target.url,
       abortController.signal,
-      { mode: 'reverse-proxy' }
+      {
+        mode: 'reverse-proxy',
+        proxyPort: await portfinder.getPortPromise({
+          port: 8000,
+          stopPort: 8999,
+        }),
+      }
     );
 
-    const get = bent(proxyUrl);
-    const response = (await get('/some-path', 'string')) as bent.BentResponse;
+    const response = await fetch(`${proxyUrl}/some-path`);
 
     expect(await response.text()).toBe('Test response');
 
@@ -49,11 +54,16 @@ describe('ProxyInteractions', () => {
     const [interactions, proxyUrl] = await ProxyInteractions.create(
       target.url,
       abortController.signal,
-      { mode: 'reverse-proxy' }
+      {
+        mode: 'reverse-proxy',
+        proxyPort: await portfinder.getPortPromise({
+          port: 9000,
+          stopPort: 9999,
+        }),
+      }
     );
 
-    const requestDelete = bent(proxyUrl, 'DELETE', 204);
-    await requestDelete('/some-path');
+    await fetch(`${proxyUrl}/some-path`, { method: 'DELETE' });
 
     abortController.abort();
 
diff --git a/yarn.lock b/yarn.lock
index 4c170d357f..31e6e7d969 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3799,7 +3799,6 @@ __metadata:
     axax: "npm:^0.2.2"
     babel-jest: "npm:^29.3.1"
     babel-plugin-transform-inline-environment-variables: "npm:^0.4.3"
-    bent: "npm:^7.3.12"
     bottleneck: "npm:^2.19.5"
     chalk: "npm:^4.1.2"
     commander: "npm:^11.0.0"
@@ -4483,17 +4482,6 @@ __metadata:
   languageName: node
   linkType: hard
 
-"bent@npm:^7.3.12":
-  version: 7.3.12
-  resolution: "bent@npm:7.3.12"
-  dependencies:
-    bytesish: "npm:^0.4.1"
-    caseless: "npm:~0.12.0"
-    is-stream: "npm:^2.0.0"
-  checksum: 20f77364bcb462a6eb0ea7322442a1125ca6181ea6b94ad498b8348c678a2adf56c231a653bcac016c5d017aee91ff55b2169b69d8263a4b3c710f4121cbe615
-  languageName: node
-  linkType: hard
-
 "binary-extensions@npm:^2.0.0":
   version: 2.2.0
   resolution: "binary-extensions@npm:2.2.0"
@@ -4700,13 +4688,6 @@ __metadata:
   languageName: node
   linkType: hard
 
-"bytesish@npm:^0.4.1":
-  version: 0.4.4
-  resolution: "bytesish@npm:0.4.4"
-  checksum: 469088f0020797dfbb61b6ce3972c91d95d79df8aacca55841ea93ac59ef3209bb04be8212b6265dfbafb7583a58dd73ca2f14e4feae36d3333a4f1509dd2eef
-  languageName: node
-  linkType: hard
-
 "cacache@npm:^15.2.0":
   version: 15.3.0
   resolution: "cacache@npm:15.3.0"
@@ -4825,13 +4806,6 @@ __metadata:
   languageName: node
   linkType: hard
 
-"caseless@npm:~0.12.0":
-  version: 0.12.0
-  resolution: "caseless@npm:0.12.0"
-  checksum: ccf64bcb6c0232cdc5b7bd91ddd06e23a4b541f138336d4725233ac538041fb2f29c2e86c3c4a7a61ef990b665348db23a047060b9414c3a6603e9fa61ad4626
-  languageName: node
-  linkType: hard
-
 "chalk@npm:5.3.0":
   version: 5.3.0
   resolution: "chalk@npm:5.3.0"