test: move dialog spec to main process (#19231)

* test: move dialog spec to main process

* skip tests on windows to avoid crash

* more disabling on windows
This commit is contained in:
Jeremy Apthorp 2019-07-26 06:37:59 -07:00 committed by John Kleinschmidt
parent 4639c68a7b
commit 16011cacef

View file

@ -1,136 +1,122 @@
const { expect } = require('chai') import { expect } from 'chai'
const { closeWindow } = require('./window-helpers') import { dialog, BrowserWindow } from 'electron'
const { remote } = require('electron') import { closeAllWindows } from './window-helpers'
const { BrowserWindow, dialog } = remote import { ifit } from './spec-helpers'
const isCI = remote.getGlobal('isCi')
describe('dialog module', () => { describe('dialog module', () => {
describe('showOpenDialog', () => { describe('showOpenDialog', () => {
it('should not throw for valid cases', () => { afterEach(closeAllWindows)
// Blocks the main process and can't be run in CI ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
if (isCI) return
let w
expect(() => { expect(() => {
dialog.showOpenDialog({ title: 'i am title' }) dialog.showOpenDialog({ title: 'i am title' })
}).to.not.throw() }).to.not.throw()
expect(() => { expect(() => {
w = new BrowserWindow() const w = new BrowserWindow()
dialog.showOpenDialog(w, { title: 'i am title' }) dialog.showOpenDialog(w, { title: 'i am title' })
}).to.not.throw() }).to.not.throw()
closeWindow(w).then(() => { w = null })
}) })
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
expect(() => { expect(() => {
dialog.showOpenDialog({ properties: false }) dialog.showOpenDialog({ properties: false as any })
}).to.throw(/Properties must be an array/) }).to.throw(/Properties must be an array/)
expect(() => { expect(() => {
dialog.showOpenDialog({ title: 300 }) dialog.showOpenDialog({ title: 300 as any })
}).to.throw(/Title must be a string/) }).to.throw(/Title must be a string/)
expect(() => { expect(() => {
dialog.showOpenDialog({ buttonLabel: [] }) dialog.showOpenDialog({ buttonLabel: [] as any })
}).to.throw(/Button label must be a string/) }).to.throw(/Button label must be a string/)
expect(() => { expect(() => {
dialog.showOpenDialog({ defaultPath: {} }) dialog.showOpenDialog({ defaultPath: {} as any })
}).to.throw(/Default path must be a string/) }).to.throw(/Default path must be a string/)
expect(() => { expect(() => {
dialog.showOpenDialog({ message: {} }) dialog.showOpenDialog({ message: {} as any })
}).to.throw(/Message must be a string/) }).to.throw(/Message must be a string/)
}) })
}) })
describe('showSaveDialog', () => { describe('showSaveDialog', () => {
it('should not throw for valid cases', () => { afterEach(closeAllWindows)
// Blocks the main process and can't be run in CI ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
if (isCI) return
let w
expect(() => { expect(() => {
dialog.showSaveDialog({ title: 'i am title' }) dialog.showSaveDialog({ title: 'i am title' })
}).to.not.throw() }).to.not.throw()
expect(() => { expect(() => {
w = new BrowserWindow() const w = new BrowserWindow()
dialog.showSaveDialog(w, { title: 'i am title' }) dialog.showSaveDialog(w, { title: 'i am title' })
}).to.not.throw() }).to.not.throw()
closeWindow(w).then(() => { w = null })
}) })
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
expect(() => { expect(() => {
dialog.showSaveDialog({ title: 300 }) dialog.showSaveDialog({ title: 300 as any })
}).to.throw(/Title must be a string/) }).to.throw(/Title must be a string/)
expect(() => { expect(() => {
dialog.showSaveDialog({ buttonLabel: [] }) dialog.showSaveDialog({ buttonLabel: [] as any })
}).to.throw(/Button label must be a string/) }).to.throw(/Button label must be a string/)
expect(() => { expect(() => {
dialog.showSaveDialog({ defaultPath: {} }) dialog.showSaveDialog({ defaultPath: {} as any })
}).to.throw(/Default path must be a string/) }).to.throw(/Default path must be a string/)
expect(() => { expect(() => {
dialog.showSaveDialog({ message: {} }) dialog.showSaveDialog({ message: {} as any })
}).to.throw(/Message must be a string/) }).to.throw(/Message must be a string/)
expect(() => { expect(() => {
dialog.showSaveDialog({ nameFieldLabel: {} }) dialog.showSaveDialog({ nameFieldLabel: {} as any })
}).to.throw(/Name field label must be a string/) }).to.throw(/Name field label must be a string/)
}) })
}) })
describe('showMessageBox', () => { describe('showMessageBox', () => {
it('should not throw for valid cases', () => { afterEach(closeAllWindows);
// Blocks the main process and can't be run in CI
if (isCI) return
let w
// parentless message boxes are synchronous on macOS
// dangling message boxes on windows cause a DCHECK: https://cs.chromium.org/chromium/src/base/win/message_window.cc?l=68&rcl=7faa4bf236a866d007dc5672c9ce42660e67a6a6
ifit(process.platform !== 'darwin' && process.platform !== 'win32')('should not throw for a parentless message box', () => {
expect(() => { expect(() => {
dialog.showMessageBox({ title: 'i am title' }) dialog.showMessageBox({ message: 'i am message' })
}).to.not.throw() }).to.not.throw()
})
ifit(process.platform !== 'win32')('should not throw for valid cases', () => {
expect(() => { expect(() => {
w = new BrowserWindow() const w = new BrowserWindow()
dialog.showMessageBox(w, { title: 'i am title' }) dialog.showMessageBox(w, { message: 'i am message' })
}).to.not.throw() }).to.not.throw()
closeWindow(w).then(() => { w = null })
}) })
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
expect(() => { expect(() => {
dialog.showMessageBox(undefined, { type: 'not-a-valid-type' }) dialog.showMessageBox(undefined as any, { type: 'not-a-valid-type', message: '' })
}).to.throw(/Invalid message box type/) }).to.throw(/Invalid message box type/)
expect(() => { expect(() => {
dialog.showMessageBox(null, { buttons: false }) dialog.showMessageBox(null as any, { buttons: false as any, message: '' })
}).to.throw(/Buttons must be an array/) }).to.throw(/Buttons must be an array/)
expect(() => { expect(() => {
dialog.showMessageBox({ title: 300 }) dialog.showMessageBox({ title: 300 as any, message: '' })
}).to.throw(/Title must be a string/) }).to.throw(/Title must be a string/)
expect(() => { expect(() => {
dialog.showMessageBox({ message: [] }) dialog.showMessageBox({ message: [] as any })
}).to.throw(/Message must be a string/) }).to.throw(/Message must be a string/)
expect(() => { expect(() => {
dialog.showMessageBox({ detail: 3.14 }) dialog.showMessageBox({ detail: 3.14 as any, message: '' })
}).to.throw(/Detail must be a string/) }).to.throw(/Detail must be a string/)
expect(() => { expect(() => {
dialog.showMessageBox({ checkboxLabel: false }) dialog.showMessageBox({ checkboxLabel: false as any, message: '' })
}).to.throw(/checkboxLabel must be a string/) }).to.throw(/checkboxLabel must be a string/)
}) })
}) })
@ -138,15 +124,15 @@ describe('dialog module', () => {
describe('showErrorBox', () => { describe('showErrorBox', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
expect(() => { expect(() => {
dialog.showErrorBox() (dialog.showErrorBox as any)()
}).to.throw(/Insufficient number of arguments/) }).to.throw(/Insufficient number of arguments/)
expect(() => { expect(() => {
dialog.showErrorBox(3, 'four') dialog.showErrorBox(3 as any, 'four')
}).to.throw(/Error processing argument at index 0/) }).to.throw(/Error processing argument at index 0/)
expect(() => { expect(() => {
dialog.showErrorBox('three', 4) dialog.showErrorBox('three', 4 as any)
}).to.throw(/Error processing argument at index 1/) }).to.throw(/Error processing argument at index 1/)
}) })
}) })
@ -154,15 +140,15 @@ describe('dialog module', () => {
describe('showCertificateTrustDialog', () => { describe('showCertificateTrustDialog', () => {
it('throws errors when the options are invalid', () => { it('throws errors when the options are invalid', () => {
expect(() => { expect(() => {
dialog.showCertificateTrustDialog() (dialog.showCertificateTrustDialog as any)()
}).to.throw(/options must be an object/) }).to.throw(/options must be an object/)
expect(() => { expect(() => {
dialog.showCertificateTrustDialog({}) dialog.showCertificateTrustDialog({} as any)
}).to.throw(/certificate must be an object/) }).to.throw(/certificate must be an object/)
expect(() => { expect(() => {
dialog.showCertificateTrustDialog({ certificate: {}, message: false }) dialog.showCertificateTrustDialog({ certificate: {} as any, message: false as any })
}).to.throw(/message must be a string/) }).to.throw(/message must be a string/)
}) })
}) })