fix: support esm entrypoint to utility process (#40047)
This commit is contained in:
parent
d6c8ff2e70
commit
371e83a8d2
4 changed files with 41 additions and 3 deletions
|
@ -5,6 +5,7 @@ import { BrowserWindow, MessageChannelMain, utilityProcess } from 'electron/main
|
|||
import { ifit } from './lib/spec-helpers';
|
||||
import { closeWindow } from './lib/window-helpers';
|
||||
import { once } from 'node:events';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, 'fixtures', 'api', 'utility-process');
|
||||
const isWindowsOnArm = process.platform === 'win32' && process.arch === 'arm64';
|
||||
|
@ -78,6 +79,12 @@ describe('utilityProcess module', () => {
|
|||
expect(code).to.equal(1);
|
||||
});
|
||||
|
||||
it('emits \'exit\' when there is uncaught exception in ESM', async () => {
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'exception.mjs'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(1);
|
||||
});
|
||||
|
||||
it('emits \'exit\' when process.exit is called', async () => {
|
||||
const exitCode = 2;
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'custom-exit.js'), [`--exitCode=${exitCode}`]);
|
||||
|
@ -97,6 +104,23 @@ describe('utilityProcess module', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('esm', () => {
|
||||
it('is launches an mjs file', async () => {
|
||||
const fixtureFile = path.join(fixturesPath, 'esm.mjs');
|
||||
const child = utilityProcess.fork(fixtureFile, [], {
|
||||
stdio: 'pipe'
|
||||
});
|
||||
await once(child, 'spawn');
|
||||
expect(child.stdout).to.not.be.null();
|
||||
let log = '';
|
||||
child.stdout!.on('data', (chunk) => {
|
||||
log += chunk.toString('utf8');
|
||||
});
|
||||
await once(child, 'exit');
|
||||
expect(log).to.equal(pathToFileURL(fixtureFile) + '\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pid property', () => {
|
||||
it('is valid when child process launches successfully', async () => {
|
||||
const child = utilityProcess.fork(path.join(fixturesPath, 'empty.js'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue