Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ClientRequest): support 100 continue flow #599

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
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'
kettanaito marked this conversation as resolved.
Show resolved Hide resolved
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')
Loading