Skip to content

Commit 166c7f5

Browse files
edsadrMylesBorins
authored andcommitted
test: improve test-http-allow-req-after-204-res
* use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: #10503 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 692dce7 commit 166c7f5

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

test/parallel/test-http-allow-req-after-204-res.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
'use strict';
2-
require('../common');
3-
var http = require('http');
4-
var assert = require('assert');
2+
const common = require('../common');
3+
const http = require('http');
4+
const assert = require('assert');
55

66
// first 204 or 304 works, subsequent anything fails
7-
var codes = [204, 200];
7+
const codes = [204, 200];
88

99
// Methods don't really matter, but we put in something realistic.
10-
var methods = ['DELETE', 'DELETE'];
10+
const methods = ['DELETE', 'DELETE'];
1111

12-
var server = http.createServer(function(req, res) {
13-
var code = codes.shift();
14-
assert.equal('number', typeof code);
12+
const server = http.createServer(common.mustCall((req, res) => {
13+
const code = codes.shift();
14+
assert.strictEqual(typeof code, 'number');
1515
assert.ok(code > 0);
16-
console.error('writing %d response', code);
1716
res.writeHead(code, {});
1817
res.end();
19-
});
18+
}, codes.length));
2019

2120
function nextRequest() {
22-
var method = methods.shift();
23-
console.error('writing request: %s', method);
21+
const method = methods.shift();
2422

25-
var request = http.request({
23+
const request = http.request({
2624
port: server.address().port,
2725
method: method,
2826
path: '/'
29-
}, function(response) {
30-
response.on('end', function() {
27+
}, common.mustCall((response) => {
28+
response.on('end', common.mustCall(() => {
3129
if (methods.length === 0) {
32-
console.error('close server');
3330
server.close();
3431
} else {
3532
// throws error:
3633
nextRequest();
3734
// works just fine:
3835
//process.nextTick(nextRequest);
3936
}
40-
});
37+
}));
4138
response.resume();
42-
});
39+
}));
4340
request.end();
4441
}
4542

0 commit comments

Comments
 (0)