fix: importing from electron/utility in ESM (#48021)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
trop[bot] 2025-08-11 11:17:15 -04:00 committed by GitHub
commit a84d77143f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 228 additions and 7 deletions

View file

@ -64,6 +64,32 @@ describe('esm', () => {
expect(result.code).to.equal(0);
expect(result.stdout).to.equal('Exit with app, ready: false');
});
it('import \'electron/lol\' should throw', async () => {
const result = await runFixture(path.resolve(fixturePath, 'electron-modules', 'import-lol.mjs'));
expect(result.code).to.equal(1);
expect(result.stderr).to.match(/Error \[ERR_MODULE_NOT_FOUND\]/);
});
it('import \'electron/main\' should not throw', async () => {
const result = await runFixture(path.resolve(fixturePath, 'electron-modules', 'import-main.mjs'));
expect(result.code).to.equal(0);
});
it('import \'electron/renderer\' should not throw', async () => {
const result = await runFixture(path.resolve(fixturePath, 'electron-modules', 'import-renderer.mjs'));
expect(result.code).to.equal(0);
});
it('import \'electron/common\' should not throw', async () => {
const result = await runFixture(path.resolve(fixturePath, 'electron-modules', 'import-common.mjs'));
expect(result.code).to.equal(0);
});
it('import \'electron/utility\' should not throw', async () => {
const result = await runFixture(path.resolve(fixturePath, 'electron-modules', 'import-utility.mjs'));
expect(result.code).to.equal(0);
});
});
describe('renderer process', () => {
@ -212,5 +238,43 @@ describe('esm', () => {
});
});
});
describe('electron modules', () => {
it('import \'electron/lol\' should throw', async () => {
const [, error] = await loadWindowWithPreload('import { ipcRenderer } from "electron/lol";', {
sandbox: false
});
expect(error).to.not.equal(null);
expect(error?.message).to.match(/Cannot find package 'electron'/);
});
it('import \'electron/main\' should not throw', async () => {
const [, error] = await loadWindowWithPreload('import { ipcRenderer } from "electron/main";', {
sandbox: false
});
expect(error).to.equal(null);
});
it('import \'electron/renderer\' should not throw', async () => {
const [, error] = await loadWindowWithPreload('import { ipcRenderer } from "electron/renderer";', {
sandbox: false
});
expect(error).to.equal(null);
});
it('import \'electron/common\' should not throw', async () => {
const [, error] = await loadWindowWithPreload('import { ipcRenderer } from "electron/common";', {
sandbox: false
});
expect(error).to.equal(null);
});
it('import \'electron/utility\' should not throw', async () => {
const [, error] = await loadWindowWithPreload('import { ipcRenderer } from "electron/utility";', {
sandbox: false
});
expect(error).to.equal(null);
});
});
});
});