Skip to content

Commit b54b39b

Browse files
committed
chore: remove comment, remove unused test
1 parent 8fc3755 commit b54b39b

5 files changed

Lines changed: 64 additions & 97 deletions

File tree

src/interceptors/http/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ export class HttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {
105105
if (!isRequestHandled) {
106106
const passthroughSocket = socket.passthrough()
107107

108-
console.log('pas?')
109-
110108
/**
111109
* @note Creating a passthroughsocket does NOT trigger the "socket" event
112110
* from `http.ClientRequest` where the request, parser, and socket get

test/modules/http/intercept/http-client-request-agent.test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/modules/http/intercept/http-client-request.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ beforeAll(async () => {
2121
})
2222

2323
afterEach(() => {
24-
vi.resetAllMocks()
2524
interceptor.removeAllListeners()
2625
})
2726

test/modules/http/intercept/http.request.test.ts

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ const httpServer = new HttpServer((app) => {
1818
app.head('/user', handleUserRequest)
1919
})
2020

21-
const resolver = vi.fn<(...args: HttpRequestEventMap['request']) => void>()
2221
const interceptor = new HttpRequestInterceptor()
23-
interceptor.on('request', resolver)
2422

2523
beforeAll(async () => {
2624
await httpServer.listen()
2725
interceptor.apply()
2826
})
2927

3028
afterEach(() => {
31-
vi.resetAllMocks()
29+
interceptor.removeAllListeners()
3230
})
3331

3432
afterAll(async () => {
@@ -37,6 +35,10 @@ afterAll(async () => {
3735
})
3836

3937
it('intercepts a HEAD request', async () => {
38+
const requestListener =
39+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
40+
interceptor.on('request', requestListener)
41+
4042
const url = httpServer.http.url('/user?id=123')
4143
const req = http.request(url, {
4244
method: 'HEAD',
@@ -47,9 +49,9 @@ it('intercepts a HEAD request', async () => {
4749
req.end()
4850
await waitForClientRequest(req)
4951

50-
expect(resolver).toHaveBeenCalledTimes(1)
52+
expect(requestListener).toHaveBeenCalledTimes(1)
5153

52-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
54+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
5355

5456
expect(request.method).toBe('HEAD')
5557
expect(request.url).toBe(url)
@@ -65,6 +67,10 @@ it('intercepts a HEAD request', async () => {
6567
})
6668

6769
it('intercepts a GET request', async () => {
70+
const requestListener =
71+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
72+
interceptor.on('request', requestListener)
73+
6874
const url = httpServer.http.url('/user?id=123')
6975
const req = http.request(url, {
7076
method: 'GET',
@@ -75,9 +81,9 @@ it('intercepts a GET request', async () => {
7581
req.end()
7682
await waitForClientRequest(req)
7783

78-
expect(resolver).toHaveBeenCalledTimes(1)
84+
expect(requestListener).toHaveBeenCalledTimes(1)
7985

80-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
86+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
8187

8288
expect(request.method).toBe('GET')
8389
expect(request.url).toBe(url)
@@ -93,6 +99,10 @@ it('intercepts a GET request', async () => {
9399
})
94100

95101
it('intercepts a POST request', async () => {
102+
const requestListener =
103+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
104+
interceptor.on('request', requestListener)
105+
96106
const url = httpServer.http.url('/user?id=123')
97107
const req = http.request(url, {
98108
method: 'POST',
@@ -106,9 +116,9 @@ it('intercepts a POST request', async () => {
106116

107117
await waitForClientRequest(req)
108118

109-
expect(resolver).toHaveBeenCalledTimes(1)
119+
expect(requestListener).toHaveBeenCalledTimes(1)
110120

111-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
121+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
112122

113123
expect(request.method).toBe('POST')
114124
expect(request.url).toBe(url)
@@ -117,13 +127,17 @@ it('intercepts a POST request', async () => {
117127
'x-custom-header': 'yes',
118128
})
119129
expect(request.credentials).toBe('same-origin')
120-
expect(await request.text()).toBe('post-payload')
130+
await expect(request.text()).resolves.toBe('post-payload')
121131
expect(controller).toBeInstanceOf(RequestController)
122132

123133
expect(requestId).toMatch(REQUEST_ID_REGEXP)
124134
})
125135

126136
it('intercepts a PUT request', async () => {
137+
const requestListener =
138+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
139+
interceptor.on('request', requestListener)
140+
127141
const url = httpServer.http.url('/user?id=123')
128142
const req = http.request(url, {
129143
method: 'PUT',
@@ -136,9 +150,9 @@ it('intercepts a PUT request', async () => {
136150
req.end()
137151
await waitForClientRequest(req)
138152

139-
expect(resolver).toHaveBeenCalledTimes(1)
153+
expect(requestListener).toHaveBeenCalledTimes(1)
140154

141-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
155+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
142156

143157
expect(request.method).toBe('PUT')
144158
expect(request.url).toBe(url)
@@ -147,13 +161,17 @@ it('intercepts a PUT request', async () => {
147161
'x-custom-header': 'yes',
148162
})
149163
expect(request.credentials).toBe('same-origin')
150-
expect(await request.text()).toBe('put-payload')
164+
await expect(request.text()).resolves.toBe('put-payload')
151165
expect(controller).toBeInstanceOf(RequestController)
152166

153167
expect(requestId).toMatch(REQUEST_ID_REGEXP)
154168
})
155169

156170
it('intercepts a PATCH request', async () => {
171+
const requestListener =
172+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
173+
interceptor.on('request', requestListener)
174+
157175
const url = httpServer.http.url('/user?id=123')
158176
const req = http.request(url, {
159177
method: 'PATCH',
@@ -166,9 +184,9 @@ it('intercepts a PATCH request', async () => {
166184
req.end()
167185
await waitForClientRequest(req)
168186

169-
expect(resolver).toHaveBeenCalledTimes(1)
187+
expect(requestListener).toHaveBeenCalledTimes(1)
170188

171-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
189+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
172190

173191
expect(request.method).toBe('PATCH')
174192
expect(request.url).toBe(url)
@@ -177,13 +195,17 @@ it('intercepts a PATCH request', async () => {
177195
'x-custom-header': 'yes',
178196
})
179197
expect(request.credentials).toBe('same-origin')
180-
expect(await request.text()).toBe('patch-payload')
198+
await expect(request.text()).resolves.toBe('patch-payload')
181199
expect(controller).toBeInstanceOf(RequestController)
182200

183201
expect(requestId).toMatch(REQUEST_ID_REGEXP)
184202
})
185203

186204
it('intercepts a DELETE request', async () => {
205+
const requestListener =
206+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
207+
interceptor.on('request', requestListener)
208+
187209
const url = httpServer.http.url('/user?id=123')
188210
const req = http.request(url, {
189211
method: 'DELETE',
@@ -194,9 +216,9 @@ it('intercepts a DELETE request', async () => {
194216
req.end()
195217
await waitForClientRequest(req)
196218

197-
expect(resolver).toHaveBeenCalledTimes(1)
219+
expect(requestListener).toHaveBeenCalledTimes(1)
198220

199-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
221+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
200222

201223
expect(request.method).toBe('DELETE')
202224
expect(request.url).toBe(url)
@@ -212,6 +234,10 @@ it('intercepts a DELETE request', async () => {
212234
})
213235

214236
it('intercepts an http.request given RequestOptions without a protocol', async () => {
237+
const requestListener =
238+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
239+
interceptor.on('request', requestListener)
240+
215241
// Create a request with `RequestOptions` without an explicit "protocol".
216242
// Since request is done via `http.get`, the "http:" protocol must be inferred.
217243
const req = http.request({
@@ -222,9 +248,9 @@ it('intercepts an http.request given RequestOptions without a protocol', async (
222248
req.end()
223249
await waitForClientRequest(req)
224250

225-
expect(resolver).toHaveBeenCalledTimes(1)
251+
expect(requestListener).toHaveBeenCalledTimes(1)
226252

227-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
253+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
228254

229255
expect(request.method).toBe('GET')
230256
expect(request.url).toBe(httpServer.http.url('/user?id=123'))
@@ -236,6 +262,10 @@ it('intercepts an http.request given RequestOptions without a protocol', async (
236262
})
237263

238264
it('intercepts an http.request path in url and options', async () => {
265+
const requestListener =
266+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
267+
interceptor.on('request', requestListener)
268+
239269
const callback = vi.fn()
240270
const req = http.request(
241271
new URL(httpServer.http.url('/one')),
@@ -245,9 +275,9 @@ it('intercepts an http.request path in url and options', async () => {
245275
req.end()
246276
await waitForClientRequest(req)
247277

248-
expect(resolver).toHaveBeenCalledTimes(1)
278+
expect(requestListener).toHaveBeenCalledTimes(1)
249279

250-
const [{ request, requestId, controller }] = resolver.mock.calls[0]
280+
const [{ request, requestId, controller }] = requestListener.mock.calls[0]
251281

252282
expect(request.method).toBe('GET')
253283
expect(request.url).toBe(httpServer.http.url('/two'))
@@ -260,6 +290,10 @@ it('intercepts an http.request path in url and options', async () => {
260290
})
261291

262292
it('intercepts an http.request with custom "auth" option', async () => {
293+
const requestListener =
294+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
295+
interceptor.on('request', requestListener)
296+
263297
const auth = 'john:secret123'
264298
const req = http.request({
265299
host: httpServer.http.address.host,
@@ -269,9 +303,9 @@ it('intercepts an http.request with custom "auth" option', async () => {
269303
req.end()
270304
await waitForClientRequest(req)
271305

272-
expect(resolver).toHaveBeenCalledTimes(1)
306+
expect(requestListener).toHaveBeenCalledTimes(1)
273307

274-
const [{ request }] = resolver.mock.calls[0]
308+
const [{ request }] = requestListener.mock.calls[0]
275309

276310
expect(request.method).toBe('GET')
277311
expect(request.url).toBe(httpServer.http.url('/'))
@@ -281,6 +315,10 @@ it('intercepts an http.request with custom "auth" option', async () => {
281315
})
282316

283317
it('intercepts an http.request with a URL with "username" and "password"', async () => {
318+
const requestListener =
319+
vi.fn<(...args: HttpRequestEventMap['request']) => void>()
320+
interceptor.on('request', requestListener)
321+
284322
const username = 'john'
285323
const password = 'secret123'
286324
const req = http.request(
@@ -292,9 +330,9 @@ it('intercepts an http.request with a URL with "username" and "password"', async
292330
req.end()
293331
await waitForClientRequest(req)
294332

295-
expect(resolver).toHaveBeenCalledTimes(1)
333+
expect(requestListener).toHaveBeenCalledTimes(1)
296334

297-
const [{ request }] = resolver.mock.calls[0]
335+
const [{ request }] = requestListener.mock.calls[0]
298336

299337
expect(request.method).toBe('GET')
300338
expect(request.url).toBe(httpServer.http.url('/'))

test/modules/net/compliance/net-socket-passthrough.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ it('establishes actual server connection on passthrough', async () => {
6161
const connectListener = vi.fn()
6262
const errorListener = vi.fn()
6363

64-
/**
65-
* @fixme Every "once" listener is fired multiple times.
66-
* From the recordings, "once" is followed by "on" immediately
67-
* as if it's implemented by it under the hood. Unit tests for the
68-
* recorder fail to prove that.
69-
*/
7064
socket
7165
.once('connect', function connectOne() {
7266
socket.write([

0 commit comments

Comments
 (0)