From 5fd7a43970c2bdfa1017a4b23098aec3dafbf513 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 14 Dec 2022 22:07:38 +0100 Subject: [PATCH] test: replace (webContents as any).destroy() with webContents.destroy() (#36653) Co-authored-by: Milan Burda Co-authored-by: John Kleinschmidt --- spec/api-browser-view-spec.ts | 12 ++++++------ spec/api-browser-window-spec.ts | 10 +++++----- spec/api-ipc-renderer-spec.ts | 2 +- spec/api-protocol-spec.ts | 6 +++--- spec/api-service-workers-spec.ts | 2 +- spec/api-web-contents-spec.ts | 2 +- spec/api-web-request-spec.ts | 2 +- spec/chromium-spec.ts | 4 ++-- spec/node-spec.ts | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/api-browser-view-spec.ts b/spec/api-browser-view-spec.ts index 89ee7af47d..a87d2dff7b 100644 --- a/spec/api-browser-view-spec.ts +++ b/spec/api-browser-view-spec.ts @@ -32,7 +32,7 @@ describe('BrowserView module', () => { if (view && view.webContents) { const p = emittedOnce(view.webContents, 'destroyed'); - (view.webContents as any).destroy(); + view.webContents.destroy(); view = null as any; await p; } @@ -193,11 +193,11 @@ describe('BrowserView module', () => { describe('BrowserWindow.addBrowserView()', () => { it('does not throw for valid args', () => { const view1 = new BrowserView(); - defer(() => (view1.webContents as any).destroy()); + defer(() => view1.webContents.destroy()); w.addBrowserView(view1); defer(() => w.removeBrowserView(view1)); const view2 = new BrowserView(); - defer(() => (view2.webContents as any).destroy()); + defer(() => view2.webContents.destroy()); w.addBrowserView(view2); defer(() => w.removeBrowserView(view2)); }); @@ -212,7 +212,7 @@ describe('BrowserView module', () => { it('does not crash if the BrowserView webContents are destroyed prior to window addition', () => { expect(() => { const view1 = new BrowserView(); - (view1.webContents as any).destroy(); + view1.webContents.destroy(); w.addBrowserView(view1); }).to.not.throw(); }); @@ -262,11 +262,11 @@ describe('BrowserView module', () => { describe('BrowserWindow.getBrowserViews()', () => { it('returns same views as was added', () => { const view1 = new BrowserView(); - defer(() => (view1.webContents as any).destroy()); + defer(() => view1.webContents.destroy()); w.addBrowserView(view1); defer(() => w.removeBrowserView(view1)); const view2 = new BrowserView(); - defer(() => (view2.webContents as any).destroy()); + defer(() => view2.webContents.destroy()); w.addBrowserView(view2); defer(() => w.removeBrowserView(view2)); diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 9b6eb24f75..82b1614523 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -2206,7 +2206,7 @@ describe('BrowserWindow module', () => { w.setBrowserView(bv); defer(() => { w.removeBrowserView(bv); - (bv.webContents as any).destroy(); + bv.webContents.destroy(); }); await bv.webContents.loadURL('about:blank'); expect(BrowserWindow.fromWebContents(bv.webContents)!.id).to.equal(w.id); @@ -2254,7 +2254,7 @@ describe('BrowserWindow module', () => { w.setBrowserView(bv); defer(() => { w.removeBrowserView(bv); - (bv.webContents as any).destroy(); + bv.webContents.destroy(); }); expect(BrowserWindow.fromBrowserView(bv)!.id).to.equal(w.id); }); @@ -2268,8 +2268,8 @@ describe('BrowserWindow module', () => { defer(() => { w.removeBrowserView(bv1); w.removeBrowserView(bv2); - (bv1.webContents as any).destroy(); - (bv2.webContents as any).destroy(); + bv1.webContents.destroy(); + bv2.webContents.destroy(); }); expect(BrowserWindow.fromBrowserView(bv1)!.id).to.equal(w.id); expect(BrowserWindow.fromBrowserView(bv2)!.id).to.equal(w.id); @@ -2278,7 +2278,7 @@ describe('BrowserWindow module', () => { it('returns undefined if not attached', () => { const bv = new BrowserView(); defer(() => { - (bv.webContents as any).destroy(); + bv.webContents.destroy(); }); expect(BrowserWindow.fromBrowserView(bv)).to.be.null('BrowserWindow associated with bv'); }); diff --git a/spec/api-ipc-renderer-spec.ts b/spec/api-ipc-renderer-spec.ts index 16f2d15a8a..861dbe6e44 100644 --- a/spec/api-ipc-renderer-spec.ts +++ b/spec/api-ipc-renderer-spec.ts @@ -144,7 +144,7 @@ describe('ipcRenderer module', () => { }); after(() => { - (contents as any).destroy(); + contents.destroy(); contents = null as unknown as WebContents; }); diff --git a/spec/api-protocol-spec.ts b/spec/api-protocol-spec.ts index f39dff7a5c..d97a61961a 100644 --- a/spec/api-protocol-spec.ts +++ b/spec/api-protocol-spec.ts @@ -74,7 +74,7 @@ describe('protocol module', () => { let contents: WebContents = null as unknown as WebContents; // NB. sandbox: true is used because it makes navigations much (~8x) faster. before(() => { contents = (webContents as any).create({ sandbox: true }); }); - after(() => (contents as any).destroy()); + after(() => contents.destroy()); async function ajax (url: string, options = {}) { // Note that we need to do navigation every time after a protocol is @@ -964,7 +964,7 @@ describe('protocol module', () => { // This is called in a timeout to avoid a crash that happens when // calling destroy() in a microtask. setTimeout(() => { - (newContents as any).destroy(); + newContents.destroy(); }); } } @@ -1062,7 +1062,7 @@ describe('protocol module', () => { // This is called in a timeout to avoid a crash that happens when // calling destroy() in a microtask. setTimeout(() => { - (newContents as any).destroy(); + newContents.destroy(); }); } } diff --git a/spec/api-service-workers-spec.ts b/spec/api-service-workers-spec.ts index 5f7f81f918..9df6714cfa 100644 --- a/spec/api-service-workers-spec.ts +++ b/spec/api-service-workers-spec.ts @@ -43,7 +43,7 @@ describe('session.serviceWorkers', () => { }); afterEach(async () => { - (w as any).destroy(); + w.destroy(); server.close(); await ses.clearStorageData(); }); diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index f92ff5abe7..66626be965 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -1552,7 +1552,7 @@ describe('webContents module', () => { const contents = (webContents as any).create() as WebContents; const originalEmit = contents.emit.bind(contents); contents.emit = (...args) => { return originalEmit(...args); }; - contents.once(e.name as any, () => (contents as any).destroy()); + contents.once(e.name as any, () => contents.destroy()); const destroyed = emittedOnce(contents, 'destroyed'); contents.loadURL(serverUrl + e.url); await destroyed; diff --git a/spec/api-web-request-spec.ts b/spec/api-web-request-spec.ts index 22e58e5fe8..734740b271 100644 --- a/spec/api-web-request-spec.ts +++ b/spec/api-web-request-spec.ts @@ -55,7 +55,7 @@ describe('webRequest module', () => { contents = (webContents as any).create({ sandbox: true }); await contents.loadFile(path.join(fixturesPath, 'pages', 'fetch.html')); }); - after(() => (contents as any).destroy()); + after(() => contents.destroy()); async function ajax (url: string, options = {}) { return contents.executeJavaScript(`ajax("${url}", ${JSON.stringify(options)})`); diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index ec5224d3b0..703f7bf250 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -1479,7 +1479,7 @@ describe('chromium features', () => { }); afterEach(() => { - (contents as any).destroy(); + contents.destroy(); contents = null as any; }); @@ -1595,7 +1595,7 @@ describe('chromium features', () => { afterEach(async () => { if (contents) { - (contents as any).destroy(); + contents.destroy(); contents = null as any; } await closeAllWindows(); diff --git a/spec/node-spec.ts b/spec/node-spec.ts index d682d12752..1eced8ab1d 100644 --- a/spec/node-spec.ts +++ b/spec/node-spec.ts @@ -790,7 +790,7 @@ describe('node feature', () => { } })`)) .then(() => { - (w as any).destroy(); + w.destroy(); child.send('plz-quit'); done(); });