mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

The subprocess might exit before the data is flushed. Run the assertion after the `'end'` event is emitted. PR-URL: https://github.com/nodejs/node/pull/42046 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { spawn } = require('child_process');
|
|
|
|
if (process.argv[2] !== 'child') {
|
|
// Expected error not emitted.
|
|
{
|
|
const child = spawn(
|
|
process.execPath, [__filename, 'child', 0], { encoding: 'utf8' }
|
|
);
|
|
child.on('exit', common.mustCall((status) => {
|
|
assert.notStrictEqual(status, 0);
|
|
}));
|
|
}
|
|
|
|
// Expected error emitted.
|
|
{
|
|
const child = spawn(
|
|
process.execPath, [__filename, 'child', 1], { encoding: 'utf8' }
|
|
);
|
|
child.on('exit', common.mustCall((status) => {
|
|
assert.strictEqual(status, 0);
|
|
}));
|
|
}
|
|
|
|
// Expected error emitted too many times.
|
|
{
|
|
const child = spawn(
|
|
process.execPath, [__filename, 'child', 2], { encoding: 'utf8' }
|
|
);
|
|
child.stderr.setEncoding('utf8');
|
|
|
|
let stderr = '';
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data;
|
|
});
|
|
child.stderr.on('end', common.mustCall(() => {
|
|
assert.match(stderr, /Unexpected extra warning received/);
|
|
}));
|
|
child.on('exit', common.mustCall((status) => {
|
|
assert.notStrictEqual(status, 0);
|
|
}));
|
|
}
|
|
} else {
|
|
const iterations = +process.argv[3];
|
|
common.expectWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads');
|
|
for (let i = 0; i < iterations; i++) {
|
|
process.emitWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads');
|
|
}
|
|
}
|