-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ClientRequest): use
ServerResponse
to build the HTTP response s…
…tring (#596) Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
- Loading branch information
1 parent
3a37d70
commit fedac45
Showing
3 changed files
with
82 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/modules/http/response/http-response-transfer-encoding.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @vitest-environment node | ||
*/ | ||
import { it, expect, beforeAll, afterEach, afterAll } from 'vitest' | ||
import http from 'node:http' | ||
import { waitForClientRequest } from '../../../helpers' | ||
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest' | ||
|
||
const interceptor = new ClientRequestInterceptor() | ||
|
||
beforeAll(() => { | ||
interceptor.apply() | ||
}) | ||
|
||
afterEach(() => { | ||
interceptor.removeAllListeners() | ||
}) | ||
|
||
afterAll(() => { | ||
interceptor.dispose() | ||
}) | ||
|
||
it('responds with a mocked "transfer-encoding: chunked" response', async () => { | ||
interceptor.on('request', ({ request }) => { | ||
request.respondWith( | ||
new Response('mock', { | ||
headers: { 'Transfer-Encoding': 'chunked' }, | ||
}) | ||
) | ||
}) | ||
|
||
const request = http.get('http://localhost') | ||
const { res, text } = await waitForClientRequest(request) | ||
|
||
expect(res.statusCode).toBe(200) | ||
expect(res.headers).toHaveProperty('transfer-encoding', 'chunked') | ||
expect(res.rawHeaders).toContain('Transfer-Encoding') | ||
expect(await text()).toBe('mock') | ||
}) |