From c740cb6667f7a3c7b10dc26b980449008065d188 Mon Sep 17 00:00:00 2001 From: abouthiroppy Date: Sun, 15 Jan 2017 03:30:14 +0900 Subject: [PATCH] test: add test case to test-http-response-statuscode.js Change regular expression of error message. Add test case(`res.writeHead()`). PR-URL: https://github.com/nodejs/node/pull/10808 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- .../parallel/test-http-response-statuscode.js | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-http-response-statuscode.js b/test/parallel/test-http-response-statuscode.js index 57256db6032324..ed3676b03e1f0c 100644 --- a/test/parallel/test-http-response-statuscode.js +++ b/test/parallel/test-http-response-statuscode.js @@ -3,70 +3,79 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -const MAX_REQUESTS = 12; -var reqNum = 0; +const MAX_REQUESTS = 13; +let reqNum = 0; + +const createErrorMessage = (code) => { + return new RegExp(`^RangeError: Invalid status code: ${code}$`); +}; const server = http.Server(common.mustCall(function(req, res) { switch (reqNum) { case 0: assert.throws(common.mustCall(() => { res.writeHead(-1); - }), /invalid status code/i); + }), createErrorMessage(-1)); break; case 1: assert.throws(common.mustCall(() => { res.writeHead(Infinity); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 2: assert.throws(common.mustCall(() => { res.writeHead(NaN); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 3: assert.throws(common.mustCall(() => { res.writeHead({}); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 4: assert.throws(common.mustCall(() => { res.writeHead(99); - }), /invalid status code/i); + }), createErrorMessage(99)); break; case 5: assert.throws(common.mustCall(() => { res.writeHead(1000); - }), /invalid status code/i); + }), createErrorMessage(1000)); break; case 6: assert.throws(common.mustCall(() => { res.writeHead('1000'); - }), /invalid status code/i); + }), createErrorMessage(1000)); break; case 7: assert.throws(common.mustCall(() => { res.writeHead(null); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 8: assert.throws(common.mustCall(() => { res.writeHead(true); - }), /invalid status code/i); + }), createErrorMessage(1)); break; case 9: assert.throws(common.mustCall(() => { res.writeHead([]); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 10: assert.throws(common.mustCall(() => { res.writeHead('this is not valid'); - }), /invalid status code/i); + }), createErrorMessage(0)); break; case 11: assert.throws(common.mustCall(() => { res.writeHead('404 this is not valid either'); - }), /invalid status code/i); + }), createErrorMessage(0)); + break; + case 12: + assert.throws(common.mustCall(() => { + res.writeHead(); + }), createErrorMessage(0)); this.close(); break; default: