Skip to content

Commit

Permalink
test: refactor test-http-parser
Browse files Browse the repository at this point in the history
Use common's mustCall (for some reason was implementing its own?), and
other small fixes.

PR-URL: #18219
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
maclover7 authored and evanlucas committed Jan 30, 2018
1 parent aa21d55 commit 506c6e8
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions test/parallel/test-http-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
};
Expand All @@ -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));
Expand Down

0 comments on commit 506c6e8

Please sign in to comment.