Skip to content

Commit 8a3b552

Browse files
Uzlopakcrysmags
authored andcommitted
chore: make some test run even without internet connection (nodejs#2786)
1 parent 54d049d commit 8a3b552

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

test/client-node-max-header-size.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
'use strict'
22

3-
const { execSync } = require('node:child_process')
4-
const { throws, doesNotThrow } = require('node:assert')
5-
const { test } = require('node:test')
6-
7-
const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"'
8-
9-
test("respect Node.js' --max-http-header-size", () => {
10-
throws(
11-
() => execSync(`${command} --max-http-header-size=1`, { stdio: 'pipe' }),
12-
/UND_ERR_HEADERS_OVERFLOW/,
13-
'max-http-header-size=1 should throw'
14-
)
15-
16-
doesNotThrow(
17-
() => execSync(command),
18-
/UND_ERR_HEADERS_OVERFLOW/,
19-
'default max-http-header-size should not throw'
20-
)
3+
const { tspl } = require('@matteo.collina/tspl')
4+
const { once } = require('node:events')
5+
const { exec } = require('node:child_process')
6+
const { test, before, after, describe } = require('node:test')
7+
const { createServer } = require('node:http')
8+
9+
describe("Node.js' --max-http-header-size cli option", () => {
10+
let server
11+
12+
before(async () => {
13+
server = createServer((req, res) => {
14+
res.writeHead(200, 'OK', {
15+
'Content-Length': 2
16+
})
17+
res.write('OK')
18+
res.end()
19+
}).listen(0)
20+
21+
await once(server, 'listening')
22+
})
23+
24+
after(() => server.close())
25+
26+
test("respect Node.js' --max-http-header-size", async (t) => {
27+
t = tspl(t, { plan: 6 })
28+
const command = 'node -e "require(\'.\').request(\'http://localhost:' + server.address().port + '\')"'
29+
30+
exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => {
31+
t.strictEqual(err.code, 1)
32+
t.strictEqual(stdout, '')
33+
t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw')
34+
})
35+
36+
exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => {
37+
t.ifError(err)
38+
t.strictEqual(stdout, '')
39+
t.strictEqual(stderr, '', 'default max-http-header-size should not throw')
40+
})
41+
42+
await t.completed
43+
})
2144
})

test/connect-timeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('prioritize socket errors over timeouts', () => {
1616
client.request({ method: 'GET', path: '/foobar' })
1717
.then(() => t.fail())
1818
.catch((err) => {
19-
t.strictEqual(err.code, 'ENOTFOUND')
19+
t.strictEqual(['ENOTFOUND', 'EAI_AGAIN'].includes(err.code), true)
2020
})
2121

2222
// block for 1s which is enough for the dns lookup to complete and TO to fire

test/issue-1670.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { test } = require('node:test')
44
const { request } = require('..')
55

6-
test('https://github.com/mcollina/undici/issues/810', async () => {
6+
test('https://github.com/mcollina/undici/issues/1670', async () => {
77
const { body } = await request('https://api.github.com/user/emails')
88

99
await body.text()

0 commit comments

Comments
 (0)