diff options
author | Jon Moss <me@jonathanmoss.me> | 2018-01-18 04:36:25 +0300 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-02-27 09:00:56 +0300 |
commit | 9e799518557cc1f1e45edbdb05ce6645f89d2fb2 (patch) | |
tree | 794a8dddf5ffbb3d17347ee79cdc55834b80f4ed /test | |
parent | deb70417cd3c03948da93dcc7cd8479890b83ce2 (diff) |
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 <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http-parser.js | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/test/parallel/test-http-parser.js b/test/parallel/test-http-parser.js index 81aadf26169..df3a87f73c8 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)); |