test: use webContents.create() in type-safe way (#37281)

test: use (webContents as typeof ElectronInternal.WebContents).create()

Co-authored-by: Milan Burda <miburda@microsoft.com>
This commit is contained in:
Milan Burda 2023-02-16 15:41:41 +01:00 committed by GitHub
parent a44e76fb70
commit ea848bc1c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 27 deletions

View file

@ -72,7 +72,7 @@ function defer (): Promise<any> & {resolve: Function, reject: Function} {
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 }); });
before(() => { contents = (webContents as typeof ElectronInternal.WebContents).create({ sandbox: true }); });
after(() => contents.destroy());
async function ajax (url: string, options = {}) {
@ -980,7 +980,10 @@ describe('protocol module', () => {
callback('');
});
const newContents: WebContents = (webContents as any).create({ nodeIntegration: true, contextIsolation: false });
const newContents = (webContents as typeof ElectronInternal.WebContents).create({
nodeIntegration: true,
contextIsolation: false
});
const consoleMessages: string[] = [];
newContents.on('console-message', (e, level, message) => consoleMessages.push(message));
try {
@ -1081,7 +1084,11 @@ describe('protocol module', () => {
await registerStreamProtocol(standardScheme, protocolHandler);
await registerStreamProtocol('stream', protocolHandler);
const newContents: WebContents = (webContents as any).create({ nodeIntegration: true, contextIsolation: false });
const newContents = (webContents as typeof ElectronInternal.WebContents).create({
nodeIntegration: true,
contextIsolation: false
});
try {
newContents.loadURL(testingScheme + '://fake-host');
const [, response] = await emittedOnce(ipcMain, 'result');