Fix unloading serialization test

This commit is contained in:
Jordan Eldredge 2018-08-27 10:24:04 -07:00
parent 57e6927f2a
commit 351b624487
2 changed files with 25 additions and 22 deletions

View File

@ -258,7 +258,7 @@ describe('AtomEnvironment', () => {
atomEnv.destroy()
})
it('ignores mousedown/keydown events happening after calling unloadEditorWindow', () => {
it('ignores mousedown/keydown events happening after calling prepareToUnloadEditorWindow', async () => {
const atomEnv = new AtomEnvironment({
applicationDelegate: global.atom.applicationDelegate
})
@ -276,18 +276,19 @@ describe('AtomEnvironment', () => {
let mousedown = new MouseEvent('mousedown')
atomEnv.document.dispatchEvent(mousedown)
atomEnv.unloadEditorWindow()
expect(atomEnv.saveState).not.toHaveBeenCalled()
await atomEnv.prepareToUnloadEditorWindow()
expect(atomEnv.saveState).toHaveBeenCalledWith({isUnloading: true})
advanceClock(atomEnv.saveStateDebounceInterval)
idleCallbacks.shift()()
expect(atomEnv.saveState).not.toHaveBeenCalled()
expect(atomEnv.saveState.calls.length).toBe(1)
mousedown = new MouseEvent('mousedown')
atomEnv.document.dispatchEvent(mousedown)
advanceClock(atomEnv.saveStateDebounceInterval)
idleCallbacks.shift()()
expect(atomEnv.saveState).not.toHaveBeenCalled()
expect(atomEnv.saveState.calls.length).toBe(1)
atomEnv.destroy()
})

View File

@ -800,24 +800,7 @@ class AtomEnvironment {
this.disposables.add(this.applicationDelegate.onApplicationMenuCommand(this.dispatchApplicationMenuCommand.bind(this)))
this.disposables.add(this.applicationDelegate.onContextMenuCommand(this.dispatchContextMenuCommand.bind(this)))
this.disposables.add(this.applicationDelegate.onURIMessage(this.dispatchURIMessage.bind(this)))
this.disposables.add(this.applicationDelegate.onDidRequestUnload(async () => {
try {
await this.saveState({isUnloading: true})
} catch (error) {
console.error(error)
}
const closing = !this.workspace || await this.workspace.confirmClose({
windowCloseRequested: true,
projectHasPaths: this.project.getPaths().length > 0
})
if (closing) {
this.unloading = true
await this.packages.deactivatePackages()
}
return closing
}))
this.disposables.add(this.applicationDelegate.onDidRequestUnload(this.prepareToUnloadEditorWindow.bind(this)))
this.listenForUpdates()
@ -896,6 +879,25 @@ class AtomEnvironment {
}
}
async prepareToUnloadEditorWindow () {
try {
await this.saveState({isUnloading: true})
} catch (error) {
console.error(error)
}
const closing = !this.workspace || await this.workspace.confirmClose({
windowCloseRequested: true,
projectHasPaths: this.project.getPaths().length > 0
})
if (closing) {
this.unloading = true
await this.packages.deactivatePackages()
}
return closing
}
unloadEditorWindow () {
if (!this.project) return