From 9c26be7b43b46c97a65cfa8eeb4566959b3926c5 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Mon, 30 Nov 2020 17:06:25 -0800 Subject: [PATCH] test: deflake current-render-view-deleted test (#26698) --- spec-main/api-web-contents-spec.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index f5b73d896b01..c72998c98224 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -1202,24 +1202,25 @@ describe('webContents module', () => { expect(currentRenderViewDeletedEmitted).to.be.false('current-render-view-deleted was emitted'); }); - // TODO (jkleinsc) - this test is very flaky on WOA due to its dependence on a setTimeout; disabling until it can be rewritten - ifit(process.platform !== 'win32' || process.arch !== 'arm64')('does not emit current-render-view-deleted when speculative RVHs are deleted and nativeWindowOpen is set to true', async () => { + it('does not emit current-render-view-deleted when speculative RVHs are deleted and nativeWindowOpen is set to true', async () => { const parentWindow = new BrowserWindow({ show: false, webPreferences: { nativeWindowOpen: true } }); let currentRenderViewDeletedEmitted = false; - let childWindow:BrowserWindow; + let childWindow: BrowserWindow | null = null; const destroyed = emittedOnce(parentWindow.webContents, 'destroyed'); const renderViewDeletedHandler = () => { currentRenderViewDeletedEmitted = true; }; - app.once('browser-window-created', (event, window) => { - childWindow = window; - window.webContents.on('current-render-view-deleted' as any, renderViewDeletedHandler); + const childWindowCreated = new Promise((resolve) => { + app.once('browser-window-created', (event, window) => { + childWindow = window; + window.webContents.on('current-render-view-deleted' as any, renderViewDeletedHandler); + resolve(); + }); }); parentWindow.loadURL(`${serverUrl}/first-window-open`); - setTimeout(() => { - childWindow.webContents.removeListener('current-render-view-deleted' as any, renderViewDeletedHandler); - parentWindow.close(); - }, 500); + await childWindowCreated; + childWindow!.webContents.removeListener('current-render-view-deleted' as any, renderViewDeletedHandler); + parentWindow.close(); await destroyed; expect(currentRenderViewDeletedEmitted).to.be.false('child window was destroyed'); });