0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-stdin-script-child.js
Vse Mozhet Byt 8b76c3e60c test: reduce string concatenations
PR-URL: https://github.com/nodejs/node/pull/12735
Refs: https://github.com/nodejs/node/pull/12455
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-05-05 17:39:05 +03: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`;
let 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);