From ed76bfa7ba008a83703825cce1da949017c30f31 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Fri, 16 Dec 2016 10:42:36 -0500 Subject: [PATCH] test: refactor code in test-cluster-http-pipe * use common.mustCall to control the functions execution automatically * use const instead of var * use assert.strictEqual instead assert.equal * use assert.ifError instead of throw error PR-URL: https://github.com/nodejs/node/pull/10297 Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung Reviewed-By: Santiago Gimeno Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-cluster-http-pipe.js | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/parallel/test-cluster-http-pipe.js b/test/parallel/test-cluster-http-pipe.js index 0d6cb422be80c2..6db581564a124c 100644 --- a/test/parallel/test-cluster-http-pipe.js +++ b/test/parallel/test-cluster-http-pipe.js @@ -13,28 +13,28 @@ if (common.isWindows) { if (cluster.isMaster) { common.refreshTmpDir(); - var worker = cluster.fork(); - worker.on('message', common.mustCall(function(msg) { - assert.equal(msg, 'DONE'); + const worker = cluster.fork(); + worker.on('message', common.mustCall((msg) => { + assert.strictEqual(msg, 'DONE'); })); - worker.on('exit', function() { - process.exit(); - }); + worker.on('exit', common.mustCall(() => {})); return; } -http.createServer(function(req, res) { - assert.equal(req.connection.remoteAddress, undefined); - assert.equal(req.connection.localAddress, undefined); // TODO common.PIPE? +http.createServer(common.mustCall((req, res) => { + assert.strictEqual(req.connection.remoteAddress, undefined); + assert.strictEqual(req.connection.localAddress, undefined); + // TODO common.PIPE? + res.writeHead(200); res.end('OK'); -}).listen(common.PIPE, function() { - http.get({ socketPath: common.PIPE, path: '/' }, function(res) { +})).listen(common.PIPE, common.mustCall(() => { + http.get({ socketPath: common.PIPE, path: '/' }, common.mustCall((res) => { res.resume(); - res.on('end', function(err) { - if (err) throw err; + res.on('end', common.mustCall((err) => { + assert.ifError(err); process.send('DONE'); process.exit(); - }); - }); -}); + })); + })); +}));