fix: importing from electron/utility in ESM (#48019)
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:
parent
fffe214702
commit
03a14844b1
22 changed files with 228 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
import { BrowserWindow } from 'electron/main';
|
||||
import { BrowserWindow, utilityProcess } from 'electron/main';
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
|
@ -82,6 +82,8 @@ describe('modules support', () => {
|
|||
});
|
||||
|
||||
describe('require(\'electron/...\')', () => {
|
||||
const utilityProcessFixturesPath = path.resolve(__dirname, 'fixtures', 'api', 'utility-process', 'electron-modules');
|
||||
|
||||
it('require(\'electron/lol\') should throw in the main process', () => {
|
||||
expect(() => {
|
||||
require('electron/lol');
|
||||
|
@ -94,6 +96,17 @@ describe('modules support', () => {
|
|||
await expect(w.webContents.executeJavaScript('{ require(\'electron/lol\'); null }')).to.eventually.be.rejected();
|
||||
});
|
||||
|
||||
it('require(\'electron/lol\') should throw in the utility process', async () => {
|
||||
const child = utilityProcess.fork(path.join(utilityProcessFixturesPath, 'require-lol.js'), [], {
|
||||
stdio: ['ignore', 'ignore', 'pipe']
|
||||
});
|
||||
let stderr = '';
|
||||
child.stderr!.on('data', (data) => { stderr += data.toString('utf8'); });
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(1);
|
||||
expect(stderr).to.match(/Cannot find module 'electron\/lol'/);
|
||||
});
|
||||
|
||||
it('require(\'electron\') should not throw in the main process', () => {
|
||||
expect(() => {
|
||||
require('electron');
|
||||
|
@ -118,6 +131,12 @@ describe('modules support', () => {
|
|||
await expect(w.webContents.executeJavaScript('{ require(\'electron/main\'); null }')).to.be.fulfilled();
|
||||
});
|
||||
|
||||
it('require(\'electron/main\') should not throw in the utility process', async () => {
|
||||
const child = utilityProcess.fork(path.join(utilityProcessFixturesPath, 'require-main.js'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
|
||||
it('require(\'electron/renderer\') should not throw in the main process', () => {
|
||||
expect(() => {
|
||||
require('electron/renderer');
|
||||
|
@ -130,6 +149,12 @@ describe('modules support', () => {
|
|||
await expect(w.webContents.executeJavaScript('{ require(\'electron/renderer\'); null }')).to.be.fulfilled();
|
||||
});
|
||||
|
||||
it('require(\'electron/renderer\') should not throw in the utility process', async () => {
|
||||
const child = utilityProcess.fork(path.join(utilityProcessFixturesPath, 'require-renderer.js'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
|
||||
it('require(\'electron/common\') should not throw in the main process', () => {
|
||||
expect(() => {
|
||||
require('electron/common');
|
||||
|
@ -141,6 +166,30 @@ describe('modules support', () => {
|
|||
w.loadURL('about:blank');
|
||||
await expect(w.webContents.executeJavaScript('{ require(\'electron/common\'); null }')).to.be.fulfilled();
|
||||
});
|
||||
|
||||
it('require(\'electron/common\') should not throw in the utility process', async () => {
|
||||
const child = utilityProcess.fork(path.join(utilityProcessFixturesPath, 'require-common.js'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
|
||||
it('require(\'electron/utility\') should not throw in the main process', () => {
|
||||
expect(() => {
|
||||
require('electron/utility');
|
||||
}).to.not.throw();
|
||||
});
|
||||
|
||||
it('require(\'electron/utility\') should not throw in the renderer process', async () => {
|
||||
const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
||||
w.loadURL('about:blank');
|
||||
await expect(w.webContents.executeJavaScript('{ require(\'electron/utility\'); null }')).to.be.fulfilled();
|
||||
});
|
||||
|
||||
it('require(\'electron/utility\') should not throw in the utility process', async () => {
|
||||
const child = utilityProcess.fork(path.join(utilityProcessFixturesPath, 'require-utility.js'));
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('coffeescript', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue