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

chore: make some test run even without internet connection #2786

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
59 changes: 41 additions & 18 deletions test/client-node-max-header-size.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
'use strict'

const { execSync } = require('node:child_process')
const { throws, doesNotThrow } = require('node:assert')
const { test } = require('node:test')

const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"'

test("respect Node.js' --max-http-header-size", () => {
throws(
() => execSync(`${command} --max-http-header-size=1`, { stdio: 'pipe' }),
/UND_ERR_HEADERS_OVERFLOW/,
'max-http-header-size=1 should throw'
)

doesNotThrow(
() => execSync(command),
/UND_ERR_HEADERS_OVERFLOW/,
'default max-http-header-size should not throw'
)
const { tspl } = require('@matteo.collina/tspl')
const { once } = require('node:events')
const { exec } = require('node:child_process')
const { test, before, after, describe } = require('node:test')
const { createServer } = require('node:http')

describe("Node.js' --max-http-header-size cli option", () => {
let server

before(async () => {
server = createServer((req, res) => {
res.writeHead(200, 'OK', {
'Content-Length': 2
})
res.write('OK')
res.end()
}).listen(0)

await once(server, 'listening')
})

after(() => server.close())

test("respect Node.js' --max-http-header-size", async (t) => {
t = tspl(t, { plan: 6 })
const command = 'node -e "require(\'.\').request(\'http:https://localhost:' + server.address().port + '\')"'

exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.strictEqual(err.code, 1)
t.strictEqual(stdout, '')
t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw')
})

exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => {
t.ifError(err)
t.strictEqual(stdout, '')
t.strictEqual(stderr, '', 'default max-http-header-size should not throw')
})

await t.completed
})
})
2 changes: 1 addition & 1 deletion test/connect-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('prioritize socket errors over timeouts', () => {
client.request({ method: 'GET', path: '/foobar' })
.then(() => t.fail())
.catch((err) => {
t.strictEqual(err.code, 'ENOTFOUND')
t.strictEqual(['ENOTFOUND', 'EAI_AGAIN'].includes(err.code), true)
})

// block for 1s which is enough for the dns lookup to complete and TO to fire
Expand Down
2 changes: 1 addition & 1 deletion test/issue-1670.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { test } = require('node:test')
const { request } = require('..')

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

await body.text()
Expand Down
Loading