From 20046f8720884d61d3260132032af88f35bd405c Mon Sep 17 00:00:00 2001 From: Emanuel Buholzer Date: Sun, 18 Dec 2016 03:04:37 +0100 Subject: [PATCH 1/2] test: refactor stdin-script-child - var -> const where possible - assert.equal -> assert.strictEqual - passed the setTimeout function a second parameter for readability - used assert.strictEqual for assert(!c) as it is expected to be 0 and not some other value --- test/parallel/test-stdin-script-child.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-stdin-script-child.js b/test/parallel/test-stdin-script-child.js index ad65734364e707..c141ea7ed9a765 100644 --- a/test/parallel/test-stdin-script-child.js +++ b/test/parallel/test-stdin-script-child.js @@ -1,14 +1,14 @@ 'use strict'; require('../common'); -var assert = require('assert'); +const assert = require('assert'); -var spawn = require('child_process').spawn; -var child = spawn(process.execPath, [], { +const spawn = require('child_process').spawn; +const child = spawn(process.execPath, [], { env: Object.assign(process.env, { NODE_DEBUG: process.argv[2] }) }); -var wanted = child.pid + '\n'; +const wanted = child.pid + '\n'; var found = ''; child.stdout.setEncoding('utf8'); @@ -22,11 +22,11 @@ child.stderr.on('data', function(c) { }); child.on('close', function(c) { - assert(!c); - assert.equal(found, wanted); + assert.strictEqual(c, 0); + assert.strictEqual(found, wanted); console.log('ok'); }); setTimeout(function() { child.stdin.end('console.log(process.pid)'); -}); +}, 1); From f7e5be5f3fd9fc5a589b391947605bba7323f93c Mon Sep 17 00:00:00 2001 From: Emanuel Buholzer Date: Thu, 22 Dec 2016 22:25:06 +0100 Subject: [PATCH 2/2] Wrap the callback with common.mustCall --- test/parallel/test-stdin-script-child.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-stdin-script-child.js b/test/parallel/test-stdin-script-child.js index c141ea7ed9a765..091c5cb29ad296 100644 --- a/test/parallel/test-stdin-script-child.js +++ b/test/parallel/test-stdin-script-child.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const spawn = require('child_process').spawn; @@ -21,11 +21,11 @@ child.stderr.on('data', function(c) { console.error('> ' + c.trim().split(/\n/).join('\n> ')); }); -child.on('close', function(c) { +child.on('close', common.mustCall(function(c) { assert.strictEqual(c, 0); assert.strictEqual(found, wanted); console.log('ok'); -}); +})); setTimeout(function() { child.stdin.end('console.log(process.pid)');