Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Updated async rename to be a sync copy (per feedback from @bridiver)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Mar 23, 2017
1 parent c35fc1e commit db0a11b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
13 changes: 7 additions & 6 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// - NODE_ENV of ‘test’ bypassing session state or else they all fail.

const Immutable = require('immutable')
const fs = require('fs')
const fs = require('fs-extra')
const path = require('path')
const electron = require('electron')
const app = electron.app
Expand Down Expand Up @@ -573,11 +573,12 @@ module.exports.backupSession = () => {
const src = getStoragePath()
const dest = getTempStoragePath('backup')

console.log('An error occurred. For support purposes, file "' + src + '" has been renamed to "' + dest + '".')

fs.rename(src, dest, (err) => {
if (err) console.log('backupSession: rename error: ' + err.toString())
})
try {
fs.copySync(src, dest)
console.log('An error occurred. For support purposes, file "' + src + '" has been copied to "' + dest + '".')
} catch (e) {
console.log('backupSession: error making copy of session file: ', e)
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"file-loader": "^0.8.5",
"font-awesome": "^4.5.0",
"font-awesome-webpack": "0.0.4",
"fs-extra": "^2.1.2",
"immutable": "^3.7.5",
"immutablediff": "^0.4.2",
"immutablepatch": "brave/immutable-js-patch",
Expand Down
15 changes: 9 additions & 6 deletions test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ describe('sessionStore unit tests', function () {
rename: (oldPath, newPath, callback) => {
console.log('calling mocked fs.rename')
callback()
},
copySync: (oldPath, newPath) => {
console.log('calling mocked fs.copySync')
}
}
const mockSiteUtil = {
Expand All @@ -64,7 +67,7 @@ describe('sessionStore unit tests', function () {
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('fs', fakeFileSystem)
mockery.registerMock('fs-extra', fakeFileSystem)
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('./locale', fakeLocale)
mockery.registerMock('../js/state/siteUtil', mockSiteUtil)
Expand Down Expand Up @@ -765,19 +768,19 @@ describe('sessionStore unit tests', function () {

describe('backupSession', function () {
describe('happy path', function () {
let renameSpy
let copySyncSpy

before(function () {
renameSpy = sinon.spy(fakeFileSystem, 'rename')
copySyncSpy = sinon.spy(fakeFileSystem, 'copySync')
})

after(function () {
renameSpy.restore()
copySyncSpy.restore()
})

it('calls fs.rename', function () {
it('calls fs.copySync', function () {
sessionStore.backupSession()
assert.equal(renameSpy.calledOnce, true)
assert.equal(copySyncSpy.calledOnce, true)
})
})
})
Expand Down

0 comments on commit db0a11b

Please sign in to comment.