From 85a0240b5c04432fc1f2511964c86bfb829e83f4 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Sat, 23 Nov 2024 10:21:38 +0000 Subject: [PATCH] test: fixup visibility tests (#44802) * test: ensure all webContents are closed * test: ensure all webContents are closed * test: fixup api-web-request-spec.ts --- spec/api-web-contents-view-spec.ts | 6 +++++- spec/api-web-request-spec.ts | 3 +-- spec/visibility-state-spec.ts | 9 ++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/api-web-contents-view-spec.ts b/spec/api-web-contents-view-spec.ts index bf8282ca2361..d041af44cd16 100644 --- a/spec/api-web-contents-view-spec.ts +++ b/spec/api-web-contents-view-spec.ts @@ -8,7 +8,11 @@ import { defer } from './lib/spec-helpers'; import { closeAllWindows } from './lib/window-helpers'; describe('WebContentsView', () => { - afterEach(closeAllWindows); + afterEach(async () => { + await closeAllWindows(); + const existingWCS = webContents.getAllWebContents(); + existingWCS.forEach((contents) => contents.close()); + }); it('can be instantiated with no arguments', () => { // eslint-disable-next-line no-new diff --git a/spec/api-web-request-spec.ts b/spec/api-web-request-spec.ts index 6a7547658851..1f414061c114 100644 --- a/spec/api-web-request-spec.ts +++ b/spec/api-web-request-spec.ts @@ -64,7 +64,6 @@ describe('webRequest module', () => { protocol.registerStringProtocol('cors', (req, cb) => cb('')); defaultURL = (await listen(server)).url + '/'; http2URL = (await listen(h2server)).url + '/'; - console.log(http2URL); }); after(() => { @@ -660,7 +659,7 @@ describe('webRequest module', () => { }); // Cleanup. - after(() => { + defer(() => { contents.destroy(); server.close(); ses.webRequest.onBeforeRequest(null); diff --git a/spec/visibility-state-spec.ts b/spec/visibility-state-spec.ts index 2f23420d803c..5a483671def9 100644 --- a/spec/visibility-state-spec.ts +++ b/spec/visibility-state-spec.ts @@ -1,4 +1,4 @@ -import { BaseWindow, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, WebContents, WebContentsView } from 'electron/main'; +import { BaseWindow, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, webContents, WebContents, WebContentsView } from 'electron/main'; import { expect } from 'chai'; @@ -15,8 +15,11 @@ import { closeWindow } from './lib/window-helpers'; ifdescribe(process.platform !== 'linux')('document.visibilityState', () => { let w: BaseWindow & {webContents: WebContents}; - afterEach(() => { - return closeWindow(w); + afterEach(async () => { + await closeWindow(w); + w = null as unknown as BrowserWindow; + const existingWCS = webContents.getAllWebContents(); + existingWCS.forEach((contents) => contents.close()); }); const load = () => w.webContents.loadFile(path.resolve(__dirname, 'fixtures', 'chromium', 'visibilitystate.html'));