diff --git a/spec/guest-window-manager-spec.ts b/spec/guest-window-manager.spec.ts similarity index 94% rename from spec/guest-window-manager-spec.ts rename to spec/guest-window-manager.spec.ts index 9021cc939c..b347d6acc2 100644 --- a/spec/guest-window-manager-spec.ts +++ b/spec/guest-window-manager.spec.ts @@ -1,13 +1,14 @@ import { BrowserWindow, screen } from 'electron'; import { expect, assert } from 'chai'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, it } from 'vitest'; import { once } from 'node:events'; import * as http from 'node:http'; import * as nodePath from 'node:path'; import { HexColors, ScreenCapture, hasCapturableScreen } from './lib/screen-helpers'; -import { ifit, listen } from './lib/spec-helpers'; +import { ifit, listen, withDone } from './lib/spec-helpers'; import { closeAllWindows } from './lib/window-helpers'; describe('webContents.setWindowOpenHandler', () => { @@ -20,34 +21,37 @@ describe('webContents.setWindowOpenHandler', () => { afterEach(closeAllWindows); - it('does not fire window creation events if the handler callback throws an error', (done) => { - const error = new Error('oh no'); - const listeners = process.listeners('uncaughtException'); - process.removeAllListeners('uncaughtException'); - process.on('uncaughtException', (thrown) => { - try { - expect(thrown).to.equal(error); - done(); - } catch (e) { - done(e); - } finally { - process.removeAllListeners('uncaughtException'); - for (const listener of listeners) { - process.on('uncaughtException', listener); + it( + 'does not fire window creation events if the handler callback throws an error', + withDone((done) => { + const error = new Error('oh no'); + const listeners = process.listeners('uncaughtException'); + process.removeAllListeners('uncaughtException'); + process.on('uncaughtException', (thrown) => { + try { + expect(thrown).to.equal(error); + done(); + } catch (e) { + done(e); + } finally { + process.removeAllListeners('uncaughtException'); + for (const listener of listeners) { + process.on('uncaughtException', listener); + } } - } - }); + }); - browserWindow.webContents.on('did-create-window', () => { - assert.fail('did-create-window should not be called with an overridden window.open'); - }); + browserWindow.webContents.on('did-create-window', () => { + assert.fail('did-create-window should not be called with an overridden window.open'); + }); - browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true"); + browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true"); - browserWindow.webContents.setWindowOpenHandler(() => { - throw error; - }); - }); + browserWindow.webContents.setWindowOpenHandler(() => { + throw error; + }); + }) + ); it('does not fire window creation events if the handler callback returns a bad result', async () => { const bad = new Promise((resolve) => { @@ -391,7 +395,7 @@ describe('webContents.setWindowOpenHandler', () => { let server: http.Server; let url: string; - before(async () => { + beforeAll(async () => { server = http.createServer((request, response) => { switch (request.url) { case '/index': @@ -414,7 +418,7 @@ describe('webContents.setWindowOpenHandler', () => { url = (await listen(server)).url; }); - after(() => { + afterAll(() => { server.close(); });