From c819fbe85254d8908d85220749b2e70009bd8fc1 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 29 Aug 2019 00:17:44 -0700 Subject: [PATCH] test: move WebContentsView spec (#19990) --- spec-main/ambient.d.ts | 3 ++ .../api-web-contents-view-spec.ts | 29 +++++++------------ .../fixtures/api/leak-exit-webcontentsview.js | 0 3 files changed, 14 insertions(+), 18 deletions(-) rename spec/api-web-contents-view-spec.js => spec-main/api-web-contents-view-spec.ts (56%) rename {spec => spec-main}/fixtures/api/leak-exit-webcontentsview.js (100%) diff --git a/spec-main/ambient.d.ts b/spec-main/ambient.d.ts index 2e30b992aa..10f112f86a 100644 --- a/spec-main/ambient.d.ts +++ b/spec-main/ambient.d.ts @@ -28,6 +28,9 @@ declare namespace Electron { setContentView(view: View): void } class View {} + class WebContentsView { + constructor(webContents: WebContents) + } } declare module 'dbus-native'; diff --git a/spec/api-web-contents-view-spec.js b/spec-main/api-web-contents-view-spec.ts similarity index 56% rename from spec/api-web-contents-view-spec.js rename to spec-main/api-web-contents-view-spec.ts index 0afa70eb56..78657a4d11 100644 --- a/spec/api-web-contents-view-spec.js +++ b/spec-main/api-web-contents-view-spec.ts @@ -1,30 +1,23 @@ -'use strict' +import { expect } from 'chai' +import * as ChildProcess from 'child_process' +import * as path from 'path' +import { emittedOnce } from './events-helpers' +import { closeWindow } from './window-helpers' -const chai = require('chai') -const ChildProcess = require('child_process') -const dirtyChai = require('dirty-chai') -const path = require('path') -const { emittedOnce } = require('./events-helpers') -const { closeWindow } = require('./window-helpers') - -const { remote } = require('electron') -const { webContents, TopLevelWindow, WebContentsView } = remote - -const { expect } = chai -chai.use(dirtyChai) +import { webContents, TopLevelWindow, WebContentsView } from 'electron' describe('WebContentsView', () => { - let w = null - afterEach(() => closeWindow(w).then(() => { w = null })) + let w: TopLevelWindow + afterEach(() => closeWindow(w as any).then(() => { w = null as unknown as TopLevelWindow })) it('can be used as content view', () => { - const web = webContents.create({}) + const web = (webContents as any).create({}) w = new TopLevelWindow({ show: false }) w.setContentView(new WebContentsView(web)) }) it('prevents adding same WebContents', () => { - const web = webContents.create({}) + const web = (webContents as any).create({}) w = new TopLevelWindow({ show: false }) w.setContentView(new WebContentsView(web)) expect(() => { @@ -35,7 +28,7 @@ describe('WebContentsView', () => { describe('new WebContentsView()', () => { it('does not crash on exit', async () => { const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontentsview.js') - const electronPath = remote.getGlobal('process').execPath + const electronPath = process.execPath const appProcess = ChildProcess.spawn(electronPath, [appPath]) const [code] = await emittedOnce(appProcess, 'close') expect(code).to.equal(0) diff --git a/spec/fixtures/api/leak-exit-webcontentsview.js b/spec-main/fixtures/api/leak-exit-webcontentsview.js similarity index 100% rename from spec/fixtures/api/leak-exit-webcontentsview.js rename to spec-main/fixtures/api/leak-exit-webcontentsview.js