From c6ff3d898881af18c566d20066f6613516f9b54e Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Sun, 8 Jan 2017 16:36:19 -0500 Subject: [PATCH 1/2] fix misplaced ) in http response statuscode test This fixes a misplaced parenthesis in each of the tests in test/parallel/test-http-response-statuscodes.js, causing the tests to pass as long as any error was thrown, without validating the error message. --- .../parallel/test-http-response-statuscode.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-http-response-statuscode.js b/test/parallel/test-http-response-statuscode.js index 3314506339b564..57256db6032324 100644 --- a/test/parallel/test-http-response-statuscode.js +++ b/test/parallel/test-http-response-statuscode.js @@ -11,62 +11,62 @@ const server = http.Server(common.mustCall(function(req, res) { case 0: assert.throws(common.mustCall(() => { res.writeHead(-1); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 1: assert.throws(common.mustCall(() => { res.writeHead(Infinity); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 2: assert.throws(common.mustCall(() => { res.writeHead(NaN); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 3: assert.throws(common.mustCall(() => { res.writeHead({}); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 4: assert.throws(common.mustCall(() => { res.writeHead(99); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 5: assert.throws(common.mustCall(() => { res.writeHead(1000); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 6: assert.throws(common.mustCall(() => { res.writeHead('1000'); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 7: assert.throws(common.mustCall(() => { res.writeHead(null); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 8: assert.throws(common.mustCall(() => { res.writeHead(true); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 9: assert.throws(common.mustCall(() => { res.writeHead([]); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 10: assert.throws(common.mustCall(() => { res.writeHead('this is not valid'); - }, /invalid status code/i)); + }), /invalid status code/i); break; case 11: assert.throws(common.mustCall(() => { res.writeHead('404 this is not valid either'); - }, /invalid status code/i)); + }), /invalid status code/i); this.close(); break; default: From cd7ce116556783e314b4132e38fb5a53c3b468d9 Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Tue, 11 Oct 2016 15:43:36 -0400 Subject: [PATCH 2/2] validate 'expected' argument to mustCall() instead of silently overwriting invalid values with the default --- test/common.js | 5 ++++- test/parallel/test-common.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index d95dd770191f5d..75fcc58379be46 100644 --- a/test/common.js +++ b/test/common.js @@ -424,7 +424,10 @@ function runCallChecks(exitCode) { exports.mustCall = function(fn, expected) { - if (typeof expected !== 'number') expected = 1; + if (expected === undefined) + expected = 1; + else if (typeof expected !== 'number') + throw new TypeError(`Invalid expected value: ${expected}`); const context = { expected: expected, diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 1adbf0098abc42..17f41840e4ffa5 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -5,3 +5,11 @@ const assert = require('assert'); common.globalCheck = false; global.gc = 42; // Not a valid global unless --expose_gc is set. assert.deepStrictEqual(common.leakedGlobals(), ['gc']); + +assert.throws(function() { + common.mustCall(function() {}, 'foo'); +}, /^TypeError: Invalid expected value: foo$/); + +assert.throws(function() { + common.mustCall(function() {}, /foo/); +}, /^TypeError: Invalid expected value: \/foo\/$/);