node/test/parallel/test-stdin-script-child.js
Emanuel Buholzer bc57f241fa test: refactor test-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

PR-URL: https://github.com/nodejs/node/pull/10321
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
2016-12-22 20:25:22 -05:00

33 lines
748 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const child = spawn(process.execPath, [], {
env: Object.assign(process.env, {
NODE_DEBUG: process.argv[2]
})
});
const wanted = child.pid + '\n';
var found = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function(c) {
found += c;
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
console.error('> ' + c.trim().split(/\n/).join('\n> '));
});
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)');
}, 1);