Skip to content

Commit e78de99

Browse files
edsadritaloacasas
authored andcommitted
test: improve test-http-chunked-304
* change the nested functions call to run tests in parallel * use const and let instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: #10462 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent ff23d81 commit e78de99

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

test/parallel/test-http-chunked-304.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@ var net = require('net');
1212
// Likewise for 304 responses. Verify that no empty chunk is sent when
1313
// the user explicitly sets a Transfer-Encoding header.
1414

15-
test(204, function() {
16-
test(304);
17-
});
15+
test(204);
16+
test(304);
1817

19-
function test(statusCode, next) {
20-
var server = http.createServer(function(req, res) {
18+
function test(statusCode) {
19+
const server = http.createServer(common.mustCall((req, res) => {
2120
res.writeHead(statusCode, { 'Transfer-Encoding': 'chunked' });
2221
res.end();
2322
server.close();
24-
});
23+
}));
2524

26-
server.listen(0, function() {
27-
var conn = net.createConnection(this.address().port, function() {
28-
conn.write('GET / HTTP/1.1\r\n\r\n');
25+
server.listen(0, common.mustCall(() => {
26+
const conn = net.createConnection(
27+
server.address().port,
28+
common.mustCall(() => {
29+
conn.write('GET / HTTP/1.1\r\n\r\n');
2930

30-
var resp = '';
31-
conn.setEncoding('utf8');
32-
conn.on('data', function(data) {
33-
resp += data;
34-
});
31+
let resp = '';
32+
conn.setEncoding('utf8');
33+
conn.on('data', common.mustCall((data) => {
34+
resp += data;
35+
}));
3536

36-
conn.on('end', common.mustCall(function() {
37-
assert.equal(/^Connection: close\r\n$/m.test(resp), true);
38-
assert.equal(/^0\r\n$/m.test(resp), false);
39-
if (next) process.nextTick(next);
40-
}));
41-
});
42-
});
37+
conn.on('end', common.mustCall(() => {
38+
// Connection: close should be in the response
39+
assert.strictEqual(/^Connection: close\r\n$/m.test(resp), true);
40+
// Make sure this doesn't end with 0\r\n\r\n
41+
assert.strictEqual(/^0\r\n$/m.test(resp), false);
42+
}));
43+
})
44+
);
45+
}));
4346
}

0 commit comments

Comments
 (0)