mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
chore: migrate guest-window-manager-spec.ts to vitest
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user