diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 08f5ce94912..6c38ba9e52d 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -520,7 +520,7 @@ describe('browser-window module', function () { describe('BrowserWindow.setAppDetails(options)', function () { it('supports setting the app details', function () { - if (process.platform !== 'win32') return this.skip() + if (process.platform !== 'win32') return const iconPath = path.join(fixtures, 'assets', 'icon.ico') @@ -657,7 +657,7 @@ describe('browser-window module', function () { describe('"zoomToPageWidth" option', function () { it('sets the window width to the page width when used', function () { - if (process.platform !== 'darwin') return this.skip() + if (process.platform !== 'darwin') return w.destroy() w = new BrowserWindow({ @@ -856,7 +856,7 @@ describe('browser-window module', function () { assert(/Blocked a frame with origin/.test(exceptionMessage)) // FIXME this popup window should be closed in sandbox.html - closeWindow(popupWindow).then(() => { + closeWindow(popupWindow, {assertSingleWindow: false}).then(() => { popupWindow = null done() }) @@ -1720,7 +1720,7 @@ describe('browser-window module', function () { describe('previewFile', function () { it('opens the path in Quick Look on macOS', function () { - if (process.platform !== 'darwin') return this.skip() + if (process.platform !== 'darwin') return assert.doesNotThrow(function () { w.previewFile(__filename) diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index f0d730d7b00..2b4aac9faea 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -87,7 +87,7 @@ describe('clipboard module', function () { describe('clipboard.read/writeFindText(text)', function () { it('reads and write text to the find pasteboard', function () { - if (process.platform !== 'darwin') return this.skip() + if (process.platform !== 'darwin') return clipboard.writeFindText('find this') assert.equal(clipboard.readFindText(), 'find this') diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index f6e69808b5c..b9b6dd0a51c 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -236,9 +236,8 @@ describe('session module', function () { }) describe('will-download event', function () { - var w = null - beforeEach(function () { + if (w != null) w.destroy() w = new BrowserWindow({ show: false, width: 400, @@ -246,10 +245,6 @@ describe('session module', function () { }) }) - afterEach(function () { - return closeWindow(w).then(function () { w = null }) - }) - it('can cancel default download behavior', function (done) { const mockFile = new Buffer(1024) const contentDisposition = 'inline; filename="mockFile.txt"' diff --git a/spec/api-web-frame-spec.js b/spec/api-web-frame-spec.js index 4ef6fdd387d..ce0d0436ec5 100644 --- a/spec/api-web-frame-spec.js +++ b/spec/api-web-frame-spec.js @@ -6,6 +6,11 @@ const {BrowserWindow, protocol, ipcMain} = remote describe('webFrame module', function () { var fixtures = path.resolve(__dirname, 'fixtures') + var w = null + + afterEach(function () { + return closeWindow(w).then(function () { w = null }) + }) describe('webFrame.registerURLSchemeAsPrivileged', function () { it('supports fetch api by default', function (done) { @@ -96,14 +101,11 @@ describe('webFrame module', function () { runNumber++ const url = standardScheme + '://fake-host' - var w = new BrowserWindow({show: false}) + w = new BrowserWindow({show: false}) after(function (done) { protocol.unregisterProtocol(corsScheme, function () { protocol.unregisterProtocol(standardScheme, function () { - closeWindow(w).then(function () { - w = null - done() - }) + done() }) }) }) diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 5399cde041f..9d485edfded 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -792,6 +792,11 @@ describe('asar package', function () { describe('asar protocol', function () { var url = require('url') + var w = null + + afterEach(function () { + return closeWindow(w).then(function () { w = null }) + }) it('can request a file in package', function (done) { var p = path.resolve(fixtures, 'asar', 'a.asar', 'file1') @@ -839,10 +844,9 @@ describe('asar package', function () { it('sets __dirname correctly', function (done) { after(function () { ipcMain.removeAllListeners('dirname') - return closeWindow(w).then(function () { w = null }) }) - var w = new BrowserWindow({ + w = new BrowserWindow({ show: false, width: 400, height: 400 @@ -863,10 +867,9 @@ describe('asar package', function () { it('loads script tag in html', function (done) { after(function () { ipcMain.removeAllListeners('ping') - return closeWindow(w).then(function () { w = null }) }) - var w = new BrowserWindow({ + w = new BrowserWindow({ show: false, width: 400, height: 400 @@ -889,10 +892,9 @@ describe('asar package', function () { after(function () { ipcMain.removeAllListeners('asar-video') - return closeWindow(w).then(function () { w = null }) }) - var w = new BrowserWindow({ + w = new BrowserWindow({ show: false, width: 400, height: 400 diff --git a/spec/window-helpers.js b/spec/window-helpers.js index 9909ec65721..5a63100f9d0 100644 --- a/spec/window-helpers.js +++ b/spec/window-helpers.js @@ -1,9 +1,18 @@ -exports.closeWindow = (window) => { +const assert = require('assert') +const {BrowserWindow} = require('electron').remote + +exports.closeWindow = (window, {assertSingleWindow} = {assertSingleWindow: true}) => { if (window == null || window.isDestroyed()) { + if (assertSingleWindow) { + assert.equal(BrowserWindow.getAllWindows().length, 1) + } return Promise.resolve() } else { return new Promise((resolve, reject) => { window.once('closed', () => { + if (assertSingleWindow) { + assert.equal(BrowserWindow.getAllWindows().length, 1) + } resolve() }) window.setClosable(true)