From 753db274fc3a8339ae4cab0a41870302b384c356 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 12 Aug 2016 15:20:58 +0200 Subject: [PATCH] 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. --- spec/main-process/atom-application.test.js | 20 ++++++++++++++++---- src/main-process/atom-application.coffee | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spec/main-process/atom-application.test.js b/spec/main-process/atom-application.test.js index 49c475383..e844f08ea 100644 --- a/spec/main-process/atom-application.test.js +++ b/spec/main-process/atom-application.test.js @@ -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) + }) + }) + } }) diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index f326d8c88..ac75f2087 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -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