-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make some test run even without internet connection (#2786)
- Loading branch information
Showing
3 changed files
with
43 additions
and
20 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
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://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 | ||
}) | ||
}) |
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