Skip to content

Commit fc16912

Browse files
committed
test: refactor test-http-response-splitting
* move repeated code to function * remove unneeded `common.mustCall()` usage with function arguments that are not callbacks * add error message checking
1 parent a196895 commit fc16912

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

test/parallel/test-http-response-splitting.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ const y = 'foo⠊Set-Cookie: foo=bar';
1919

2020
let count = 0;
2121

22+
function test(res, code, header) {
23+
assert.throws(() => {
24+
res.writeHead(code, header);
25+
}, /^TypeError: The header content contains invalid characters$/);
26+
}
27+
2228
const server = http.createServer((req, res) => {
2329
switch (count++) {
2430
case 0:
2531
const loc = url.parse(req.url, true).query.lang;
26-
assert.throws(common.mustCall(() => {
27-
res.writeHead(302, {Location: `/foo?lang=${loc}`});
28-
}));
32+
test(res, 302, {Location: `/foo?lang=${loc}`});
2933
break;
3034
case 1:
31-
assert.throws(common.mustCall(() => {
32-
res.writeHead(200, {'foo': x});
33-
}));
35+
test(res, 200, {'foo': x});
3436
break;
3537
case 2:
36-
assert.throws(common.mustCall(() => {
37-
res.writeHead(200, {'foo': y});
38-
}));
38+
test(res, 200, {'foo': y});
3939
break;
4040
default:
4141
common.fail('should not get to here.');

0 commit comments

Comments
 (0)