Skip to content
Draft
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
40 changes: 40 additions & 0 deletions test/modules/http/request/http-request-continue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { it, expect, beforeAll, afterAll } from 'vitest'
Comment thread
kettanaito marked this conversation as resolved.
Outdated
import http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { waitForClientRequest } from '../../../helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

const interceptor = new ClientRequestInterceptor()

const httpServer = new HttpServer((app) => {
app.get('/resource', (req, res) => {
res.send('original response')
})
})

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

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

it('Unmocked request with `Expect: 100-continue` triggers continue event', async () => {
const body = 'this is the full request body'
const request = http.get(httpServer.http.url('/resource'), {
headers: { Expect: '100-continue' },
})
request.on('continue', () => {
request.end(body)
})

const { res, text } = await waitForClientRequest(request)

expect(res.statusCode).toBe(200)
expect(await text()).toBe('original response')
})

it.todo('Mocked request with `Expect: 100-continue` triggers continue event')