Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/interceptors/ClientRequest/MockHttpSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@

const socket = this.createConnection()
this.originalSocket = socket
this._handle = { reading: true, close: () => {} }

Check failure on line 181 in src/interceptors/ClientRequest/MockHttpSocket.ts

View workflow job for this annotation

GitHub Actions / build (20)

Property '_handle' does not exist on type 'MockHttpSocket'.

Check failure on line 181 in src/interceptors/ClientRequest/MockHttpSocket.ts

View workflow job for this annotation

GitHub Actions / build (18)

Property '_handle' does not exist on type 'MockHttpSocket'.

// If the developer destroys the socket, destroy the original connection.
this.once('error', (error) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @vitest-environment node
*/
import { vi, it, expect, beforeAll, afterAll } from 'vitest'
import http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
import {
waitForClientRequest,
} from '../../../helpers'

const httpServer = new HttpServer((app) => {
app.get('/', (_req, res) => {
let count = 1
const i = setInterval(() => {
res.write('a')
if (++count > 20) {
clearInterval(i)
res.end()
}
}, 10)
})
})

const interceptor = new ClientRequestInterceptor()

beforeAll(async () => {
interceptor.apply()
await httpServer.listen()
})

afterAll(async () => {
interceptor.dispose()
await httpServer.close()
})

it('does ', async () => {
const url = httpServer.http.url('/')
const warningListener = vi.fn()
process.on('warning', warningListener)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an indirect assertion. I think you are onto something with that connect event. Can we somehow add a listener to that instead and assert that it's being called once? That would make a nice compliance test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delightful comment! Fixed.


const req = http.get(url)
const { text } = await waitForClientRequest(req)

expect(await text()).toBe('a'.repeat(20))
expect(warningListener).not.toHaveBeenCalled()
})
Loading