diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts
index 4a136bf99ff5..05e3822c32d9 100644
--- a/spec-main/api-app-spec.ts
+++ b/spec-main/api-app-spec.ts
@@ -209,21 +209,17 @@ describe('app module', () => {
});
describe('app.requestSingleInstanceLock', () => {
- it('prevents the second launch of app', function (done) {
+ it('prevents the second launch of app', async function () {
this.timeout(120000);
const appPath = path.join(fixturesPath, 'api', 'singleton');
const first = cp.spawn(process.execPath, [appPath]);
- first.once('exit', code => {
- expect(code).to.equal(0);
- });
+ await emittedOnce(first.stdout, 'data');
// Start second app when received output.
- first.stdout.once('data', () => {
- const second = cp.spawn(process.execPath, [appPath]);
- second.once('exit', code => {
- expect(code).to.equal(1);
- done();
- });
- });
+ const second = cp.spawn(process.execPath, [appPath]);
+ const [code2] = await emittedOnce(second, 'exit');
+ expect(code2).to.equal(1);
+ const [code1] = await emittedOnce(first, 'exit');
+ expect(code1).to.equal(0);
});
it('passes arguments to the second-instance event', async () => {
@@ -1003,34 +999,28 @@ describe('app module', () => {
}
});
- it('does not launch for argument following a URL', done => {
+ it('does not launch for argument following a URL', async () => {
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']);
- first.once('exit', code => {
- expect(code).to.not.equal(123);
- done();
- });
+ const [code] = await emittedOnce(first, 'exit');
+ expect(code).to.not.equal(123);
});
- it('launches successfully for argument following a file path', done => {
+ it('launches successfully for argument following a file path', async () => {
const appPath = path.join(fixturesPath, 'api', 'quit-app');
// App should exit with code 123.
const first = cp.spawn(process.execPath, [appPath, 'e:\\abc', 'abc']);
- first.once('exit', code => {
- expect(code).to.equal(123);
- done();
- });
+ const [code] = await emittedOnce(first, 'exit');
+ expect(code).to.equal(123);
});
- it('launches successfully for multiple URIs following --', done => {
+ it('launches successfully for multiple URIs following --', async () => {
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']);
- first.once('exit', code => {
- expect(code).to.equal(123);
- done();
- });
+ const [code] = await emittedOnce(first, 'exit');
+ expect(code).to.equal(123);
});
});
diff --git a/spec-main/api-auto-updater-spec.ts b/spec-main/api-auto-updater-spec.ts
index 4d1e19fcbbbe..1839303b6fcf 100644
--- a/spec-main/api-auto-updater-spec.ts
+++ b/spec-main/api-auto-updater-spec.ts
@@ -1,16 +1,16 @@
import { autoUpdater } from 'electron/main';
import { expect } from 'chai';
import { ifit, ifdescribe } from './spec-helpers';
+import { emittedOnce } from './events-helpers';
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', function (done) {
- autoUpdater.once('error', function (error) {
- expect(error.message).to.equal('Update URL is not set');
- done();
- });
+ ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', async function () {
+ const errorEvent = emittedOnce(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
autoUpdater.checkForUpdates();
+ const [error] = await errorEvent;
+ expect(error.message).to.equal('Update URL is not set');
});
});
@@ -19,11 +19,10 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
expect(autoUpdater.getFeedURL()).to.equal('');
});
- ifit(process.platform === 'win32')('correctly fetches the previously set FeedURL', function (done) {
+ ifit(process.platform === 'win32')('correctly fetches the previously set FeedURL', function () {
const updateURL = 'https://fake-update.electron.io';
autoUpdater.setFeedURL({ url: updateURL });
expect(autoUpdater.getFeedURL()).to.equal(updateURL);
- done();
});
});
@@ -56,12 +55,11 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
});
ifdescribe(process.platform === 'darwin')('on Mac', function () {
- it('emits an error when the application is unsigned', done => {
- autoUpdater.once('error', function (error) {
- expect(error.message).equal('Could not get code signature for running application');
- done();
- });
+ it('emits an error when the application is unsigned', async () => {
+ const errorEvent = emittedOnce(autoUpdater, 'error');
autoUpdater.setFeedURL({ url: '' });
+ const [error] = await errorEvent;
+ expect(error.message).equal('Could not get code signature for running application');
});
it('does not throw if default is the serverType', () => {
@@ -81,12 +79,11 @@ ifdescribe(!process.mas)('autoUpdater module', function () {
});
describe('quitAndInstall', () => {
- ifit(process.platform === 'win32')('emits an error on Windows when no update is available', function (done) {
- autoUpdater.once('error', function (error) {
- expect(error.message).to.equal('No update available, can\'t quit and install');
- done();
- });
+ ifit(process.platform === 'win32')('emits an error on Windows when no update is available', async function () {
+ const errorEvent = emittedOnce(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-main/api-browser-view-spec.ts b/spec-main/api-browser-view-spec.ts
index 19e0ab3212f1..2c17badce875 100644
--- a/spec-main/api-browser-view-spec.ts
+++ b/spec-main/api-browser-view-spec.ts
@@ -233,17 +233,16 @@ describe('BrowserView module', () => {
});
describe('window.open()', () => {
- it('works in BrowserView', (done) => {
+ it('works in BrowserView', async () => {
view = new BrowserView();
w.setBrowserView(view);
- view.webContents.once('new-window', (e, url, frameName, disposition, options, additionalFeatures) => {
- e.preventDefault();
- expect(url).to.equal('http://host/');
- expect(frameName).to.equal('host');
- expect(additionalFeatures[0]).to.equal('this-is-not-a-standard-feature');
- done();
- });
+ const newWindow = emittedOnce(view.webContents, 'new-window');
+ view.webContents.once('new-window', event => event.preventDefault());
view.webContents.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
+ const [, url, frameName,,, additionalFeatures] = await newWindow;
+ expect(url).to.equal('http://host/');
+ expect(frameName).to.equal('host');
+ expect(additionalFeatures[0]).to.equal('this-is-not-a-standard-feature');
});
});
});
diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts
index 78aa8ded1ba3..57756c70cd2a 100644
--- a/spec-main/api-browser-window-spec.ts
+++ b/spec-main/api-browser-window-spec.ts
@@ -68,21 +68,18 @@ describe('BrowserWindow module', () => {
const v8Util = process._linkedBinding('electron_common_v8_util');
afterEach(closeAllWindows);
- it('window does not get garbage collected when opened', (done) => {
+ it('window does not get garbage collected when opened', async () => {
const w = new BrowserWindow({ show: false });
// Keep a weak reference to the window.
// eslint-disable-next-line no-undef
const wr = new (globalThis as any).WeakRef(w);
- 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();
+ // 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();
- setTimeout(() => {
- expect(wr.deref()).to.not.be.undefined();
- done();
- });
- });
+ await delay();
+ expect(wr.deref()).to.not.be.undefined();
});
});
@@ -324,30 +321,27 @@ describe('BrowserWindow module', () => {
});
// 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', (done) => {
- w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => {
- expect(code).to.equal(-6);
- expect(desc).to.equal('ERR_FILE_NOT_FOUND');
- expect(isMainFrame).to.equal(true);
- done();
- });
+ it.skip('should emit did-fail-load event for files that do not exist', async () => {
+ const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
w.loadURL('file://a.txt');
+ const [, code, desc,, isMainFrame] = await didFailLoad;
+ expect(code).to.equal(-6);
+ expect(desc).to.equal('ERR_FILE_NOT_FOUND');
+ expect(isMainFrame).to.equal(true);
});
- it('should emit did-fail-load event for invalid URL', (done) => {
- w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => {
- expect(desc).to.equal('ERR_INVALID_URL');
- expect(code).to.equal(-300);
- expect(isMainFrame).to.equal(true);
- done();
- });
+ it('should emit did-fail-load event for invalid URL', async () => {
+ const didFailLoad = emittedOnce(w.webContents, 'did-fail-load');
w.loadURL('http://example:port');
+ const [, code, desc,, isMainFrame] = await didFailLoad;
+ expect(desc).to.equal('ERR_INVALID_URL');
+ expect(code).to.equal(-300);
+ expect(isMainFrame).to.equal(true);
});
- it('should set `mainFrame = false` on did-fail-load events in iframes', (done) => {
- w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => {
- expect(isMainFrame).to.equal(false);
- done();
- });
+ it('should set `mainFrame = false` on did-fail-load events in iframes', async () => {
+ const didFailLoad = emittedOnce(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);
});
it('does not crash in did-fail-provisional-load handler', (done) => {
w.webContents.once('did-fail-provisional-load', () => {
@@ -356,15 +350,14 @@ describe('BrowserWindow module', () => {
});
w.loadURL('http://127.0.0.1:11111');
});
- it('should emit did-fail-load event for URL exceeding character limit', (done) => {
- w.webContents.on('did-fail-load', (event, code, desc, url, isMainFrame) => {
- expect(desc).to.equal('ERR_INVALID_URL');
- expect(code).to.equal(-300);
- expect(isMainFrame).to.equal(true);
- done();
- });
+ 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');
w.loadURL(`data:image/png;base64,${data}`);
+ const [, code, desc,, isMainFrame] = await didFailLoad;
+ expect(desc).to.equal('ERR_INVALID_URL');
+ expect(code).to.equal(-300);
+ expect(isMainFrame).to.equal(true);
});
it('should return a promise', () => {
@@ -433,12 +426,11 @@ describe('BrowserWindow module', () => {
});
});
- it('should support support base url for data urls', (done) => {
- ipcMain.once('answer', (event, test) => {
- expect(test).to.equal('test');
- done();
- });
+ it('should support support base url for data urls', async () => {
+ const answer = emittedOnce(ipcMain, 'answer');
w.loadURL('data:text/html,', { baseURLForDataURL: `other://${path.join(fixtures, 'api')}${path.sep}` });
+ const [, test] = await answer;
+ expect(test).to.equal('test');
});
});
@@ -485,8 +477,12 @@ describe('BrowserWindow module', () => {
w.webContents.on('did-stop-loading', () => {
if (willNavigate) {
// i.e. it shouldn't have had '?navigated' appended to it.
- expect(w.webContents.getURL().endsWith('will-navigate.html')).to.be.true();
- done();
+ try {
+ expect(w.webContents.getURL().endsWith('will-navigate.html')).to.be.true();
+ done();
+ } catch (e) {
+ done(e);
+ }
}
});
w.loadFile(path.join(fixtures, 'pages', 'will-navigate.html'));
@@ -550,28 +546,26 @@ describe('BrowserWindow module', () => {
w.loadURL(`${url}/302`);
});
- it('is emitted after will-navigate on redirects', (done) => {
+ it('is emitted after will-navigate on redirects', async () => {
let navigateCalled = false;
w.webContents.on('will-navigate', () => {
navigateCalled = true;
});
- w.webContents.on('will-redirect', () => {
- expect(navigateCalled).to.equal(true, 'should have called will-navigate first');
- done();
- });
+ const willRedirect = emittedOnce(w.webContents, 'will-redirect');
w.loadURL(`${url}/navigate-302`);
+ await willRedirect;
+ expect(navigateCalled).to.equal(true, 'should have called will-navigate first');
});
- it('is emitted before did-stop-loading on redirects', (done) => {
+ it('is emitted before did-stop-loading on redirects', async () => {
let stopCalled = false;
w.webContents.on('did-stop-loading', () => {
stopCalled = true;
});
- w.webContents.on('will-redirect', () => {
- expect(stopCalled).to.equal(false, 'should not have called did-stop-loading first');
- done();
- });
+ const willRedirect = emittedOnce(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', (done) => {
@@ -590,14 +584,22 @@ describe('BrowserWindow module', () => {
expect(u).to.equal(`${url}/302`);
});
w.webContents.on('did-stop-loading', () => {
- expect(w.webContents.getURL()).to.equal(
- `${url}/navigate-302`,
- 'url should not have changed after navigation event'
- );
- done();
+ try {
+ expect(w.webContents.getURL()).to.equal(
+ `${url}/navigate-302`,
+ 'url should not have changed after navigation event'
+ );
+ done();
+ } catch (e) {
+ done(e);
+ }
});
w.webContents.on('will-redirect', (e, u) => {
- expect(u).to.equal(`${url}/200`);
+ try {
+ expect(u).to.equal(`${url}/200`);
+ } catch (e) {
+ done(e);
+ }
});
w.loadURL(`${url}/navigate-302`);
});
@@ -624,12 +626,11 @@ describe('BrowserWindow module', () => {
w.show();
expect(w.isVisible()).to.equal(true);
});
- it('emits when window is shown', (done) => {
- w.once('show', () => {
- expect(w.isVisible()).to.equal(true);
- done();
- });
+ it('emits when window is shown', async () => {
+ const show = emittedOnce(w, 'show');
w.show();
+ await show;
+ expect(w.isVisible()).to.equal(true);
});
});
@@ -845,27 +846,24 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.setAspectRatio(ratio)', () => {
- it('resets the behaviour when passing in 0', (done) => {
+ it('resets the behaviour when passing in 0', async () => {
const size = [300, 400];
w.setAspectRatio(1 / 2);
w.setAspectRatio(0);
- w.once('resize', () => {
- expectBoundsEqual(w.getSize(), size);
- done();
- });
+ const resize = emittedOnce(w, 'resize');
w.setSize(size[0], size[1]);
+ await resize;
+ expectBoundsEqual(w.getSize(), size);
});
});
describe('BrowserWindow.setPosition(x, y)', () => {
- it('sets the window position', (done) => {
+ it('sets the window position', async () => {
const pos = [10, 10];
- w.once('move', () => {
- const newPos = w.getPosition();
- expect(newPos).to.deep.equal(pos);
- done();
- });
+ const move = emittedOnce(w, 'move');
w.setPosition(pos[0], pos[1]);
+ await move;
+ expect(w.getPosition()).to.deep.equal(pos);
});
});
@@ -898,17 +896,15 @@ describe('BrowserWindow module', () => {
});
describe('BrowserWindow.setContentBounds(bounds)', () => {
- it('sets the content size and position', (done) => {
+ it('sets the content size and position', async () => {
const bounds = { x: 10, y: 10, width: 250, height: 250 };
- w.once('resize', () => {
- setTimeout(() => {
- expectBoundsEqual(w.getContentBounds(), bounds);
- done();
- });
- });
+ const resize = emittedOnce(w, 'resize');
w.setContentBounds(bounds);
+ await resize;
+ await delay();
+ expectBoundsEqual(w.getContentBounds(), bounds);
});
- it('works for a frameless window', (done) => {
+ it('works for a frameless window', async () => {
w.destroy();
w = new BrowserWindow({
show: false,
@@ -917,13 +913,11 @@ describe('BrowserWindow module', () => {
height: 300
});
const bounds = { x: 10, y: 10, width: 250, height: 250 };
- w.once('resize', () => {
- setTimeout(() => {
- expect(w.getContentBounds()).to.deep.equal(bounds);
- done();
- });
- });
+ const resize = emittedOnce(w, 'resize');
w.setContentBounds(bounds);
+ await resize;
+ await delay();
+ expectBoundsEqual(w.getContentBounds(), bounds);
});
});
@@ -952,69 +946,63 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.getNormalBounds()', () => {
describe('Normal state', () => {
- it('checks normal bounds after resize', (done) => {
+ it('checks normal bounds after resize', async () => {
const size = [300, 400];
- w.once('resize', () => {
- expectBoundsEqual(w.getNormalBounds(), w.getBounds());
- done();
- });
+ const resize = emittedOnce(w, 'resize');
w.setSize(size[0], size[1]);
+ await resize;
+ expectBoundsEqual(w.getNormalBounds(), w.getBounds());
});
- it('checks normal bounds after move', (done) => {
+ it('checks normal bounds after move', async () => {
const pos = [10, 10];
- w.once('move', () => {
- expectBoundsEqual(w.getNormalBounds(), w.getBounds());
- done();
- });
+ const move = emittedOnce(w, 'move');
w.setPosition(pos[0], pos[1]);
+ await move;
+ expectBoundsEqual(w.getNormalBounds(), w.getBounds());
});
});
ifdescribe(process.platform !== 'linux')('Maximized state', () => {
- it('checks normal bounds when maximized', (done) => {
+ it('checks normal bounds when maximized', async () => {
const bounds = w.getBounds();
- w.once('maximize', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const maximize = emittedOnce(w, 'maximize');
w.show();
w.maximize();
+ await maximize;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
- it('checks normal bounds when unmaximized', (done) => {
+ it('checks normal bounds when unmaximized', async () => {
const bounds = w.getBounds();
w.once('maximize', () => {
w.unmaximize();
});
- w.once('unmaximize', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const unmaximize = emittedOnce(w, 'unmaximize');
w.show();
w.maximize();
+ await unmaximize;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
ifdescribe(process.platform !== 'linux')('Minimized state', () => {
- it('checks normal bounds when minimized', (done) => {
+ it('checks normal bounds when minimized', async () => {
const bounds = w.getBounds();
- w.once('minimize', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const minimize = emittedOnce(w, 'minimize');
w.show();
w.minimize();
+ await minimize;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
- it('checks normal bounds when restored', (done) => {
+ it('checks normal bounds when restored', async () => {
const bounds = w.getBounds();
w.once('minimize', () => {
w.restore();
});
- w.once('restore', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const restore = emittedOnce(w, 'restore');
w.show();
w.minimize();
+ await restore;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
@@ -1032,27 +1020,25 @@ describe('BrowserWindow module', () => {
expect(w.fullScreen).to.be.true();
});
- it(`checks normal bounds when fullscreen'ed`, (done) => {
+ it(`checks normal bounds when fullscreen'ed`, async () => {
const bounds = w.getBounds();
- w.once('enter-full-screen', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const enterFullScreen = emittedOnce(w, 'enter-full-screen');
w.show();
w.fullScreen = true;
+ await enterFullScreen;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
- it(`checks normal bounds when unfullscreen'ed`, (done) => {
+ it(`checks normal bounds when unfullscreen'ed`, async () => {
const bounds = w.getBounds();
w.once('enter-full-screen', () => {
w.fullScreen = false;
});
- w.once('leave-full-screen', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
+ const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
w.show();
w.fullScreen = true;
+ await leaveFullScreen;
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
@@ -1069,27 +1055,30 @@ describe('BrowserWindow module', () => {
expect(w.isFullScreen()).to.be.true();
});
- it(`checks normal bounds when fullscreen'ed`, (done) => {
+ it(`checks normal bounds when fullscreen'ed`, async () => {
const bounds = w.getBounds();
- w.once('enter-full-screen', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
w.show();
+
+ const enterFullScreen = emittedOnce(w, 'enter-full-screen');
w.setFullScreen(true);
+ await enterFullScreen;
+
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
- it(`checks normal bounds when unfullscreen'ed`, (done) => {
+ it(`checks normal bounds when unfullscreen'ed`, async () => {
const bounds = w.getBounds();
- w.once('enter-full-screen', () => {
- w.setFullScreen(false);
- });
- w.once('leave-full-screen', () => {
- expectBoundsEqual(w.getNormalBounds(), bounds);
- done();
- });
w.show();
+
+ const enterFullScreen = emittedOnce(w, 'enter-full-screen');
w.setFullScreen(true);
+ await enterFullScreen;
+
+ const leaveFullScreen = emittedOnce(w, 'leave-full-screen');
+ w.setFullScreen(false);
+ await leaveFullScreen;
+
+ expectBoundsEqual(w.getNormalBounds(), bounds);
});
});
});
@@ -1304,14 +1293,12 @@ describe('BrowserWindow module', () => {
expect(w.isAlwaysOnTop()).to.be.true('is not alwaysOnTop');
});
- it('causes the right value to be emitted on `always-on-top-changed`', (done) => {
- w.on('always-on-top-changed', (e, alwaysOnTop) => {
- expect(alwaysOnTop).to.be.true('is not alwaysOnTop');
- done();
- });
-
+ it('causes the right value to be emitted on `always-on-top-changed`', async () => {
+ const alwaysOnTopChanged = emittedOnce(w, 'always-on-top-changed');
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true);
+ const [, alwaysOnTop] = await alwaysOnTopChanged;
+ expect(alwaysOnTop).to.be.true('is not alwaysOnTop');
});
});
@@ -1344,16 +1331,13 @@ describe('BrowserWindow module', () => {
server = null as unknown as http.Server;
});
- it('calling preconnect() connects to the server', (done) => {
+ it('calling preconnect() connects to the server', async () => {
w = new BrowserWindow({ show: false });
w.webContents.on('did-start-navigation', (event, url) => {
w.webContents.session.preconnect({ url, numSockets: 4 });
});
- w.webContents.on('did-finish-load', () => {
- expect(connections).to.equal(4);
- done();
- });
- w.loadURL(url);
+ await w.loadURL(url);
+ expect(connections).to.equal(4);
});
it('does not preconnect unless requested', async () => {
@@ -2296,8 +2280,12 @@ describe('BrowserWindow module', () => {
// We need to give it some time so the windows get properly disposed (at least on OSX).
setTimeout(() => {
const currentWebContents = webContents.getAllWebContents().map((i) => i.id);
- expect(currentWebContents).to.deep.equal(initialWebContents);
- done();
+ try {
+ expect(currentWebContents).to.deep.equal(initialWebContents);
+ done();
+ } catch (error) {
+ done(e);
+ }
}, 100);
});
w.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
@@ -2332,8 +2320,12 @@ describe('BrowserWindow module', () => {
ipcMain.once('answer', (event, arg) => {
ipcMain.removeAllListeners('reloaded');
ipcMain.removeAllListeners('get-remote-module-path');
- expect(arg).to.equal('hi');
- done();
+ try {
+ expect(arg).to.equal('hi');
+ done();
+ } catch (e) {
+ done(e);
+ }
});
});
@@ -2369,8 +2361,12 @@ describe('BrowserWindow module', () => {
ipcMain.once('answer', (event, arg) => {
ipcMain.removeAllListeners('reloaded');
ipcMain.removeAllListeners('get-remote-module-path');
- expect(arg).to.equal('hi child window');
- done();
+ try {
+ expect(arg).to.equal('hi child window');
+ done();
+ } catch (e) {
+ done(e);
+ }
});
});
@@ -2448,33 +2444,29 @@ describe('BrowserWindow module', () => {
});
});
- it('opens window of about:blank with cross-scripting enabled', (done) => {
- ipcMain.once('answer', (event, content) => {
- expect(content).to.equal('Hello');
- done();
- });
+ it('opens window of about:blank with cross-scripting enabled', async () => {
+ const answer = emittedOnce(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', (done) => {
- ipcMain.once('answer', (event, content) => {
- expect(content).to.equal('Hello');
- done();
- });
+ it('opens window of same domain with cross-scripting enabled', async () => {
+ const answer = emittedOnce(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', (done) => {
- ipcMain.once('answer', (event, content) => {
- expect(content).to.equal('Blocked a frame with origin "file://" from accessing a cross-origin frame.');
- done();
- });
+ it('blocks accessing cross-origin frames', async () => {
+ const answer = emittedOnce(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