node/test/parallel/test-stdin-script-child.js
Vse Mozhet Byt 0fdb67be9f test: use string instead of RegExp in split()
PR-URL: https://github.com/nodejs/node/pull/13710
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-06-19 02:26:04 +03:00

34 lines
807 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { spawn } = require('child_process');
for (const args of [[], ['-']]) {
const child = spawn(process.execPath, args, {
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);
}));
setTimeout(function() {
child.stdin.end('console.log(process.pid)');
}, 1);
}