From cf10c19c336c88f4f869990ddded067318f1c5a4 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Sun, 19 Feb 2023 10:24:24 +0100 Subject: [PATCH] test: cleanup let xyz = null as unknown as T; (#37335) --- spec/api-browser-window-spec.ts | 58 ++++++++++++++++---------------- spec/api-ipc-spec.ts | 4 +-- spec/api-protocol-spec.ts | 8 ++--- spec/api-service-workers-spec.ts | 2 +- spec/api-web-contents-spec.ts | 4 +-- spec/api-web-request-spec.ts | 2 +- spec/chromium-spec.ts | 4 +-- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 92bc1d29c359..138fd281a1e7 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -95,7 +95,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.close()', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); }); @@ -150,8 +150,8 @@ describe('BrowserWindow module', () => { }); describe('when invoked synchronously inside navigation observer', () => { - let server: http.Server = null as unknown as http.Server; - let url: string = null as unknown as string; + let server: http.Server; + let url: string; before((done) => { server = http.createServer((request, response) => { @@ -210,7 +210,7 @@ describe('BrowserWindow module', () => { }); describe('window.close()', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); }); @@ -236,7 +236,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.destroy()', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); }); @@ -274,7 +274,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.loadURL(url)', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; const scheme = 'other'; const srcPath = path.join(fixtures, 'api', 'loaded-from-dataurl.js'); before(() => { @@ -294,8 +294,8 @@ describe('BrowserWindow module', () => { await closeWindow(w); w = null as unknown as BrowserWindow; }); - let server = null as unknown as http.Server; - let url = null as unknown as string; + let server: http.Server; + let url: string; let postData = null as any; before((done) => { const filePath = path.join(fixtures, 'pages', 'a.html'); @@ -474,7 +474,7 @@ describe('BrowserWindow module', () => { for (const sandbox of [false, true]) { describe(`navigation events${sandbox ? ' with sandbox' : ''}`, () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, sandbox } }); }); @@ -484,8 +484,8 @@ describe('BrowserWindow module', () => { }); describe('will-navigate event', () => { - let server = null as unknown as http.Server; - let url = null as unknown as string; + let server: http.Server; + let url: string; before((done) => { server = http.createServer((req, res) => { if (req.url === '/navigate-top') { @@ -592,8 +592,8 @@ describe('BrowserWindow module', () => { }); describe('will-redirect event', () => { - let server = null as unknown as http.Server; - let url = null as unknown as string; + let server: http.Server; + let url: string; before((done) => { server = http.createServer((req, res) => { if (req.url === '/302') { @@ -683,7 +683,7 @@ describe('BrowserWindow module', () => { } describe('focus and visibility', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false }); }); @@ -1015,7 +1015,7 @@ describe('BrowserWindow module', () => { }); describe('sizing', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, width: 400, height: 400 }); @@ -1617,7 +1617,7 @@ describe('BrowserWindow module', () => { }); ifdescribe(process.platform === 'darwin')('tabbed windows', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false }); }); @@ -1810,7 +1810,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.setProgressBar(progress)', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; before(() => { w = new BrowserWindow({ show: false }); }); @@ -1849,7 +1849,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; afterEach(closeAllWindows); @@ -1897,10 +1897,10 @@ describe('BrowserWindow module', () => { }); describe('preconnect feature', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; - let server = null as unknown as http.Server; - let url = null as unknown as string; + let server: http.Server; + let url: string; let connections = 0; beforeEach(async () => { @@ -1951,7 +1951,7 @@ describe('BrowserWindow module', () => { }); describe('BrowserWindow.setAutoHideCursor(autoHide)', () => { - let w = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false }); }); @@ -2941,8 +2941,8 @@ describe('BrowserWindow module', () => { describe('"sandbox" option', () => { const preload = path.join(path.resolve(__dirname, 'fixtures'), 'module', 'preload-sandbox.js'); - let server: http.Server = null as unknown as http.Server; - let serverUrl: string = null as unknown as string; + let server: http.Server; + let serverUrl: string; before((done) => { server = http.createServer((request, response) => { @@ -3213,7 +3213,7 @@ describe('BrowserWindow module', () => { }); describe('event handling', () => { - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } }); }); @@ -3314,7 +3314,7 @@ describe('BrowserWindow module', () => { }); describe('child windows', () => { - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ @@ -3514,7 +3514,7 @@ describe('BrowserWindow module', () => { }); describe('beforeunload handler', function () { - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); }); @@ -4472,8 +4472,8 @@ describe('BrowserWindow module', () => { }); describe('loading main frame state', () => { - let server: http.Server = null as unknown as http.Server; - let serverUrl: string = null as unknown as string; + let server: http.Server; + let serverUrl: string; before((done) => { server = http.createServer((request, response) => { diff --git a/spec/api-ipc-spec.ts b/spec/api-ipc-spec.ts index efcb7c02e696..8696f360bee3 100644 --- a/spec/api-ipc-spec.ts +++ b/spec/api-ipc-spec.ts @@ -13,7 +13,7 @@ const fixturesPath = path.resolve(__dirname, 'fixtures'); describe('ipc module', () => { describe('invoke', () => { - let w = (null as unknown as BrowserWindow); + let w: BrowserWindow; before(async () => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); @@ -127,7 +127,7 @@ describe('ipc module', () => { }); describe('ordering', () => { - let w = (null as unknown as BrowserWindow); + let w: BrowserWindow; before(async () => { w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); diff --git a/spec/api-protocol-spec.ts b/spec/api-protocol-spec.ts index 9c142731d114..d85a3f6fa5c0 100644 --- a/spec/api-protocol-spec.ts +++ b/spec/api-protocol-spec.ts @@ -70,7 +70,7 @@ function defer (): Promise & {resolve: Function, reject: Function} { } describe('protocol module', () => { - let contents: WebContents = null as unknown as WebContents; + let contents: WebContents; // NB. sandbox: true is used because it makes navigations much (~8x) faster. before(() => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); }); after(() => contents.destroy()); @@ -824,7 +824,7 @@ describe('protocol module', () => { const imageURL = `${origin}/test.png`; const filePath = path.join(fixturesPath, 'pages', 'b.html'); const fileContent = ''; - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(() => { w = new BrowserWindow({ @@ -900,7 +900,7 @@ describe('protocol module', () => { }); describe('protocol.registerSchemesAsPrivileged cors-fetch', function () { - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; beforeEach(async () => { w = new BrowserWindow({ show: false }); }); @@ -1005,7 +1005,7 @@ describe('protocol module', () => { const pagePath = path.join(fixturesPath, 'pages', 'video.html'); const videoSourceImagePath = path.join(fixturesPath, 'video-source-image.webp'); const videoPath = path.join(fixturesPath, 'video.webm'); - let w: BrowserWindow = null as unknown as BrowserWindow; + let w: BrowserWindow; before(async () => { // generate test video diff --git a/spec/api-service-workers-spec.ts b/spec/api-service-workers-spec.ts index 77bdd697a7d6..3a16f2fd0e53 100644 --- a/spec/api-service-workers-spec.ts +++ b/spec/api-service-workers-spec.ts @@ -13,7 +13,7 @@ describe('session.serviceWorkers', () => { let ses: Electron.Session; let server: http.Server; let baseUrl: string; - let w: WebContents = null as unknown as WebContents; + let w: WebContents; before(async () => { ses = session.fromPartition(partition); diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index b6208b3d05e7..8325fc965a84 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -292,8 +292,8 @@ describe('webContents module', () => { }); afterEach(closeAllWindows); - let server: http.Server = null as unknown as http.Server; - let serverUrl: string = null as unknown as string; + let server: http.Server; + let serverUrl: string; before((done) => { server = http.createServer((request, response) => { diff --git a/spec/api-web-request-spec.ts b/spec/api-web-request-spec.ts index dcdb4dbca1d3..d9cb44e49398 100644 --- a/spec/api-web-request-spec.ts +++ b/spec/api-web-request-spec.ts @@ -49,7 +49,7 @@ describe('webRequest module', () => { protocol.unregisterProtocol('cors'); }); - let contents: WebContents = null as unknown as WebContents; + let contents: WebContents; // NB. sandbox: true is used because it makes navigations much (~8x) faster. before(async () => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index 9b814ddec563..c0d48ef723b7 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -97,8 +97,8 @@ describe('window.postMessage', () => { }); describe('focus handling', () => { - let webviewContents: WebContents = null as unknown as WebContents; - let w: BrowserWindow = null as unknown as BrowserWindow; + let webviewContents: WebContents; + let w: BrowserWindow; beforeEach(async () => { w = new BrowserWindow({