test: cleanup let xyz = null as unknown as T; (#37335)

This commit is contained in:
Milan Burda 2023-02-19 10:24:24 +01:00 committed by GitHub
parent fcfbcbc7e1
commit cf10c19c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 41 deletions

View file

@ -95,7 +95,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.close()', () => { describe('BrowserWindow.close()', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
}); });
@ -150,8 +150,8 @@ describe('BrowserWindow module', () => {
}); });
describe('when invoked synchronously inside navigation observer', () => { describe('when invoked synchronously inside navigation observer', () => {
let server: http.Server = null as unknown as http.Server; let server: http.Server;
let url: string = null as unknown as string; let url: string;
before((done) => { before((done) => {
server = http.createServer((request, response) => { server = http.createServer((request, response) => {
@ -210,7 +210,7 @@ describe('BrowserWindow module', () => {
}); });
describe('window.close()', () => { describe('window.close()', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
}); });
@ -236,7 +236,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.destroy()', () => { describe('BrowserWindow.destroy()', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
}); });
@ -274,7 +274,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.loadURL(url)', () => { describe('BrowserWindow.loadURL(url)', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
const scheme = 'other'; const scheme = 'other';
const srcPath = path.join(fixtures, 'api', 'loaded-from-dataurl.js'); const srcPath = path.join(fixtures, 'api', 'loaded-from-dataurl.js');
before(() => { before(() => {
@ -294,8 +294,8 @@ describe('BrowserWindow module', () => {
await closeWindow(w); await closeWindow(w);
w = null as unknown as BrowserWindow; w = null as unknown as BrowserWindow;
}); });
let server = null as unknown as http.Server; let server: http.Server;
let url = null as unknown as string; let url: string;
let postData = null as any; let postData = null as any;
before((done) => { before((done) => {
const filePath = path.join(fixtures, 'pages', 'a.html'); const filePath = path.join(fixtures, 'pages', 'a.html');
@ -474,7 +474,7 @@ describe('BrowserWindow module', () => {
for (const sandbox of [false, true]) { for (const sandbox of [false, true]) {
describe(`navigation events${sandbox ? ' with sandbox' : ''}`, () => { describe(`navigation events${sandbox ? ' with sandbox' : ''}`, () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, sandbox } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: false, sandbox } });
}); });
@ -484,8 +484,8 @@ describe('BrowserWindow module', () => {
}); });
describe('will-navigate event', () => { describe('will-navigate event', () => {
let server = null as unknown as http.Server; let server: http.Server;
let url = null as unknown as string; let url: string;
before((done) => { before((done) => {
server = http.createServer((req, res) => { server = http.createServer((req, res) => {
if (req.url === '/navigate-top') { if (req.url === '/navigate-top') {
@ -592,8 +592,8 @@ describe('BrowserWindow module', () => {
}); });
describe('will-redirect event', () => { describe('will-redirect event', () => {
let server = null as unknown as http.Server; let server: http.Server;
let url = null as unknown as string; let url: string;
before((done) => { before((done) => {
server = http.createServer((req, res) => { server = http.createServer((req, res) => {
if (req.url === '/302') { if (req.url === '/302') {
@ -683,7 +683,7 @@ describe('BrowserWindow module', () => {
} }
describe('focus and visibility', () => { describe('focus and visibility', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false });
}); });
@ -1015,7 +1015,7 @@ describe('BrowserWindow module', () => {
}); });
describe('sizing', () => { describe('sizing', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, width: 400, height: 400 }); w = new BrowserWindow({ show: false, width: 400, height: 400 });
@ -1617,7 +1617,7 @@ describe('BrowserWindow module', () => {
}); });
ifdescribe(process.platform === 'darwin')('tabbed windows', () => { ifdescribe(process.platform === 'darwin')('tabbed windows', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false });
}); });
@ -1810,7 +1810,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.setProgressBar(progress)', () => { describe('BrowserWindow.setProgressBar(progress)', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
before(() => { before(() => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false });
}); });
@ -1849,7 +1849,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => { describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
afterEach(closeAllWindows); afterEach(closeAllWindows);
@ -1897,10 +1897,10 @@ describe('BrowserWindow module', () => {
}); });
describe('preconnect feature', () => { describe('preconnect feature', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
let server = null as unknown as http.Server; let server: http.Server;
let url = null as unknown as string; let url: string;
let connections = 0; let connections = 0;
beforeEach(async () => { beforeEach(async () => {
@ -1951,7 +1951,7 @@ describe('BrowserWindow module', () => {
}); });
describe('BrowserWindow.setAutoHideCursor(autoHide)', () => { describe('BrowserWindow.setAutoHideCursor(autoHide)', () => {
let w = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false });
}); });
@ -2941,8 +2941,8 @@ describe('BrowserWindow module', () => {
describe('"sandbox" option', () => { describe('"sandbox" option', () => {
const preload = path.join(path.resolve(__dirname, 'fixtures'), 'module', 'preload-sandbox.js'); const preload = path.join(path.resolve(__dirname, 'fixtures'), 'module', 'preload-sandbox.js');
let server: http.Server = null as unknown as http.Server; let server: http.Server;
let serverUrl: string = null as unknown as string; let serverUrl: string;
before((done) => { before((done) => {
server = http.createServer((request, response) => { server = http.createServer((request, response) => {
@ -3213,7 +3213,7 @@ describe('BrowserWindow module', () => {
}); });
describe('event handling', () => { describe('event handling', () => {
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } }); w = new BrowserWindow({ show: false, webPreferences: { sandbox: true } });
}); });
@ -3314,7 +3314,7 @@ describe('BrowserWindow module', () => {
}); });
describe('child windows', () => { describe('child windows', () => {
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ w = new BrowserWindow({
@ -3514,7 +3514,7 @@ describe('BrowserWindow module', () => {
}); });
describe('beforeunload handler', function () { describe('beforeunload handler', function () {
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
}); });
@ -4472,8 +4472,8 @@ describe('BrowserWindow module', () => {
}); });
describe('loading main frame state', () => { describe('loading main frame state', () => {
let server: http.Server = null as unknown as http.Server; let server: http.Server;
let serverUrl: string = null as unknown as string; let serverUrl: string;
before((done) => { before((done) => {
server = http.createServer((request, response) => { server = http.createServer((request, response) => {

View file

@ -13,7 +13,7 @@ const fixturesPath = path.resolve(__dirname, 'fixtures');
describe('ipc module', () => { describe('ipc module', () => {
describe('invoke', () => { describe('invoke', () => {
let w = (null as unknown as BrowserWindow); let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });
@ -127,7 +127,7 @@ describe('ipc module', () => {
}); });
describe('ordering', () => { describe('ordering', () => {
let w = (null as unknown as BrowserWindow); let w: BrowserWindow;
before(async () => { before(async () => {
w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } }); w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true, contextIsolation: false } });

View file

@ -70,7 +70,7 @@ function defer (): Promise<any> & {resolve: Function, reject: Function} {
} }
describe('protocol module', () => { 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. // NB. sandbox: true is used because it makes navigations much (~8x) faster.
before(() => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); }); before(() => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); });
after(() => contents.destroy()); after(() => contents.destroy());
@ -824,7 +824,7 @@ describe('protocol module', () => {
const imageURL = `${origin}/test.png`; const imageURL = `${origin}/test.png`;
const filePath = path.join(fixturesPath, 'pages', 'b.html'); const filePath = path.join(fixturesPath, 'pages', 'b.html');
const fileContent = '<img src="/test.png" />'; const fileContent = '<img src="/test.png" />';
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(() => { beforeEach(() => {
w = new BrowserWindow({ w = new BrowserWindow({
@ -900,7 +900,7 @@ describe('protocol module', () => {
}); });
describe('protocol.registerSchemesAsPrivileged cors-fetch', function () { describe('protocol.registerSchemesAsPrivileged cors-fetch', function () {
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ show: false }); w = new BrowserWindow({ show: false });
}); });
@ -1005,7 +1005,7 @@ describe('protocol module', () => {
const pagePath = path.join(fixturesPath, 'pages', 'video.html'); const pagePath = path.join(fixturesPath, 'pages', 'video.html');
const videoSourceImagePath = path.join(fixturesPath, 'video-source-image.webp'); const videoSourceImagePath = path.join(fixturesPath, 'video-source-image.webp');
const videoPath = path.join(fixturesPath, 'video.webm'); const videoPath = path.join(fixturesPath, 'video.webm');
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
before(async () => { before(async () => {
// generate test video // generate test video

View file

@ -13,7 +13,7 @@ describe('session.serviceWorkers', () => {
let ses: Electron.Session; let ses: Electron.Session;
let server: http.Server; let server: http.Server;
let baseUrl: string; let baseUrl: string;
let w: WebContents = null as unknown as WebContents; let w: WebContents;
before(async () => { before(async () => {
ses = session.fromPartition(partition); ses = session.fromPartition(partition);

View file

@ -292,8 +292,8 @@ describe('webContents module', () => {
}); });
afterEach(closeAllWindows); afterEach(closeAllWindows);
let server: http.Server = null as unknown as http.Server; let server: http.Server;
let serverUrl: string = null as unknown as string; let serverUrl: string;
before((done) => { before((done) => {
server = http.createServer((request, response) => { server = http.createServer((request, response) => {

View file

@ -49,7 +49,7 @@ describe('webRequest module', () => {
protocol.unregisterProtocol('cors'); 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. // NB. sandbox: true is used because it makes navigations much (~8x) faster.
before(async () => { before(async () => {
contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true });

View file

@ -97,8 +97,8 @@ describe('window.postMessage', () => {
}); });
describe('focus handling', () => { describe('focus handling', () => {
let webviewContents: WebContents = null as unknown as WebContents; let webviewContents: WebContents;
let w: BrowserWindow = null as unknown as BrowserWindow; let w: BrowserWindow;
beforeEach(async () => { beforeEach(async () => {
w = new BrowserWindow({ w = new BrowserWindow({