fix: ensure utilityProcess only emits one 'exit' event (#44243)

fix: ensure utilityProcess only emits one exit
This commit is contained in:
Shelley Vohr 2024-10-16 10:47:12 +02:00 committed by GitHub
parent b5acebf3ba
commit df45474b58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 11 deletions

View file

@ -58,10 +58,20 @@ describe('utilityProcess module', () => {
await once(child, 'spawn');
});
it('emits \'exit\' when child process exits gracefully', async () => {
it('emits \'exit\' when child process exits gracefully', (done) => {
const child = utilityProcess.fork(path.join(fixturesPath, 'empty.js'));
const [code] = await once(child, 'exit');
expect(code).to.equal(0);
child.on('exit', (code) => {
expect(code).to.equal(0);
done();
});
});
it('emits \'exit\' when the child process file does not exist', (done) => {
const child = utilityProcess.fork('nonexistent');
child.on('exit', (code) => {
expect(code).to.equal(1);
done();
});
});
ifit(!isWindows32Bit)('emits the correct error code when child process exits nonzero', async () => {