Skip to content

Commit eec8b6d

Browse files
committed
minor test refactor
1 parent 9be8d56 commit eec8b6d

2 files changed

+49
-60
lines changed

test/parallel/test-http-early-hints-invalid-argument-value.js

-35
This file was deleted.

test/parallel/test-http-early-hints-invalid-argument.js

+49-25
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,52 @@ const debug = require('node:util').debuglog('test');
66

77
const testResBody = 'response content\n';
88

9-
const server = http.createServer(common.mustCall((req, res) => {
10-
debug('Server sending early hints...');
11-
res.writeEarlyHints('bad argument type');
12-
13-
debug('Server sending full response...');
14-
res.end(testResBody);
15-
}));
16-
17-
server.listen(0, common.mustCall(() => {
18-
const req = http.request({
19-
port: server.address().port, path: '/'
20-
});
21-
22-
req.end();
23-
debug('Client sending request...');
24-
25-
req.on('information', common.mustNotCall());
26-
27-
process.on('uncaughtException', (err) => {
28-
debug(`Caught an exception: ${JSON.stringify(err)}`);
29-
if (err.name === 'AssertionError') throw err;
30-
assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
31-
process.exit(0);
32-
});
33-
}));
9+
{
10+
const server = http.createServer(common.mustCall((req, res) => {
11+
debug('Server sending early hints...');
12+
assert.throws(() => {
13+
res.writeEarlyHints('bad argument type');
14+
}, (err) => err.code === 'ERR_INVALID_ARG_TYPE');
15+
16+
debug('Server sending full response...');
17+
res.end(testResBody);
18+
server.close();
19+
}));
20+
21+
server.listen(0, common.mustCall(() => {
22+
const req = http.request({
23+
port: server.address().port, path: '/'
24+
});
25+
26+
req.end();
27+
debug('Client sending request...');
28+
29+
req.on('information', common.mustNotCall());
30+
}));
31+
}
32+
33+
{
34+
const server = http.createServer(common.mustCall((req, res) => {
35+
debug('Server sending early hints...');
36+
assert.throws(() => {
37+
res.writeEarlyHints({
38+
link: '</>; '
39+
});
40+
}, (err) => err.code === 'ERR_INVALID_ARG_VALUE');
41+
42+
debug('Server sending full response...');
43+
res.end(testResBody);
44+
server.close();
45+
}));
46+
47+
server.listen(0, common.mustCall(() => {
48+
const req = http.request({
49+
port: server.address().port, path: '/'
50+
});
51+
52+
req.end();
53+
debug('Client sending request...');
54+
55+
req.on('information', common.mustNotCall());
56+
}));
57+
}

0 commit comments

Comments
 (0)