node/test/parallel/test-stdout-cannot-be-closed-child-process-pipe.js
Antoine du Hamel 411ce7ed2e
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60760
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-11-24 22:44:48 +00:00

33 lines
715 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
if (process.argv[2] === 'child')
process.stdout.end('foo');
else
parent();
function parent() {
const spawn = require('child_process').spawn;
const child = spawn(process.execPath, [__filename, 'child']);
let out = '';
let err = '';
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function(c) {
out += c;
});
child.stderr.on('data', function(c) {
err += c;
});
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(err, '');
assert.strictEqual(out, 'foo');
console.log('ok');
}));
}