Merge pull request #17750 from atom/mb-reduce-test-noise

Fix errors causing tests to fail when run from the UI
This commit is contained in:
Max Brunsfeld
2018-08-10 12:22:54 -07:00
committed by GitHub
3 changed files with 27 additions and 81 deletions

View File

@@ -746,29 +746,6 @@ describe('AtomEnvironment', () => {
})
})
describe('::updateAvailable(info) (called via IPC from browser process)', () => {
let subscription
afterEach(() => {
if (subscription) subscription.dispose()
})
it('invokes onUpdateAvailable listeners', async () => {
if (process.platform !== 'darwin') return // Test tied to electron autoUpdater, we use something else on Linux and Win32
const updateAvailablePromise = new Promise(resolve => {
subscription = atom.onUpdateAvailable(resolve)
})
atom.listenForUpdates()
const {autoUpdater} = require('electron').remote
autoUpdater.emit('update-downloaded', null, 'notes', 'version')
const {releaseVersion} = await updateAvailablePromise
expect(releaseVersion).toBe('version')
})
})
describe('::getReleaseChannel()', () => {
let version

View File

@@ -1,11 +1,8 @@
'use babel'
import AutoUpdateManager from '../src/auto-update-manager'
import {remote} from 'electron'
const AutoUpdateManager = require('../src/auto-update-manager')
const {remote} = require('electron')
const electronAutoUpdater = remote.require('electron').autoUpdater
describe('AutoUpdateManager (renderer)', () => {
if (process.platform !== 'darwin') return // Tests are tied to electron autoUpdater, we use something else on Linux and Win32
let autoUpdateManager

View File

@@ -1,12 +1,23 @@
const {ipcRenderer, remote, shell} = require('electron')
const ipcHelpers = require('./ipc-helpers')
const {Disposable} = require('event-kit')
const {Emitter, Disposable} = require('event-kit')
const getWindowLoadSettings = require('./get-window-load-settings')
module.exports =
class ApplicationDelegate {
constructor () {
this.pendingSettingsUpdateCount = 0
this._ipcMessageEmitter = null
}
ipcMessageEmitter () {
if (!this._ipcMessageEmitter) {
this._ipcMessageEmitter = new Emitter()
ipcRenderer.on('message', (event, message, detail) => {
this._ipcMessageEmitter.emit(message, detail)
})
}
return this._ipcMessageEmitter
}
getWindowLoadSettings () { return getWindowLoadSettings() }
@@ -189,21 +200,13 @@ class ApplicationDelegate {
}
onDidChangeUserSettings (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'did-change-user-settings') {
if (this.pendingSettingsUpdateCount === 0) callback(detail)
}
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('did-change-user-settings', detail => {
if (this.pendingSettingsUpdateCount === 0) callback(detail)
})
}
onDidFailToReadUserSettings (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'did-fail-to-read-user-settings') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('did-fail-to-read-user-setting', callback)
}
confirm (options, callback) {
@@ -261,24 +264,14 @@ class ApplicationDelegate {
}
onDidOpenLocations (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'open-locations') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('open-locations', callback)
}
onUpdateAvailable (callback) {
const outerCallback = (event, message, detail) => {
// TODO: Yes, this is strange that `onUpdateAvailable` is listening for
// `did-begin-downloading-update`. We currently have no mechanism to know
// if there is an update, so begin of downloading is a good proxy.
if (message === 'did-begin-downloading-update') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
// TODO: Yes, this is strange that `onUpdateAvailable` is listening for
// `did-begin-downloading-update`. We currently have no mechanism to know
// if there is an update, so begin of downloading is a good proxy.
return this.ipcMessageEmitter().on('did-begin-downloading-update', callback)
}
onDidBeginDownloadingUpdate (callback) {
@@ -286,40 +279,19 @@ class ApplicationDelegate {
}
onDidBeginCheckingForUpdate (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'checking-for-update') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('checking-for-update', callback)
}
onDidCompleteDownloadingUpdate (callback) {
const outerCallback = (event, message, detail) => {
// TODO: We could rename this event to `did-complete-downloading-update`
if (message === 'update-available') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('update-available', callback)
}
onUpdateNotAvailable (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'update-not-available') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('update-not-available', callback)
}
onUpdateError (callback) {
const outerCallback = (event, message, detail) => {
if (message === 'update-error') callback(detail)
}
ipcRenderer.on('message', outerCallback)
return new Disposable(() => ipcRenderer.removeListener('message', outerCallback))
return this.ipcMessageEmitter().on('update-error', callback)
}
onApplicationMenuCommand (handler) {