Skip to content

Commit 0b6eab5

Browse files
maclover7evanlucas
authored andcommitted
test: refactor test-http-parser
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]>
1 parent 20734dc commit 0b6eab5

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

test/parallel/test-http-parser.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
const { mustCall, mustNotCall } = require('../common');
2424
const assert = require('assert');
2525

26-
const binding = process.binding('http_parser');
27-
const methods = binding.methods;
28-
const HTTPParser = binding.HTTPParser;
29-
30-
const REQUEST = HTTPParser.REQUEST;
31-
const RESPONSE = HTTPParser.RESPONSE;
26+
const { methods, HTTPParser } = process.binding('http_parser');
27+
const { REQUEST, RESPONSE } = HTTPParser;
3228

3329
const kOnHeaders = HTTPParser.kOnHeaders | 0;
3430
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
@@ -55,7 +51,7 @@ function newParser(type) {
5551
parser[kOnHeadersComplete] = function() {
5652
};
5753

58-
parser[kOnBody] = common.mustNotCall('kOnBody should not be called');
54+
parser[kOnBody] = mustNotCall('kOnBody should not be called');
5955

6056
parser[kOnMessageComplete] = function() {
6157
};
@@ -64,21 +60,6 @@ function newParser(type) {
6460
}
6561

6662

67-
function mustCall(f, times) {
68-
let actual = 0;
69-
70-
process.setMaxListeners(256);
71-
process.on('exit', function() {
72-
assert.strictEqual(actual, times || 1);
73-
});
74-
75-
return function() {
76-
actual++;
77-
return f.apply(this, Array.prototype.slice.call(arguments));
78-
};
79-
}
80-
81-
8263
function expectBody(expected) {
8364
return mustCall(function(buf, start, len) {
8465
const body = String(buf.slice(start, start + len));

0 commit comments

Comments
 (0)