Skip to content

Commit b0c8454

Browse files
chore: remove got in tests
1 parent 10c4323 commit b0c8454

File tree

5 files changed

+105
-56
lines changed

5 files changed

+105
-56
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"express-http-proxy": "^2.1.2",
6868
"fast-proxy": "^2.2.0",
6969
"fastify": "^5.6.2",
70-
"got": "^11.8.6",
7170
"http-errors": "^2.0.0",
7271
"http-proxy": "^1.18.1",
7372
"neostandard": "^0.12.2",

test/helper/helper.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,58 @@ async function createServices ({ t, wsReconnectOptions, wsTargetOptions, wsServe
7676
}
7777
}
7878

79+
// Helper function to wrap fetch
80+
async function request (url, options = {}) {
81+
// Handle got's object format: request({ url: '...', headers: {...} })
82+
if (typeof url === 'object' && url.url) {
83+
options = url
84+
url = options.url
85+
}
86+
87+
const fetchOptions = {
88+
method: options.method || 'GET',
89+
headers: options.headers || {},
90+
redirect: options.followRedirect === false ? 'manual' : 'follow'
91+
}
92+
93+
if (options.json) {
94+
fetchOptions.headers['content-type'] = 'application/json'
95+
fetchOptions.body = JSON.stringify(options.json)
96+
}
97+
98+
if (options.retry !== undefined) {
99+
// Native fetch doesn't have retry, just ignore it
100+
}
101+
102+
const response = await fetch(url, fetchOptions)
103+
104+
// Convert fetch Response to got-like response
105+
const result = {
106+
statusCode: response.status,
107+
statusMessage: response.statusText,
108+
headers: Object.fromEntries(response.headers.entries())
109+
}
110+
111+
// Handle response body based on responseType
112+
if (options.responseType === 'json') {
113+
result.body = await response.json()
114+
} else {
115+
result.body = await response.text()
116+
}
117+
118+
// Throw on HTTP errors like got does
119+
if (!response.ok && response.status !== 302) {
120+
const error = new Error(`Response code ${response.status} (${response.statusText})`)
121+
error.response = result
122+
throw error
123+
}
124+
125+
return result
126+
}
127+
79128
module.exports = {
80129
waitForLogMessage,
81130
createTargetServer,
82-
createServices
131+
createServices,
132+
request
83133
}

0 commit comments

Comments
 (0)