Skip to content

Commit 360d2a7

Browse files
authored
test: drain request bodies in request tests (#5247)
1 parent 9d82667 commit 360d2a7

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

test/request.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,40 @@ test('no-slash/one-slash pathname should be included in req.path', async (t) =>
3838
pathname: `localhost:${pathServer.address().port}`
3939
})
4040
t.strictEqual(noSlashPathname.statusCode, 200)
41+
await noSlashPathname.body.dump()
4142
const noSlashPath = await request({
4243
method: 'GET',
4344
origin: `http://localhost:${requestedServer.address().port}`,
4445
path: `localhost:${pathServer.address().port}`
4546
})
4647
t.strictEqual(noSlashPath.statusCode, 200)
48+
await noSlashPath.body.dump()
4749
const noSlashPath2Arg = await request(
4850
`http://localhost:${requestedServer.address().port}`,
4951
{ path: `localhost:${pathServer.address().port}` }
5052
)
5153
t.strictEqual(noSlashPath2Arg.statusCode, 200)
54+
await noSlashPath2Arg.body.dump()
5255
const oneSlashPathname = await request({
5356
method: 'GET',
5457
origin: `http://localhost:${requestedServer.address().port}`,
5558
pathname: `/localhost:${pathServer.address().port}`
5659
})
5760
t.strictEqual(oneSlashPathname.statusCode, 200)
61+
await oneSlashPathname.body.dump()
5862
const oneSlashPath = await request({
5963
method: 'GET',
6064
origin: `http://localhost:${requestedServer.address().port}`,
6165
path: `/localhost:${pathServer.address().port}`
6266
})
6367
t.strictEqual(oneSlashPath.statusCode, 200)
68+
await oneSlashPath.body.dump()
6469
const oneSlashPath2Arg = await request(
6570
`http://localhost:${requestedServer.address().port}`,
6671
{ path: `/localhost:${pathServer.address().port}` }
6772
)
6873
t.strictEqual(oneSlashPath2Arg.statusCode, 200)
74+
await oneSlashPath2Arg.body.dump()
6975
t.end()
7076
})
7177

@@ -102,17 +108,20 @@ test('protocol-relative URL as pathname should be included in req.path', async (
102108
pathname: `//localhost:${pathServer.address().port}`
103109
})
104110
t.strictEqual(noSlashPathname.statusCode, 200)
111+
await noSlashPathname.body.dump()
105112
const noSlashPath = await request({
106113
method: 'GET',
107114
origin: `http://localhost:${requestedServer.address().port}`,
108115
path: `//localhost:${pathServer.address().port}`
109116
})
110117
t.strictEqual(noSlashPath.statusCode, 200)
118+
await noSlashPath.body.dump()
111119
const noSlashPath2Arg = await request(
112120
`http://localhost:${requestedServer.address().port}`,
113121
{ path: `//localhost:${pathServer.address().port}` }
114122
)
115123
t.strictEqual(noSlashPath2Arg.statusCode, 200)
124+
await noSlashPath2Arg.body.dump()
116125
t.end()
117126
})
118127

@@ -149,17 +158,20 @@ test('Absolute URL as pathname should be included in req.path', async (t) => {
149158
pathname: `http://localhost:${pathServer.address().port}`
150159
})
151160
t.strictEqual(noSlashPathname.statusCode, 200)
161+
await noSlashPathname.body.dump()
152162
const noSlashPath = await request({
153163
method: 'GET',
154164
origin: `http://localhost:${requestedServer.address().port}`,
155165
path: `http://localhost:${pathServer.address().port}`
156166
})
157167
t.strictEqual(noSlashPath.statusCode, 200)
168+
await noSlashPath.body.dump()
158169
const noSlashPath2Arg = await request(
159170
`http://localhost:${requestedServer.address().port}`,
160171
{ path: `http://localhost:${pathServer.address().port}` }
161172
)
162173
t.strictEqual(noSlashPath2Arg.statusCode, 200)
174+
await noSlashPath2Arg.body.dump()
163175
t.end()
164176
})
165177

@@ -256,11 +268,12 @@ describe('DispatchOptions#reset', () => {
256268
})
257269
})
258270

259-
await request({
271+
const { body } = await request({
260272
method: 'GET',
261273
origin: `http://localhost:${server.address().port}`,
262274
reset: true
263275
})
276+
await body.dump()
264277
})
265278

266279
test('Should include "connection:keep-alive" if reset false', async t => {
@@ -286,11 +299,12 @@ describe('DispatchOptions#reset', () => {
286299
})
287300
})
288301

289-
await request({
302+
const { body } = await request({
290303
method: 'GET',
291304
origin: `http://localhost:${server.address().port}`,
292305
reset: false
293306
})
307+
await body.dump()
294308
})
295309

296310
test('Should react to manual set of "connection:close" header', async t => {
@@ -316,13 +330,14 @@ describe('DispatchOptions#reset', () => {
316330
})
317331
})
318332

319-
await request({
333+
const { body } = await request({
320334
method: 'GET',
321335
origin: `http://localhost:${server.address().port}`,
322336
headers: {
323337
connection: 'close'
324338
}
325339
})
340+
await body.dump()
326341
})
327342
})
328343

@@ -353,12 +368,13 @@ describe('Should include headers from iterable objects', scope => {
353368
})
354369
})
355370

356-
await request({
371+
const { body } = await request({
357372
method: 'GET',
358373
origin: `http://localhost:${server.address().port}`,
359374
reset: true,
360375
headers
361376
})
377+
await body.dump()
362378
})
363379

364380
test('Should include headers built with Map', async t => {
@@ -387,12 +403,13 @@ describe('Should include headers from iterable objects', scope => {
387403
})
388404
})
389405

390-
await request({
406+
const { body } = await request({
391407
method: 'GET',
392408
origin: `http://localhost:${server.address().port}`,
393409
reset: true,
394410
headers
395411
})
412+
await body.dump()
396413
})
397414

398415
test('Should include headers built with custom iterable object', async t => {
@@ -424,12 +441,13 @@ describe('Should include headers from iterable objects', scope => {
424441
})
425442
})
426443

427-
await request({
444+
const { body } = await request({
428445
method: 'GET',
429446
origin: `http://localhost:${server.address().port}`,
430447
reset: true,
431448
headers
432449
})
450+
await body.dump()
433451
})
434452

435453
test('Should include headers from plain objects with polluted Object.prototype[Symbol.iterator]', async t => {
@@ -464,12 +482,13 @@ describe('Should include headers from iterable objects', scope => {
464482
})
465483
})
466484

467-
await request({
485+
const { body } = await request({
468486
method: 'GET',
469487
origin: `http://localhost:${server.address().port}`,
470488
reset: true,
471489
headers
472490
})
491+
await body.dump()
473492
} finally {
474493
if (originalIterator === undefined) {
475494
delete Object.prototype[Symbol.iterator]

0 commit comments

Comments
 (0)