AtlatestRepositorysigil-http

sigil-http / tree / test / integrationrun-upload-tests.mjs

1// Node 18+; ephemeral loopback listener, no third-party services or credentials.
2import http from 'node:http';
3import assert from 'node:assert/strict';
4import { spawn } from 'node:child_process';
5const lengths = [];
6const server = http.createServer(async (req, res) => {
7 const chunks = [];
8 for await (const chunk of req) chunks.push(chunk);
9 const body = Buffer.concat(chunks);
10 lengths.push(body.length);
11 res.writeHead(200, { 'content-length': String(body.length) });
12 res.end(body);
13});
14await new Promise((resolve, reject) => {
15 server.once('error', reject); server.listen(0, '127.0.0.1', resolve);
16});
17try {
18 const child = spawn('sigil', ['test', '--sgl', '--strict', ...process.argv.slice(2)], {
19 stdio: 'inherit', env: { ...process.env, HTTP_UPLOAD_TEST_PORT: String(server.address().port) },
20 });
21 const timeout = setTimeout(() => child.kill('SIGTERM'), 180_000);
22 const code = await new Promise((resolve, reject) => { child.once('error', reject); child.once('exit', resolve); });
23 clearTimeout(timeout);
24 assert.equal(code, 0, 'HTTP suite including binary round-trip passed');
25 assert.deepEqual(lengths, [2 * 1024 * 1024, 0], 'both binary requests reached the server');
26} finally { server.closeAllConnections(); server.close(); }