mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
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:
@@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user