Skip to content

Commit 84f6203

Browse files
author
Wliu
authored
Merge pull request atom#16322 from atom/wl-more-history-fixes
More history manager fixes in specs
2 parents 1d6549a + 266a40d commit 84f6203

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

spec/history-manager-spec.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
/** @babel */
1+
const {it, fit, ffit, fffit, beforeEach, afterEach} = require('./async-spec-helpers')
2+
const {Emitter, Disposable, CompositeDisposable} = require('event-kit')
23

3-
import {it, fit, ffit, fffit, beforeEach, afterEach} from './async-spec-helpers'
4-
import {Emitter, Disposable, CompositeDisposable} from 'event-kit'
5-
6-
import {HistoryManager, HistoryProject} from '../src/history-manager'
7-
import StateStore from '../src/state-store'
4+
const {HistoryManager, HistoryProject} = require('../src/history-manager')
5+
const StateStore = require('../src/state-store')
86

97
describe("HistoryManager", () => {
108
let historyManager, commandRegistry, project, stateStore
119
let commandDisposable, projectDisposable
1210

1311
beforeEach(async () => {
14-
// Do not clobber recent project history
15-
spyOn(atom.applicationDelegate, 'didChangeHistoryManager')
16-
1712
commandDisposable = jasmine.createSpyObj('Disposable', ['dispose'])
1813
commandRegistry = jasmine.createSpyObj('CommandRegistry', ['add'])
1914
commandRegistry.add.andReturn(commandDisposable)
@@ -185,11 +180,26 @@ describe("HistoryManager", () => {
185180
})
186181
})
187182

188-
describe("saveState" ,() => {
183+
describe("saveState", () => {
184+
let savedHistory
185+
beforeEach(() => {
186+
// historyManager.saveState is spied on globally to prevent specs from
187+
// modifying the shared project history. Since these tests depend on
188+
// saveState, we unspy it but in turn spy on the state store instead
189+
// so that no data is actually stored to it.
190+
jasmine.unspy(historyManager, 'saveState')
191+
192+
spyOn(historyManager.stateStore, 'save').andCallFake((name, history) => {
193+
savedHistory = history
194+
return Promise.resolve()
195+
})
196+
})
197+
189198
it("saves the state", async () => {
190199
await historyManager.addProject(["/save/state"])
191200
await historyManager.saveState()
192201
const historyManager2 = new HistoryManager({stateStore, project, commands: commandRegistry})
202+
spyOn(historyManager2.stateStore, 'load').andCallFake(name => Promise.resolve(savedHistory))
193203
await historyManager2.loadState()
194204
expect(historyManager2.getProjects()[0].paths).toEqual(['/save/state'])
195205
})

spec/spec-helper.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ else
6363

6464
beforeEach ->
6565
# Do not clobber recent project history
66-
spyOn(atom.history, 'saveState').andReturn(Promise.resolve())
66+
spyOn(Object.getPrototypeOf(atom.history), 'saveState').andReturn(Promise.resolve())
6767

6868
atom.project.setPaths([specProjectPath])
6969

0 commit comments

Comments
 (0)