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
Ebrahim Byagowi 594b5d7b89
cmd: support dash as stdin alias
PR-URL: https://github.com/nodejs/node/pull/13012
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-05-23 20:41:13 +02: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);
}