From 4bcf1a0387dd2730a980a8c23dbb637c00d4de08 Mon Sep 17 00:00:00 2001 From: Arseniy Maximov Date: Thu, 16 Feb 2017 23:29:23 +0300 Subject: [PATCH] test: refactor test-http-response-splitting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move repeated code to function * remove unneeded `common.mustCall()` usage with function arguments that are not callbacks * add error message checking PR-URL: https://github.com/nodejs/node/pull/11429 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич --- test/parallel/test-http-response-splitting.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js index e4021e7831..f2c7bc5d8d 100644 --- a/test/parallel/test-http-response-splitting.js +++ b/test/parallel/test-http-response-splitting.js @@ -19,23 +19,23 @@ const y = 'foo⠊Set-Cookie: foo=bar'; var count = 0; +function test(res, code, header) { + assert.throws(() => { + res.writeHead(code, header); + }, /^TypeError: The header content contains invalid characters$/); +} + const server = http.createServer((req, res) => { switch (count++) { case 0: const loc = url.parse(req.url, true).query.lang; - assert.throws(common.mustCall(() => { - res.writeHead(302, {Location: `/foo?lang=${loc}`}); - })); + test(res, 302, {Location: `/foo?lang=${loc}`}); break; case 1: - assert.throws(common.mustCall(() => { - res.writeHead(200, {'foo': x}); - })); + test(res, 200, {'foo': x}); break; case 2: - assert.throws(common.mustCall(() => { - res.writeHead(200, {'foo': y}); - })); + test(res, 200, {'foo': y}); break; default: common.fail('should not get to here.');