diff --git a/spec/atom-environment-spec.js b/spec/atom-environment-spec.js index 7dc07dafd..324e9eddf 100644 --- a/spec/atom-environment-spec.js +++ b/spec/atom-environment-spec.js @@ -1,5 +1,6 @@ const {it, fit, ffit, beforeEach, afterEach, conditionPromise} = require('./async-spec-helpers') const _ = require('underscore-plus') +const fs = require('fs') const path = require('path') const temp = require('temp').track() const AtomEnvironment = require('../src/atom-environment') @@ -471,15 +472,28 @@ describe('AtomEnvironment', () => { await atom.workspace.open() }) - it('automatically restores the saved state into the current environment', () => { - const state = {} - spyOn(atom.workspace, 'open') - spyOn(atom, 'restoreStateIntoThisEnvironment') + it('automatically restores the saved state into the current environment', async () => { + const projectPath = temp.mkdirSync() + const filePath1 = path.join(projectPath, 'file-1') + const filePath2 = path.join(projectPath, 'file-2') + const filePath3 = path.join(projectPath, 'file-3') + fs.writeFileSync(filePath1, 'abc') + fs.writeFileSync(filePath2, 'def') + fs.writeFileSync(filePath3, 'ghi') - atom.attemptRestoreProjectStateForPaths(state, [__dirname], [__filename]) - expect(atom.restoreStateIntoThisEnvironment).toHaveBeenCalledWith(state) - expect(atom.workspace.open.callCount).toBe(1) - expect(atom.workspace.open).toHaveBeenCalledWith(__filename) + const env1 = new AtomEnvironment({applicationDelegate: atom.applicationDelegate}) + env1.project.setPaths([projectPath]) + await env1.workspace.open(filePath1) + await env1.workspace.open(filePath2) + await env1.workspace.open(filePath3) + const env1State = env1.serialize() + env1.destroy() + + const env2 = new AtomEnvironment({applicationDelegate: atom.applicationDelegate}) + await env2.attemptRestoreProjectStateForPaths(env1State, [projectPath], [filePath2]) + const restoredURIs = env2.workspace.getPaneItems().map(p => p.getURI()) + expect(restoredURIs).toEqual([filePath1, filePath2, filePath3]) + env2.destroy() }) describe('when a dock has a non-text editor', () => { diff --git a/src/atom-environment.js b/src/atom-environment.js index 159464534..a80cde66c 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -373,7 +373,7 @@ class AtomEnvironment { if (this.project) this.project.destroy() this.project = null this.commands.clear() - this.stylesElement.remove() + if (this.stylesElement) this.stylesElement.remove() this.config.unobserveUserConfig() this.autoUpdater.destroy() this.uriHandlerRegistry.destroy() @@ -1121,7 +1121,7 @@ class AtomEnvironment { } if (windowIsUnused()) { - this.restoreStateIntoThisEnvironment(state) + await this.restoreStateIntoThisEnvironment(state) return Promise.all(filesToOpen.map(file => this.workspace.open(file))) } else { let resolveDiscardStatePromise = null