diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts
index b47a59be7315..fb46131e955d 100644
--- a/spec/api-app-spec.ts
+++ b/spec/api-app-spec.ts
@@ -7,9 +7,9 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import { promisify } from 'util';
import { app, BrowserWindow, Menu, session, net as electronNet } from 'electron/main';
-import { emittedOnce } from './lib/events-helpers';
import { closeWindow, closeAllWindows } from './lib/window-helpers';
import { ifdescribe, ifit, listen, waitUntil } from './lib/spec-helpers';
+import { once } from 'events';
import split = require('split')
const fixturesPath = path.resolve(__dirname, 'fixtures');
@@ -169,7 +169,7 @@ describe('app module', () => {
if (appProcess && appProcess.stdout) {
appProcess.stdout.on('data', data => { output += data; });
}
- const [code] = await emittedOnce(appProcess, 'exit');
+ const [code] = await once(appProcess, 'exit');
if (process.platform !== 'win32') {
expect(output).to.include('Exit event with code: 123');
@@ -182,7 +182,7 @@ describe('app module', () => {
const electronPath = process.execPath;
appProcess = cp.spawn(electronPath, [appPath]);
- const [code, signal] = await emittedOnce(appProcess, 'exit');
+ const [code, signal] = await once(appProcess, 'exit');
expect(signal).to.equal(null, 'exit signal should be null, if you see this please tag @MarshallOfSound');
expect(code).to.equal(123, 'exit code should be 123, if you see this please tag @MarshallOfSound');
@@ -203,7 +203,7 @@ describe('app module', () => {
if (appProcess && appProcess.stdout) {
appProcess.stdout.on('data', () => appProcess!.kill());
}
- const [code, signal] = await emittedOnce(appProcess, 'exit');
+ const [code, signal] = await once(appProcess, 'exit');
const message = `code:\n${code}\nsignal:\n${signal}`;
expect(code).to.equal(0, message);
@@ -229,37 +229,37 @@ describe('app module', () => {
this.timeout(120000);
const appPath = path.join(fixturesPath, 'api', 'singleton-data');
const first = cp.spawn(process.execPath, [appPath]);
- await emittedOnce(first.stdout, 'data');
+ await once(first.stdout, 'data');
// Start second app when received output.
const second = cp.spawn(process.execPath, [appPath]);
- const [code2] = await emittedOnce(second, 'exit');
+ const [code2] = await once(second, 'exit');
expect(code2).to.equal(1);
- const [code1] = await emittedOnce(first, 'exit');
+ const [code1] = await once(first, 'exit');
expect(code1).to.equal(0);
});
it('returns true when setting non-existent user data folder', async function () {
const appPath = path.join(fixturesPath, 'api', 'singleton-userdata');
const instance = cp.spawn(process.execPath, [appPath]);
- const [code] = await emittedOnce(instance, 'exit');
+ const [code] = await once(instance, 'exit');
expect(code).to.equal(0);
});
async function testArgumentPassing (testArgs: SingleInstanceLockTestArgs) {
const appPath = path.join(fixturesPath, 'api', 'singleton-data');
const first = cp.spawn(process.execPath, [appPath, ...testArgs.args]);
- const firstExited = emittedOnce(first, 'exit');
+ const firstExited = once(first, 'exit');
// Wait for the first app to boot.
const firstStdoutLines = first.stdout.pipe(split());
- while ((await emittedOnce(firstStdoutLines, 'data')).toString() !== 'started') {
+ while ((await once(firstStdoutLines, 'data')).toString() !== 'started') {
// wait.
}
- const additionalDataPromise = emittedOnce(firstStdoutLines, 'data');
+ const additionalDataPromise = once(firstStdoutLines, 'data');
const secondInstanceArgs = [process.execPath, appPath, ...testArgs.args, '--some-switch', 'some-arg'];
const second = cp.spawn(secondInstanceArgs[0], secondInstanceArgs.slice(1));
- const secondExited = emittedOnce(second, 'exit');
+ const secondExited = once(second, 'exit');
const [code2] = await secondExited;
expect(code2).to.equal(1);
@@ -427,7 +427,7 @@ describe('app module', () => {
it('is emitted when visiting a server with a self-signed cert', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(secureUrl);
- await emittedOnce(app, 'certificate-error');
+ await once(app, 'certificate-error');
});
describe('when denied', () => {
@@ -444,7 +444,7 @@ describe('app module', () => {
it('causes did-fail-load', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(secureUrl);
- await emittedOnce(w.webContents, 'did-fail-load');
+ await once(w.webContents, 'did-fail-load');
});
});
});
@@ -506,7 +506,7 @@ describe('app module', () => {
afterEach(() => closeWindow(w).then(() => { w = null as any; }));
it('should emit browser-window-focus event when window is focused', async () => {
- const emitted = emittedOnce(app, 'browser-window-focus');
+ const emitted = once(app, 'browser-window-focus');
w = new BrowserWindow({ show: false });
w.emit('focus');
const [, window] = await emitted;
@@ -514,7 +514,7 @@ describe('app module', () => {
});
it('should emit browser-window-blur event when window is blurred', async () => {
- const emitted = emittedOnce(app, 'browser-window-blur');
+ const emitted = once(app, 'browser-window-blur');
w = new BrowserWindow({ show: false });
w.emit('blur');
const [, window] = await emitted;
@@ -522,14 +522,14 @@ describe('app module', () => {
});
it('should emit browser-window-created event when window is created', async () => {
- const emitted = emittedOnce(app, 'browser-window-created');
+ const emitted = once(app, 'browser-window-created');
w = new BrowserWindow({ show: false });
const [, window] = await emitted;
expect(window.id).to.equal(w.id);
});
it('should emit web-contents-created event when a webContents is created', async () => {
- const emitted = emittedOnce(app, 'web-contents-created');
+ const emitted = once(app, 'web-contents-created');
w = new BrowserWindow({ show: false });
const [, webContents] = await emitted;
expect(webContents.id).to.equal(w.webContents.id);
@@ -546,7 +546,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
- const emitted = emittedOnce(app, 'renderer-process-crashed');
+ const emitted = once(app, 'renderer-process-crashed');
w.webContents.executeJavaScript('process.crash()');
const [, webContents] = await emitted;
@@ -564,7 +564,7 @@ describe('app module', () => {
});
await w.loadURL('about:blank');
- const emitted = emittedOnce(app, 'render-process-gone');
+ const emitted = once(app, 'render-process-gone');
w.webContents.executeJavaScript('process.crash()');
const [, webContents, details] = await emitted;
@@ -890,7 +890,7 @@ describe('app module', () => {
ifit(process.platform === 'win32')('detects disabled by TaskManager', async function () {
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: true, args: ['arg1'] });
const appProcess = cp.spawn('reg', [...regAddArgs, '030000000000000000000000']);
- await emittedOnce(appProcess, 'exit');
+ await once(appProcess, 'exit');
expect(app.getLoginItemSettings()).to.deep.equal({
openAtLogin: false,
openAsHidden: false,
@@ -927,12 +927,12 @@ describe('app module', () => {
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false, args: ['arg1'] });
let appProcess = cp.spawn('reg', [...regAddArgs, '020000000000000000000000']);
- await emittedOnce(appProcess, 'exit');
+ await once(appProcess, 'exit');
expect(app.getLoginItemSettings()).to.deep.equal(expectation);
app.setLoginItemSettings({ openAtLogin: true, name: 'additionalEntry', enabled: false, args: ['arg1'] });
appProcess = cp.spawn('reg', [...regAddArgs, '000000000000000000000000']);
- await emittedOnce(appProcess, 'exit');
+ await once(appProcess, 'exit');
expect(app.getLoginItemSettings()).to.deep.equal(expectation);
});
});
@@ -1290,7 +1290,7 @@ describe('app module', () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with non 123 code.
const first = cp.spawn(process.execPath, [appPath, 'electron-test:?', 'abc']);
- const [code] = await emittedOnce(first, 'exit');
+ const [code] = await once(first, 'exit');
expect(code).to.not.equal(123);
});
@@ -1298,7 +1298,7 @@ describe('app module', () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with code 123.
const first = cp.spawn(process.execPath, [appPath, 'e:\\abc', 'abc']);
- const [code] = await emittedOnce(first, 'exit');
+ const [code] = await once(first, 'exit');
expect(code).to.equal(123);
});
@@ -1306,7 +1306,7 @@ describe('app module', () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with code 123.
const first = cp.spawn(process.execPath, [appPath, '--', 'http://electronjs.org', 'electron-test://testdata']);
- const [code] = await emittedOnce(first, 'exit');
+ const [code] = await once(first, 'exit');
expect(code).to.equal(123);
});
});
@@ -1432,7 +1432,7 @@ describe('app module', () => {
appProcess.stderr.on('data', (data) => {
errorData += data;
});
- const [exitCode] = await emittedOnce(appProcess, 'exit');
+ const [exitCode] = await once(appProcess, 'exit');
if (exitCode === 0) {
try {
const [, json] = /HERE COMES THE JSON: (.+) AND THERE IT WAS/.exec(gpuInfoData)!;
@@ -1949,7 +1949,7 @@ describe('default behavior', () => {
it('should emit a login event on app when a WebContents hits a 401', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(serverUrl);
- const [, webContents] = await emittedOnce(app, 'login');
+ const [, webContents] = await once(app, 'login');
expect(webContents).to.equal(w.webContents);
});
});
@@ -1976,7 +1976,7 @@ async function runTestApp (name: string, ...args: any[]) {
let output = '';
appProcess.stdout.on('data', (data) => { output += data; });
- await emittedOnce(appProcess.stdout, 'end');
+ await once(appProcess.stdout, 'end');
return JSON.parse(output);
}
diff --git a/spec/api-auto-updater-spec.ts b/spec/api-auto-updater-spec.ts
index 27183c96216e..fe89b97be235 100644
--- a/spec/api-auto-updater-spec.ts
+++ b/spec/api-auto-updater-spec.ts
@@ -1,12 +1,12 @@
import { autoUpdater } from 'electron/main';
import { expect } from 'chai';
import { ifit, ifdescribe } from './lib/spec-helpers';
-import { emittedOnce } from './lib/events-helpers';
+import { once } from 'events';
ifdescribe(!process.mas)('autoUpdater module', function () {
describe('checkForUpdates', function () {
ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', async function () {
- const errorEvent = emittedOnce(autoUpdater, 'error');
+ const errorEvent = once(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
autoUpdater.checkForUpdates();
const [error] = await errorEvent;
@@ -56,7 +56,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
ifdescribe(process.platform === 'darwin' && process.arch !== 'arm64')('on Mac', function () {
it('emits an error when the application is unsigned', async () => {
- const errorEvent = emittedOnce(autoUpdater, 'error');
+ const errorEvent = once(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
const [error] = await errorEvent;
expect(error.message).equal('Could not get code signature for running application');
@@ -80,7 +80,7 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
describe('quitAndInstall', () => {
ifit(process.platform === 'win32')('emits an error on Windows when no update is available', async function () {
- const errorEvent = emittedOnce(autoUpdater, 'error');
+ const errorEvent = once(autoUpdater, 'error');
autoUpdater.quitAndInstall();
const [error] = await errorEvent;
expect(error.message).to.equal('No update available, can\'t quit and install');
diff --git a/spec/api-browser-view-spec.ts b/spec/api-browser-view-spec.ts
index c4de3dff86fe..65b70e911b53 100644
--- a/spec/api-browser-view-spec.ts
+++ b/spec/api-browser-view-spec.ts
@@ -1,10 +1,10 @@
import { expect } from 'chai';
import * as path from 'path';
-import { emittedOnce } from './lib/events-helpers';
import { BrowserView, BrowserWindow, screen, webContents } from 'electron/main';
import { closeWindow } from './lib/window-helpers';
import { defer, ifit, startRemoteControlApp } from './lib/spec-helpers';
import { areColorsSimilar, captureScreen, getPixelColor } from './lib/screen-helpers';
+import { once } from 'events';
describe('BrowserView module', () => {
const fixtures = path.resolve(__dirname, 'fixtures');
@@ -25,13 +25,13 @@ describe('BrowserView module', () => {
});
afterEach(async () => {
- const p = emittedOnce(w.webContents, 'destroyed');
+ const p = once(w.webContents, 'destroyed');
await closeWindow(w);
w = null as any;
await p;
if (view && view.webContents) {
- const p = emittedOnce(view.webContents, 'destroyed');
+ const p = once(view.webContents, 'destroyed');
view.webContents.destroy();
view = null as any;
await p;
@@ -231,7 +231,7 @@ describe('BrowserView module', () => {
w.addBrowserView(view);
view.webContents.loadURL('about:blank');
- await emittedOnce(view.webContents, 'did-finish-load');
+ await once(view.webContents, 'did-finish-load');
const w2 = new BrowserWindow({ show: false });
w2.addBrowserView(view);
@@ -239,7 +239,7 @@ describe('BrowserView module', () => {
w.close();
view.webContents.loadURL(`file://${fixtures}/pages/blank.html`);
- await emittedOnce(view.webContents, 'did-finish-load');
+ await once(view.webContents, 'did-finish-load');
// Clean up - the afterEach hook assumes the webContents on w is still alive.
w = new BrowserWindow({ show: false });
@@ -326,7 +326,7 @@ describe('BrowserView module', () => {
app.quit();
});
});
- const [code] = await emittedOnce(rc.process, 'exit');
+ const [code] = await once(rc.process, 'exit');
expect(code).to.equal(0);
});
@@ -342,7 +342,7 @@ describe('BrowserView module', () => {
app.quit();
});
});
- const [code] = await emittedOnce(rc.process, 'exit');
+ const [code] = await once(rc.process, 'exit');
expect(code).to.equal(0);
});
});
diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts
index 3252bc0eff84..4eb4e908c497 100644
--- a/spec/api-browser-window-spec.ts
+++ b/spec/api-browser-window-spec.ts
@@ -7,10 +7,12 @@ import * as http from 'http';
import * as os from 'os';
import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersListenerDetails, protocol, screen, webContents, session, WebContents } from 'electron/main';
-import { emittedOnce, emittedUntil, emittedNTimes } from './lib/events-helpers';
-import { ifit, ifdescribe, defer, delay, listen } from './lib/spec-helpers';
+import { emittedUntil, emittedNTimes } from './lib/events-helpers';
+import { ifit, ifdescribe, defer, listen } from './lib/spec-helpers';
import { closeWindow, closeAllWindows } from './lib/window-helpers';
import { areColorsSimilar, captureScreen, HexColors, getPixelColor } from './lib/screen-helpers';
+import { once } from 'events';
+import { setTimeout } from 'timers/promises';
const features = process._linkedBinding('electron_common_features');
const fixtures = path.resolve(__dirname, 'fixtures');
@@ -61,7 +63,7 @@ describe('BrowserWindow module', () => {
ifit(process.platform === 'linux')('does not crash when setting large window icons', async () => {
const appPath = path.join(fixtures, 'apps', 'xwindow-icon');
const appProcess = childProcess.spawn(process.execPath, [appPath]);
- await emittedOnce(appProcess, 'exit');
+ await once(appProcess, 'exit');
});
it('does not crash or throw when passed an invalid icon', async () => {
@@ -83,12 +85,12 @@ describe('BrowserWindow module', () => {
// Keep a weak reference to the window.
// eslint-disable-next-line no-undef
const wr = new WeakRef(w);
- await delay();
+ await setTimeout();
// Do garbage collection, since |w| is not referenced in this closure
// it would be gone after next call if there is no other reference.
v8Util.requestGarbageCollectionForTesting();
- await delay();
+ await setTimeout();
expect(wr.deref()).to.not.be.undefined();
});
});
@@ -104,7 +106,7 @@ describe('BrowserWindow module', () => {
});
it('should work if called when a messageBox is showing', async () => {
- const closed = emittedOnce(w, 'closed');
+ const closed = once(w, 'closed');
dialog.showMessageBox(w, { message: 'Hello Error' });
w.close();
await closed;
@@ -113,7 +115,7 @@ describe('BrowserWindow module', () => {
it('closes window without rounded corners', async () => {
await closeWindow(w);
w = new BrowserWindow({ show: false, frame: false, roundedCorners: false });
- const closed = emittedOnce(w, 'closed');
+ const closed = once(w, 'closed');
w.close();
await closed;
});
@@ -125,7 +127,7 @@ describe('BrowserWindow module', () => {
it('should emit unload handler', async () => {
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
- const closed = emittedOnce(w, 'closed');
+ const closed = once(w, 'closed');
w.close();
await closed;
const test = path.join(fixtures, 'api', 'unload');
@@ -137,12 +139,12 @@ describe('BrowserWindow module', () => {
it('should emit beforeunload handler', async () => {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.close();
- await emittedOnce(w.webContents, 'before-unload-fired');
+ await once(w.webContents, 'before-unload-fired');
});
it('should not crash when keyboard event is sent before closing', async () => {
await w.loadURL('data:text/html,pls no crash');
- const closed = emittedOnce(w, 'closed');
+ const closed = once(w, 'closed');
w.webContents.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
w.close();
await closed;
@@ -199,7 +201,7 @@ describe('BrowserWindow module', () => {
w.webContents.once((name as any), () => {
w.close();
});
- const destroyed = emittedOnce(w.webContents, 'destroyed');
+ const destroyed = once(w.webContents, 'destroyed');
w.webContents.loadURL(url + path);
await destroyed;
});
@@ -219,7 +221,7 @@ describe('BrowserWindow module', () => {
it('should emit unload event', async () => {
w.loadFile(path.join(fixtures, 'api', 'close.html'));
- await emittedOnce(w, 'closed');
+ await once(w, 'closed');
const test = path.join(fixtures, 'api', 'close');
const content = fs.readFileSync(test).toString();
fs.unlinkSync(test);
@@ -229,7 +231,7 @@ describe('BrowserWindow module', () => {
it('should emit beforeunload event', async function () {
await w.loadFile(path.join(__dirname, 'fixtures', 'api', 'beforeunload-false.html'));
w.webContents.executeJavaScript('window.close()', true);
- await emittedOnce(w.webContents, 'before-unload-fired');
+ await once(w.webContents, 'before-unload-fired');
});
});
@@ -336,7 +338,7 @@ describe('BrowserWindow module', () => {
res.end();
}
}
- setTimeout(respond, req.url && req.url.includes('slow') ? 200 : 0);
+ setTimeout(req.url && req.url.includes('slow') ? 200 : 0).then(respond);
});
url = (await listen(server)).url;
@@ -347,19 +349,19 @@ describe('BrowserWindow module', () => {
});
it('should emit did-start-loading event', async () => {
- const didStartLoading = emittedOnce(w.webContents, 'did-start-loading');
+ const didStartLoading = once(w.webContents, 'did-start-loading');
w.loadURL('about:blank');
await didStartLoading;
});
it('should emit ready-to-show event', async () => {
- const readyToShow = emittedOnce(w, 'ready-to-show');
+ const readyToShow = once(w, 'ready-to-show');
w.loadURL('about:blank');
await readyToShow;
});
// TODO(deepak1556): The error code now seems to be `ERR_FAILED`, verify what
// changed and adjust the test.
it.skip('should emit did-fail-load event for files that do not exist', async () => {
- const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
+ const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL('file://a.txt');
const [, code, desc,, isMainFrame] = await didFailLoad;
expect(code).to.equal(-6);
@@ -367,7 +369,7 @@ describe('BrowserWindow module', () => {
expect(isMainFrame).to.equal(true);
});
it('should emit did-fail-load event for invalid URL', async () => {
- const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
+ const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL('http://example:port');
const [, code, desc,, isMainFrame] = await didFailLoad;
expect(desc).to.equal('ERR_INVALID_URL');
@@ -375,7 +377,7 @@ describe('BrowserWindow module', () => {
expect(isMainFrame).to.equal(true);
});
it('should set `mainFrame = false` on did-fail-load events in iframes', async () => {
- const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
+ const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadFile(path.join(fixtures, 'api', 'did-fail-load-iframe.html'));
const [,,,, isMainFrame] = await didFailLoad;
expect(isMainFrame).to.equal(false);
@@ -389,7 +391,7 @@ describe('BrowserWindow module', () => {
});
it('should emit did-fail-load event for URL exceeding character limit', async () => {
const data = Buffer.alloc(2 * 1024 * 1024).toString('base64');
- const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
+ const didFailLoad = once(w.webContents, 'did-fail-load');
w.loadURL(`data:image/png;base64,${data}`);
const [, code, desc,, isMainFrame] = await didFailLoad;
expect(desc).to.equal('ERR_INVALID_URL');
@@ -498,7 +500,7 @@ describe('BrowserWindow module', () => {
});
it('allows the window to be closed from the event listener', async () => {
- const event = emittedOnce(w.webContents, 'will-navigate');
+ const event = once(w.webContents, 'will-navigate');
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
await event;
w.close();
@@ -552,7 +554,7 @@ describe('BrowserWindow module', () => {
it('is triggered when a cross-origin iframe navigates _top', async () => {
await w.loadURL(`data:text/html,`);
- await delay(1000);
+ await setTimeout(1000);
w.webContents.debugger.attach('1.1');
const targets = await w.webContents.debugger.sendCommand('Target.getTargets');
const iframeTarget = targets.targetInfos.find((t: any) => t.type === 'iframe');
@@ -578,7 +580,7 @@ describe('BrowserWindow module', () => {
clickCount: 1,
button: 'left'
}, sessionId);
- await emittedOnce(w.webContents, 'did-navigate');
+ await once(w.webContents, 'did-navigate');
expect(willNavigateEmitted).to.be.true();
});
});
@@ -605,7 +607,7 @@ describe('BrowserWindow module', () => {
server.close();
});
it('is emitted on redirects', async () => {
- const willRedirect = emittedOnce(w.webContents, 'will-redirect');
+ const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await willRedirect;
});
@@ -615,7 +617,7 @@ describe('BrowserWindow module', () => {
w.webContents.on('will-navigate', () => {
navigateCalled = true;
});
- const willRedirect = emittedOnce(w.webContents, 'will-redirect');
+ const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/navigate-302`);
await willRedirect;
expect(navigateCalled).to.equal(true, 'should have called will-navigate first');
@@ -626,14 +628,14 @@ describe('BrowserWindow module', () => {
w.webContents.on('did-stop-loading', () => {
stopCalled = true;
});
- const willRedirect = emittedOnce(w.webContents, 'will-redirect');
+ const willRedirect = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await willRedirect;
expect(stopCalled).to.equal(false, 'should not have called did-stop-loading first');
});
it('allows the window to be closed from the event listener', async () => {
- const event = emittedOnce(w.webContents, 'will-redirect');
+ const event = once(w.webContents, 'will-redirect');
w.loadURL(`${url}/302`);
await event;
w.close();
@@ -682,15 +684,19 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.show()', () => {
it('should focus on window', async () => {
- await emittedOnce(w, 'focus', () => w.show());
+ const p = once(w, 'focus');
+ w.show();
+ await p;
expect(w.isFocused()).to.equal(true);
});
it('should make the window visible', async () => {
- await emittedOnce(w, 'focus', () => w.show());
+ const p = once(w, 'focus');
+ w.show();
+ await p;
expect(w.isVisible()).to.equal(true);
});
it('emits when window is shown', async () => {
- const show = emittedOnce(w, 'show');
+ const show = once(w, 'show');
w.show();
await show;
expect(w.isVisible()).to.equal(true);
@@ -708,10 +714,10 @@ describe('BrowserWindow module', () => {
expect(w.isVisible()).to.equal(false);
});
it('emits when window is hidden', async () => {
- const shown = emittedOnce(w, 'show');
+ const shown = once(w, 'show');
w.show();
await shown;
- const hidden = emittedOnce(w, 'hide');
+ const hidden = once(w, 'hide');
w.hide();
await hidden;
expect(w.isVisible()).to.equal(false);
@@ -726,14 +732,14 @@ describe('BrowserWindow module', () => {
// TODO(dsanders11): Enable for Linux once CI plays nice with these kinds of tests
ifit(process.platform !== 'linux')('should not restore maximized windows', async () => {
- const maximize = emittedOnce(w, 'maximize');
- const shown = emittedOnce(w, 'show');
+ const maximize = once(w, 'maximize');
+ const shown = once(w, 'show');
w.maximize();
// TODO(dsanders11): The maximize event isn't firing on macOS for a window initially hidden
if (process.platform !== 'darwin') {
await maximize;
} else {
- await delay(1000);
+ await setTimeout(1000);
}
w.showInactive();
await shown;
@@ -750,8 +756,8 @@ describe('BrowserWindow module', () => {
ifit(process.platform !== 'win32')('focuses a blurred window', async () => {
{
- const isBlurred = emittedOnce(w, 'blur');
- const isShown = emittedOnce(w, 'show');
+ const isBlurred = once(w, 'blur');
+ const isShown = once(w, 'show');
w.show();
w.blur();
await isShown;
@@ -767,10 +773,10 @@ describe('BrowserWindow module', () => {
const w2 = new BrowserWindow({ show: false });
const w3 = new BrowserWindow({ show: false });
{
- const isFocused3 = emittedOnce(w3, 'focus');
- const isShown1 = emittedOnce(w1, 'show');
- const isShown2 = emittedOnce(w2, 'show');
- const isShown3 = emittedOnce(w3, 'show');
+ const isFocused3 = once(w3, 'focus');
+ const isShown1 = once(w1, 'show');
+ const isShown2 = once(w2, 'show');
+ const isShown3 = once(w3, 'show');
w1.show();
w2.show();
w3.show();
@@ -800,9 +806,9 @@ describe('BrowserWindow module', () => {
expect(w3.isFocused()).to.equal(true);
{
- const isClosed1 = emittedOnce(w1, 'closed');
- const isClosed2 = emittedOnce(w2, 'closed');
- const isClosed3 = emittedOnce(w3, 'closed');
+ const isClosed1 = once(w1, 'closed');
+ const isClosed2 = once(w2, 'closed');
+ const isClosed3 = once(w3, 'closed');
w1.destroy();
w2.destroy();
w3.destroy();
@@ -818,8 +824,8 @@ describe('BrowserWindow module', () => {
ifdescribe(process.platform !== 'win32')('BrowserWindow.blur()', () => {
it('removes focus from window', async () => {
{
- const isFocused = emittedOnce(w, 'focus');
- const isShown = emittedOnce(w, 'show');
+ const isFocused = once(w, 'focus');
+ const isShown = once(w, 'show');
w.show();
await isShown;
await isFocused;
@@ -834,10 +840,10 @@ describe('BrowserWindow module', () => {
const w2 = new BrowserWindow({ show: false });
const w3 = new BrowserWindow({ show: false });
{
- const isFocused3 = emittedOnce(w3, 'focus');
- const isShown1 = emittedOnce(w1, 'show');
- const isShown2 = emittedOnce(w2, 'show');
- const isShown3 = emittedOnce(w3, 'show');
+ const isFocused3 = once(w3, 'focus');
+ const isShown1 = once(w1, 'show');
+ const isShown2 = once(w2, 'show');
+ const isShown3 = once(w3, 'show');
w1.show();
w2.show();
w3.show();
@@ -867,9 +873,9 @@ describe('BrowserWindow module', () => {
expect(w3.isFocused()).to.equal(true);
{
- const isClosed1 = emittedOnce(w1, 'closed');
- const isClosed2 = emittedOnce(w2, 'closed');
- const isClosed3 = emittedOnce(w3, 'closed');
+ const isClosed1 = once(w1, 'closed');
+ const isClosed2 = once(w2, 'closed');
+ const isClosed3 = once(w3, 'closed');
w1.destroy();
w2.destroy();
w3.destroy();
@@ -882,9 +888,11 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.getFocusedWindow()', () => {
it('returns the opener window when dev tools window is focused', async () => {
- await emittedOnce(w, 'focus', () => w.show());
+ const p = once(w, 'focus');
+ w.show();
+ await p;
w.webContents.openDevTools({ mode: 'undocked' });
- await emittedOnce(w.webContents, 'devtools-focused');
+ await once(w.webContents, 'devtools-focused');
expect(BrowserWindow.getFocusedWindow()).to.equal(w);
});
});
@@ -892,14 +900,14 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.moveTop()', () => {
it('should not steal focus', async () => {
const posDelta = 50;
- const wShownInactive = emittedOnce(w, 'show');
+ const wShownInactive = once(w, 'show');
w.showInactive();
await wShownInactive;
expect(w.isFocused()).to.equal(false);
const otherWindow = new BrowserWindow({ show: false, title: 'otherWindow' });
- const otherWindowShown = emittedOnce(otherWindow, 'show');
- const otherWindowFocused = emittedOnce(otherWindow, 'focus');
+ const otherWindowShown = once(otherWindow, 'show');
+ const otherWindowFocused = once(otherWindow, 'focus');
otherWindow.show();
await otherWindowShown;
await otherWindowFocused;
@@ -907,14 +915,14 @@ describe('BrowserWindow module', () => {
w.moveTop();
const wPos = w.getPosition();
- const wMoving = emittedOnce(w, 'move');
+ const wMoving = once(w, 'move');
w.setPosition(wPos[0] + posDelta, wPos[1] + posDelta);
await wMoving;
expect(w.isFocused()).to.equal(false);
expect(otherWindow.isFocused()).to.equal(true);
- const wFocused = emittedOnce(w, 'focus');
- const otherWindowBlurred = emittedOnce(otherWindow, 'blur');
+ const wFocused = once(w, 'focus');
+ const otherWindowBlurred = once(otherWindow, 'blur');
w.focus();
await wFocused;
await otherWindowBlurred;
@@ -922,7 +930,7 @@ describe('BrowserWindow module', () => {
otherWindow.moveTop();
const otherWindowPos = otherWindow.getPosition();
- const otherWindowMoving = emittedOnce(otherWindow, 'move');
+ const otherWindowMoving = once(otherWindow, 'move');
otherWindow.setPosition(otherWindowPos[0] + posDelta, otherWindowPos[1] + posDelta);
await otherWindowMoving;
expect(otherWindow.isFocused()).to.equal(false);
@@ -967,7 +975,7 @@ describe('BrowserWindow module', () => {
it('should not throw an exception', async () => {
const w2 = new BrowserWindow({ show: false, title: 'window2' });
- const w2Shown = emittedOnce(w2, 'show');
+ const w2Shown = once(w2, 'show');
w2.show();
await w2Shown;
@@ -982,7 +990,7 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.setFocusable()', () => {
it('can set unfocusable window to focusable', async () => {
const w2 = new BrowserWindow({ focusable: false });
- const w2Focused = emittedOnce(w2, 'focus');
+ const w2Focused = once(w2, 'focus');
w2.setFocusable(true);
w2.focus();
await w2Focused;
@@ -1038,7 +1046,7 @@ describe('BrowserWindow module', () => {
const fullBounds = { x: 440, y: 225, width: 500, height: 400 };
w.setBounds(fullBounds, true);
- await expect(emittedOnce(w, 'resized')).to.eventually.be.fulfilled();
+ await expect(once(w, 'resized')).to.eventually.be.fulfilled();
});
});
});
@@ -1047,7 +1055,7 @@ describe('BrowserWindow module', () => {
it('sets the window size', async () => {
const size = [300, 400];
- const resized = emittedOnce(w, 'resize');
+ const resized = once(w, 'resize');
w.setSize(size[0], size[1]);
await resized;
@@ -1059,7 +1067,7 @@ describe('BrowserWindow module', () => {
const size = [300, 400];
w.setSize(size[0], size[1], true);
- await expect(emittedOnce(w, 'resized')).to.eventually.be.fulfilled();
+ await expect(once(w, 'resized')).to.eventually.be.fulfilled();
});
});
});
@@ -1084,7 +1092,7 @@ describe('BrowserWindow module', () => {
const size = [300, 400];
w.setAspectRatio(1 / 2);
w.setAspectRatio(0);
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
expectBoundsEqual(w.getSize(), size);
@@ -1105,7 +1113,7 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.setPosition(x, y)', () => {
it('sets the window position', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
expect(w.getPosition()).to.deep.equal(pos);
@@ -1143,10 +1151,10 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.setContentBounds(bounds)', () => {
it('sets the content size and position', async () => {
const bounds = { x: 10, y: 10, width: 250, height: 250 };
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setContentBounds(bounds);
await resize;
- await delay();
+ await setTimeout();
expectBoundsEqual(w.getContentBounds(), bounds);
});
it('works for a frameless window', async () => {
@@ -1158,10 +1166,10 @@ describe('BrowserWindow module', () => {
height: 300
});
const bounds = { x: 10, y: 10, width: 250, height: 250 };
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setContentBounds(bounds);
await resize;
- await delay();
+ await setTimeout();
expectBoundsEqual(w.getContentBounds(), bounds);
});
});
@@ -1212,7 +1220,7 @@ describe('BrowserWindow module', () => {
describe('Normal state', () => {
it('checks normal bounds after resize', async () => {
const size = [300, 400];
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
expectBoundsEqual(w.getNormalBounds(), w.getBounds());
@@ -1220,7 +1228,7 @@ describe('BrowserWindow module', () => {
it('checks normal bounds after move', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
expectBoundsEqual(w.getNormalBounds(), w.getBounds());
@@ -1230,7 +1238,7 @@ describe('BrowserWindow module', () => {
ifdescribe(process.platform !== 'linux')('Maximized state', () => {
it('checks normal bounds when maximized', async () => {
const bounds = w.getBounds();
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
@@ -1239,12 +1247,12 @@ describe('BrowserWindow module', () => {
it('updates normal bounds after resize and maximize', async () => {
const size = [300, 400];
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.maximize();
await maximize;
@@ -1254,19 +1262,19 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and maximize', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.maximize();
await maximize;
@@ -1276,7 +1284,7 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
@@ -1286,7 +1294,7 @@ describe('BrowserWindow module', () => {
w.once('maximize', () => {
w.unmaximize();
});
- const unmaximize = emittedOnce(w, 'unmaximize');
+ const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
await unmaximize;
@@ -1307,7 +1315,7 @@ describe('BrowserWindow module', () => {
w.once('maximize', () => {
w.unmaximize();
});
- const unmaximize = emittedOnce(w, 'unmaximize');
+ const unmaximize = once(w, 'unmaximize');
w.show();
w.maximize();
await unmaximize;
@@ -1323,12 +1331,12 @@ describe('BrowserWindow module', () => {
transparent: true
});
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
expect(w.isMaximized()).to.equal(true);
- const unmaximize = emittedOnce(w, 'unmaximize');
+ const unmaximize = once(w, 'unmaximize');
w.unmaximize();
await unmaximize;
expect(w.isMaximized()).to.equal(false);
@@ -1343,7 +1351,7 @@ describe('BrowserWindow module', () => {
w.setAspectRatio(16 / 11);
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
@@ -1357,7 +1365,7 @@ describe('BrowserWindow module', () => {
ifdescribe(process.platform !== 'linux')('Minimized state', () => {
it('checks normal bounds when minimized', async () => {
const bounds = w.getBounds();
- const minimize = emittedOnce(w, 'minimize');
+ const minimize = once(w, 'minimize');
w.show();
w.minimize();
await minimize;
@@ -1366,12 +1374,12 @@ describe('BrowserWindow module', () => {
it('updates normal bounds after move and minimize', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
- const minimize = emittedOnce(w, 'minimize');
+ const minimize = once(w, 'minimize');
w.minimize();
await minimize;
@@ -1383,12 +1391,12 @@ describe('BrowserWindow module', () => {
it('updates normal bounds after resize and minimize', async () => {
const size = [300, 400];
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
- const minimize = emittedOnce(w, 'minimize');
+ const minimize = once(w, 'minimize');
w.minimize();
await minimize;
@@ -1403,7 +1411,7 @@ describe('BrowserWindow module', () => {
w.once('minimize', () => {
w.restore();
});
- const restore = emittedOnce(w, 'restore');
+ const restore = once(w, 'restore');
w.show();
w.minimize();
await restore;
@@ -1424,7 +1432,7 @@ describe('BrowserWindow module', () => {
w.once('minimize', () => {
w.restore();
});
- const restore = emittedOnce(w, 'restore');
+ const restore = once(w, 'restore');
w.show();
w.minimize();
await restore;
@@ -1453,7 +1461,7 @@ describe('BrowserWindow module', () => {
it('checks normal bounds when fullscreen\'ed', async () => {
const bounds = w.getBounds();
- const enterFullScreen = emittedOnce(w, 'enter-full-screen');
+ const enterFullScreen = once(w, 'enter-full-screen');
w.show();
w.fullScreen = true;
await enterFullScreen;
@@ -1462,12 +1470,12 @@ describe('BrowserWindow module', () => {
it('updates normal bounds after resize and fullscreen', async () => {
const size = [300, 400];
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
- const fsc = emittedOnce(w, 'enter-full-screen');
+ const fsc = once(w, 'enter-full-screen');
w.fullScreen = true;
await fsc;
@@ -1477,19 +1485,19 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and fullscreen', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
- const fsc = emittedOnce(w, 'enter-full-screen');
+ const fsc = once(w, 'enter-full-screen');
w.fullScreen = true;
await fsc;
@@ -1499,7 +1507,7 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
@@ -1509,7 +1517,7 @@ describe('BrowserWindow module', () => {
w.once('enter-full-screen', () => {
w.fullScreen = false;
});
- const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
+ const leaveFullScreen = once(w, 'leave-full-screen');
w.show();
w.fullScreen = true;
await leaveFullScreen;
@@ -1534,7 +1542,7 @@ describe('BrowserWindow module', () => {
const bounds = w.getBounds();
w.show();
- const enterFullScreen = emittedOnce(w, 'enter-full-screen');
+ const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
@@ -1543,12 +1551,12 @@ describe('BrowserWindow module', () => {
it('updates normal bounds after resize and fullscreen', async () => {
const size = [300, 400];
- const resize = emittedOnce(w, 'resize');
+ const resize = once(w, 'resize');
w.setSize(size[0], size[1]);
await resize;
const original = w.getBounds();
- const fsc = emittedOnce(w, 'enter-full-screen');
+ const fsc = once(w, 'enter-full-screen');
w.setFullScreen(true);
await fsc;
@@ -1558,19 +1566,19 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
it('updates normal bounds after move and fullscreen', async () => {
const pos = [10, 10];
- const move = emittedOnce(w, 'move');
+ const move = once(w, 'move');
w.setPosition(pos[0], pos[1]);
await move;
const original = w.getBounds();
- const fsc = emittedOnce(w, 'enter-full-screen');
+ const fsc = once(w, 'enter-full-screen');
w.setFullScreen(true);
await fsc;
@@ -1580,7 +1588,7 @@ describe('BrowserWindow module', () => {
expect(normal).to.deep.equal(original);
expect(normal).to.not.deep.equal(bounds);
- const close = emittedOnce(w, 'close');
+ const close = once(w, 'close');
w.close();
await close;
});
@@ -1589,11 +1597,11 @@ describe('BrowserWindow module', () => {
const bounds = w.getBounds();
w.show();
- const enterFullScreen = emittedOnce(w, 'enter-full-screen');
+ const enterFullScreen = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFullScreen;
- const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
+ const leaveFullScreen = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFullScreen;
@@ -1737,7 +1745,7 @@ describe('BrowserWindow module', () => {
w.loadFile(path.join(fixtures, 'pages', 'visibilitychange.html'));
{
- const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong');
+ const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('visible');
expect(hidden).to.be.false('hidden');
}
@@ -1745,7 +1753,7 @@ describe('BrowserWindow module', () => {
w.hide();
{
- const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong');
+ const [, visibilityState, hidden] = await once(ipcMain, 'pong');
expect(visibilityState).to.equal('hidden');
expect(hidden).to.be.true('hidden');
}
@@ -1759,7 +1767,7 @@ describe('BrowserWindow module', () => {
it('resolves after the window is hidden', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixtures, 'pages', 'a.html'));
- await emittedOnce(w, 'ready-to-show');
+ await once(w, 'ready-to-show');
w.show();
const visibleImage = await w.capturePage();
@@ -1776,7 +1784,7 @@ describe('BrowserWindow module', () => {
const w = new BrowserWindow({ show: false });
w.webContents.setBackgroundThrottling(false);
w.loadFile(path.join(fixtures, 'pages', 'a.html'));
- await emittedOnce(w, 'ready-to-show');
+ await once(w, 'ready-to-show');
const image = await w.capturePage();
expect(image.isEmpty()).to.equal(false);
@@ -1785,7 +1793,7 @@ describe('BrowserWindow module', () => {
it('preserves transparency', async () => {
const w = new BrowserWindow({ show: false, transparent: true });
w.loadFile(path.join(fixtures, 'pages', 'theme-color.html'));
- await emittedOnce(w, 'ready-to-show');
+ await once(w, 'ready-to-show');
w.show();
const image = await w.capturePage();
@@ -1866,7 +1874,7 @@ describe('BrowserWindow module', () => {
});
it('causes the right value to be emitted on `always-on-top-changed`', async () => {
- const alwaysOnTopChanged = emittedOnce(w, 'always-on-top-changed');
+ const alwaysOnTopChanged = once(w, 'always-on-top-changed');
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true);
const [, alwaysOnTop] = await alwaysOnTopChanged;
@@ -1928,7 +1936,7 @@ describe('BrowserWindow module', () => {
it('parses ', async () => {
w = new BrowserWindow({ show: true });
- const p = emittedOnce(w.webContents.session, 'preconnect');
+ const p = once(w.webContents.session, 'preconnect');
w.loadURL(url + '/link');
const [, preconnectUrl, allowCredentials] = await p;
expect(preconnectUrl).to.equal('http://example.com/');
@@ -2016,11 +2024,11 @@ describe('BrowserWindow module', () => {
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
- const enterFS = emittedOnce(w, 'enter-full-screen');
+ const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
- const leaveFS = emittedOnce(w, 'leave-full-screen');
+ const leaveFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFS;
@@ -2034,11 +2042,11 @@ describe('BrowserWindow module', () => {
w.setWindowButtonVisibility(false);
expect(w._getWindowButtonVisibility()).to.equal(false);
- const enterFS = emittedOnce(w, 'enter-full-screen');
+ const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
- const leaveFS = emittedOnce(w, 'leave-full-screen');
+ const leaveFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFS;
@@ -2206,7 +2214,7 @@ describe('BrowserWindow module', () => {
appProcess = childProcess.spawn(process.execPath, [appPath]);
- const [code] = await emittedOnce(appProcess, 'exit');
+ const [code] = await once(appProcess, 'exit');
expect(code).to.equal(0);
});
});
@@ -2247,8 +2255,8 @@ describe('BrowserWindow module', () => {
// NOTE(nornagon): Waiting for 'did-attach-webview' is a workaround for
// https://github.com/electron/electron/issues/25413, and is not integral
// to the test.
- const p = emittedOnce(w.webContents, 'did-attach-webview');
- const [, webviewContents] = await emittedOnce(app, 'web-contents-created');
+ const p = once(w.webContents, 'did-attach-webview');
+ const [, webviewContents] = await once(app, 'web-contents-created');
expect(BrowserWindow.fromWebContents(webviewContents)!.id).to.equal(w.id);
await p;
});
@@ -2257,7 +2265,7 @@ describe('BrowserWindow module', () => {
const w = new BrowserWindow({ show: false });
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.open(""); null');
- const [win, winFromWebContents] = await new Promise((resolve) => {
+ const [win, winFromWebContents] = await new Promise((resolve) => {
app.once('browser-window-created', (e, win) => {
resolve([win, BrowserWindow.fromWebContents(win.webContents)]);
});
@@ -2419,7 +2427,7 @@ describe('BrowserWindow module', () => {
if (process.platform === 'darwin') {
await w.loadFile(overlayHTML);
} else {
- const overlayReady = emittedOnce(ipcMain, 'geometrychange');
+ const overlayReady = once(ipcMain, 'geometrychange');
await w.loadFile(overlayHTML);
await overlayReady;
}
@@ -2436,7 +2444,7 @@ describe('BrowserWindow module', () => {
expect(overlayRect.height).to.be.greaterThan(0);
const cssOverlayRect = await w.webContents.executeJavaScript('getCssOverlayProperties();');
expect(cssOverlayRect).to.deep.equal(overlayRect);
- const geometryChange = emittedOnce(ipcMain, 'geometrychange');
+ const geometryChange = once(ipcMain, 'geometrychange');
w.setBounds({ width: 800 });
const [, newOverlayRect] = await geometryChange;
expect(newOverlayRect.width).to.equal(overlayRect.width + 400);
@@ -2527,7 +2535,7 @@ describe('BrowserWindow module', () => {
if (process.platform === 'darwin') {
await w.loadFile(overlayHTML);
} else {
- const overlayReady = emittedOnce(ipcMain, 'geometrychange');
+ const overlayReady = once(ipcMain, 'geometrychange');
await w.loadFile(overlayHTML);
await overlayReady;
}
@@ -2536,7 +2544,7 @@ describe('BrowserWindow module', () => {
const overlayRectPreMax = await w.webContents.executeJavaScript('getJSOverlayProperties()');
if (!w.isMaximized()) {
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
@@ -2596,7 +2604,7 @@ describe('BrowserWindow module', () => {
it('correctly updates the height of the overlay', async () => {
const testOverlay = async (w: BrowserWindow, size: Number, firstRun: boolean) => {
const overlayHTML = path.join(__dirname, 'fixtures', 'pages', 'overlay.html');
- const overlayReady = emittedOnce(ipcMain, 'geometrychange');
+ const overlayReady = once(ipcMain, 'geometrychange');
await w.loadFile(overlayHTML);
if (firstRun) {
await overlayReady;
@@ -2607,7 +2615,7 @@ describe('BrowserWindow module', () => {
const { height: preMaxHeight } = await w.webContents.executeJavaScript('getJSOverlayProperties()');
if (!w.isMaximized()) {
- const maximize = emittedOnce(w, 'maximize');
+ const maximize = once(w, 'maximize');
w.show();
w.maximize();
await maximize;
@@ -2738,7 +2746,7 @@ describe('BrowserWindow module', () => {
show: false
});
w.loadFile(path.join(fixtures, 'api', 'no-leak.html'));
- const [, result] = await emittedOnce(ipcMain, 'leak-result');
+ const [, result] = await once(ipcMain, 'leak-result');
expect(result).to.have.property('require', 'undefined');
expect(result).to.have.property('exports', 'undefined');
expect(result).to.have.property('windowExports', 'undefined');
@@ -2776,7 +2784,7 @@ describe('BrowserWindow module', () => {
show: false
});
w.loadFile(path.join(fixtures, 'api', 'globals.html'));
- const [, notIsolated] = await emittedOnce(ipcMain, 'leak-result');
+ const [, notIsolated] = await once(ipcMain, 'leak-result');
expect(notIsolated).to.have.property('globals');
w.destroy();
@@ -2789,7 +2797,7 @@ describe('BrowserWindow module', () => {
show: false
});
w.loadFile(path.join(fixtures, 'api', 'globals.html'));
- const [, isolated] = await emittedOnce(ipcMain, 'leak-result');
+ const [, isolated] = await once(ipcMain, 'leak-result');
expect(isolated).to.have.property('globals');
const notIsolatedGlobals = new Set(notIsolated.globals);
for (const isolatedGlobal of isolated.globals) {
@@ -2809,7 +2817,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
- const [, test] = await emittedOnce(ipcMain, 'answer');
+ const [, test] = await once(ipcMain, 'answer');
expect(test).to.eql('preload');
});
it('has synchronous access to all eventual window APIs', async () => {
@@ -2823,7 +2831,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
- const [, test] = await emittedOnce(ipcMain, 'answer');
+ const [, test] = await once(ipcMain, 'answer');
expect(test).to.be.an('object');
expect(test.atPreload).to.be.an('array');
expect(test.atLoad).to.be.an('array');
@@ -2863,7 +2871,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadURL('about:blank');
- const [, preload1, preload2, preload3] = await emittedOnce(ipcMain, 'vars');
+ const [, preload1, preload2, preload3] = await once(ipcMain, 'vars');
expect(preload1).to.equal('preload-1');
expect(preload2).to.equal('preload-1-2');
expect(preload3).to.be.undefined('preload 3');
@@ -2887,7 +2895,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
- const [, argv] = await emittedOnce(ipcMain, 'answer');
+ const [, argv] = await once(ipcMain, 'answer');
expect(argv).to.include('--my-magic-arg');
});
@@ -2902,7 +2910,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
- const [, argv] = await emittedOnce(ipcMain, 'answer');
+ const [, argv] = await once(ipcMain, 'answer');
expect(argv).to.include('--my-magic-arg=foo');
});
});
@@ -2918,7 +2926,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'blank.html'));
- const [, typeofProcess, typeofBuffer] = await emittedOnce(ipcMain, 'answer');
+ const [, typeofProcess, typeofBuffer] = await once(ipcMain, 'answer');
expect(typeofProcess).to.equal('undefined');
expect(typeofBuffer).to.equal('undefined');
});
@@ -2957,7 +2965,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
- const [, test] = await emittedOnce(ipcMain, 'answer');
+ const [, test] = await once(ipcMain, 'answer');
expect(test).to.equal('preload');
});
@@ -2972,7 +2980,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
- const [, test] = await emittedOnce(ipcMain, 'answer');
+ const [, test] = await once(ipcMain, 'answer');
expect(test).to.equal('preload');
});
@@ -2985,7 +2993,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadURL('about:blank');
- await emittedOnce(ipcMain, 'process-loaded');
+ await once(ipcMain, 'process-loaded');
});
it('exposes "exit" event to preload script', async () => {
@@ -3000,7 +3008,7 @@ describe('BrowserWindow module', () => {
const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?exit-event');
const pageUrl = 'file://' + htmlPath;
w.loadURL(pageUrl);
- const [, url] = await emittedOnce(ipcMain, 'answer');
+ const [, url] = await once(ipcMain, 'answer');
const expectedUrl = process.platform === 'win32'
? 'file:///' + htmlPath.replace(/\\/g, '/')
: pageUrl;
@@ -3016,7 +3024,7 @@ describe('BrowserWindow module', () => {
}
});
w.loadURL('about:blank');
- const [, rendererEventEmitterProperties] = await emittedOnce(ipcMain, 'answer');
+ const [, rendererEventEmitterProperties] = await once(ipcMain, 'answer');
const { EventEmitter } = require('events');
const emitter = new EventEmitter();
const browserEventEmitterProperties = [];
@@ -3048,9 +3056,9 @@ describe('BrowserWindow module', () => {
const htmlPath = path.join(__dirname, 'fixtures', 'api', 'sandbox.html?window-open');
const pageUrl = 'file://' + htmlPath;
- const answer = emittedOnce(ipcMain, 'answer');
+ const answer = once(ipcMain, 'answer');
w.loadURL(pageUrl);
- const [, { url, frameName, options }] = await emittedOnce(w.webContents, 'did-create-window');
+ const [, { url, frameName, options }] = await once(w.webContents, 'did-create-window');
const expectedUrl = process.platform === 'win32'
? 'file:///' + htmlPath.replace(/\\/g, '/')
: pageUrl;
@@ -3087,7 +3095,7 @@ describe('BrowserWindow module', () => {
);
// Wait for a message from the main window saying that it's ready.
- await emittedOnce(ipcMain, 'opener-loaded');
+ await once(ipcMain, 'opener-loaded');
// Ask the opener to open a popup with window.opener.
const expectedPopupUrl = `${serverUrl}/cross-site`; // Set in "sandbox.html".
@@ -3096,22 +3104,22 @@ describe('BrowserWindow module', () => {
// The page is going to open a popup that it won't be able to close.
// We have to close it from here later.
- const [, popupWindow] = await emittedOnce(app, 'browser-window-created');
+ const [, popupWindow] = await once(app, 'browser-window-created');
// Ask the popup window for details.
- const detailsAnswer = emittedOnce(ipcMain, 'child-loaded');
+ const detailsAnswer = once(ipcMain, 'child-loaded');
popupWindow.webContents.send('provide-details');
const [, openerIsNull, , locationHref] = await detailsAnswer;
expect(openerIsNull).to.be.false('window.opener is null');
expect(locationHref).to.equal(expectedPopupUrl);
// Ask the page to access the popup.
- const touchPopupResult = emittedOnce(ipcMain, 'answer');
+ const touchPopupResult = once(ipcMain, 'answer');
w.webContents.send('touch-the-popup');
const [, popupAccessMessage] = await touchPopupResult;
// Ask the popup to access the opener.
- const touchOpenerResult = emittedOnce(ipcMain, 'answer');
+ const touchOpenerResult = once(ipcMain, 'answer');
popupWindow.webContents.send('touch-the-opener');
const [, openerAccessMessage] = await touchOpenerResult;
@@ -3138,7 +3146,7 @@ describe('BrowserWindow module', () => {
const preloadPath = path.join(mainFixtures, 'api', 'new-window-preload.js');
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath } } }));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
- const [, { argv }] = await emittedOnce(ipcMain, 'answer');
+ const [, { argv }] = await once(ipcMain, 'answer');
expect(argv).to.include('--enable-sandbox');
});
@@ -3154,8 +3162,8 @@ describe('BrowserWindow module', () => {
w.webContents.setWindowOpenHandler(() => ({ action: 'allow', overrideBrowserWindowOptions: { webPreferences: { preload: preloadPath, contextIsolation: false } } }));
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
const [[, childWebContents]] = await Promise.all([
- emittedOnce(app, 'web-contents-created'),
- emittedOnce(ipcMain, 'answer')
+ once(app, 'web-contents-created'),
+ once(ipcMain, 'answer')
]);
const webPreferences = childWebContents.getLastWebPreferences();
expect(webPreferences.contextIsolation).to.equal(false);
@@ -3191,7 +3199,7 @@ describe('BrowserWindow module', () => {
const done = Promise.all([
'parent-answer',
'child-answer'
- ].map(name => emittedOnce(ipcMain, name)));
+ ].map(name => once(ipcMain, name)));
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'verify-ipc-sender' });
await done;
});
@@ -3202,7 +3210,7 @@ describe('BrowserWindow module', () => {
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
});
it('works for window events', async () => {
- const pageTitleUpdated = emittedOnce(w, 'page-title-updated');
+ const pageTitleUpdated = once(w, 'page-title-updated');
w.loadURL('data:text/html,');
await pageTitleUpdated;
});
@@ -3212,7 +3220,7 @@ describe('BrowserWindow module', () => {
'did-navigate',
'did-fail-load',
'did-stop-loading'
- ].map(name => emittedOnce(w.webContents, name)));
+ ].map(name => once(w.webContents, name)));
w.loadURL('data:text/html,');
await done;
});
@@ -3227,7 +3235,7 @@ describe('BrowserWindow module', () => {
'did-stop-loading',
'did-frame-finish-load',
'dom-ready'
- ].map(name => emittedOnce(w.webContents, name)));
+ ].map(name => once(w.webContents, name)));
w.loadFile(path.join(__dirname, 'fixtures', 'api', 'sandbox.html'), { search: 'webcontents-events' });
await done;
});
@@ -3247,7 +3255,7 @@ describe('BrowserWindow module', () => {
});
process.env.sandboxmain = 'foo';
w.loadFile(path.join(fixtures, 'api', 'preload.html'));
- const [, test] = await emittedOnce(ipcMain, 'answer');
+ const [, test] = await once(ipcMain, 'answer');
expect(test.hasCrash).to.be.true('has crash');
expect(test.hasHang).to.be.true('has hang');
expect(test.heapStatistics).to.be.an('object');
@@ -3287,8 +3295,8 @@ describe('BrowserWindow module', () => {
contextIsolation: false
}
});
- const didAttachWebview = emittedOnce(w.webContents, 'did-attach-webview');
- const webviewDomReady = emittedOnce(ipcMain, 'webview-dom-ready');
+ const didAttachWebview = once(w.webContents, 'did-attach-webview');
+ const webviewDomReady = once(ipcMain, 'webview-dom-ready');
w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html'));
const [, webContents] = await didAttachWebview;
@@ -3313,25 +3321,25 @@ describe('BrowserWindow module', () => {
});
it('opens window of about:blank with cross-scripting enabled', async () => {
- const answer = emittedOnce(ipcMain, 'answer');
+ const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-blank.html'));
const [, content] = await answer;
expect(content).to.equal('Hello');
});
it('opens window of same domain with cross-scripting enabled', async () => {
- const answer = emittedOnce(ipcMain, 'answer');
+ const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-file.html'));
const [, content] = await answer;
expect(content).to.equal('Hello');
});
it('blocks accessing cross-origin frames', async () => {
- const answer = emittedOnce(ipcMain, 'answer');
+ const answer = once(ipcMain, 'answer');
w.loadFile(path.join(fixtures, 'api', 'native-window-open-cross-origin.html'));
const [, content] = await answer;
expect(content).to.equal('Blocked a frame with origin "file://" from accessing a cross-origin frame.');
});
it('opens window from