From 0b6eab556e0ec251d156a3307f25e9385db1e317 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 17 Jan 2018 20:36:25 -0500 Subject: [PATCH] test: refactor test-http-parser Use common's mustCall (for some reason was implementing its own?), and other small fixes. PR-URL: https://github.com/nodejs/node/pull/18219 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- test/parallel/test-http-parser.js | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index 81aadf26169179..df3a87f73c8d15 100644 --- a/test/parallel/test-http-parser.js +++ b/test/parallel/test-http-parser.js @@ -20,15 +20,11 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +const { mustCall, mustNotCall } = require('../common'); const assert = require('assert'); -const binding = process.binding('http_parser'); -const methods = binding.methods; -const HTTPParser = binding.HTTPParser; - -const REQUEST = HTTPParser.REQUEST; -const RESPONSE = HTTPParser.RESPONSE; +const { methods, HTTPParser } = process.binding('http_parser'); +const { REQUEST, RESPONSE } = HTTPParser; const kOnHeaders = HTTPParser.kOnHeaders | 0; const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; @@ -55,7 +51,7 @@ function newParser(type) { parser[kOnHeadersComplete] = function() { }; - parser[kOnBody] = common.mustNotCall('kOnBody should not be called'); + parser[kOnBody] = mustNotCall('kOnBody should not be called'); parser[kOnMessageComplete] = function() { }; @@ -64,21 +60,6 @@ function newParser(type) { } -function mustCall(f, times) { - let actual = 0; - - process.setMaxListeners(256); - process.on('exit', function() { - assert.strictEqual(actual, times || 1); - }); - - return function() { - actual++; - return f.apply(this, Array.prototype.slice.call(arguments)); - }; -} - - function expectBody(expected) { return mustCall(function(buf, start, len) { const body = String(buf.slice(start, start + len));