Clear storage data after each AtomApplication test

This, along with using a temporary directory as the ATOM_HOME, will make
sure that tests won't share any state with one another, possibly
increasing the level of resiliency of the suite.
This commit is contained in:
Antonio Scandurra
2016-08-12 15:20:58 +02:00
parent a817a354dc
commit 753db274fc
2 changed files with 19 additions and 5 deletions

View File

@@ -12,6 +12,8 @@ import parseCommandLine from '../../src/main-process/parse-command-line'
const ATOM_RESOURCE_PATH = path.resolve(__dirname, '..', '..')
describe('AtomApplication', function () {
this.timeout(20000)
let originalAtomHome, atomApplicationsToDestroy
beforeEach(function () {
@@ -25,16 +27,15 @@ describe('AtomApplication', function () {
atomApplicationsToDestroy = []
})
afterEach(function () {
afterEach(async function () {
process.env.ATOM_HOME = originalAtomHome
for (let atomApplication of atomApplicationsToDestroy) {
atomApplication.destroy()
await atomApplication.destroy()
}
await clearElectronSession()
})
describe('launch', function () {
this.timeout(20000)
it('can open to a specific line number of a file', async function () {
const filePath = path.join(makeTempDir(), 'new-file')
fs.writeFileSync(filePath, '1\n2\n3\n4\n')
@@ -403,4 +404,15 @@ describe('AtomApplication', function () {
global.setTimeout(resolve, timeout)
})
}
function clearElectronSession () {
return new Promise(function (resolve) {
electron.session.defaultSession.clearStorageData(function () {
// Resolve promise on next tick, otherwise the process stalls. This
// might be a bug in Electron, but it's probably fixed on the newer
// versions.
process.nextTick(resolve)
})
})
}
})

View File

@@ -97,8 +97,10 @@ class AtomApplication
destroy: ->
@disposable.dispose()
for window in @windows
windowsClosePromises = @windows.map (window) ->
window.close()
window.closedPromise
Promise.all(windowsClosePromises)
launch: (options) ->
if options.pathsToOpen?.length > 0 or options.urlsToOpen?.length > 0 or options.test