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

Commit

Permalink
allow setting of user data dir
Browse files Browse the repository at this point in the history
use a different user data dir for each test run
refactor autofill tests
fixes #3618
  • Loading branch information
bridiver committed Sep 2, 2016
1 parent 7078680 commit 2a6d5b8
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 331 deletions.
9 changes: 9 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var locale = require('./locale')

const Immutable = require('immutable')
const electron = require('electron')
const path = require('path')
const BrowserWindow = electron.BrowserWindow
const dialog = electron.dialog
const ipcMain = electron.ipcMain
Expand Down Expand Up @@ -64,6 +65,14 @@ const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const basicAuth = require('./browser/basicAuth')

if (!process.env.USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) {
process.env.USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV)
}

if (process.env.USER_DATA_DIR) {
app.setPath('userData', process.env.USER_DATA_DIR)
}

// Used to collect the per window state when shutting down the application
let perWindowState = []
let sessionStateStoreCompleteOnQuit = false
Expand Down
16 changes: 6 additions & 10 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ const sessionStorageVersion = 1
const filtering = require('./filtering')
// const tabState = require('./common/state/tabState')

let suffix = ''
if (process.env.NODE_ENV === 'development') {
suffix = '-dev'
}
const sessionStorageName = `session-store-${sessionStorageVersion}${suffix}`
const storagePath = process.env.NODE_ENV !== 'test'
? path.join(app.getPath('userData'), sessionStorageName)
: path.join(process.env.HOME, '.brave-test-session-store-1')
const getSetting = require('../js/settings').getSetting
const promisify = require('../js/lib/promisify')
const sessionStorageName = `session-store-${sessionStorageVersion}`

const getStoragePath = () => {
return path.join(app.getPath('userData'), sessionStorageName)
}
/**
* Saves the specified immutable browser state to storage.
*
Expand Down Expand Up @@ -78,7 +74,7 @@ module.exports.saveAppState = (payload, isShutdown) => {
: path.join(process.env.HOME, '.brave-test-session-store-tmp-' + epochTimestamp)

let p = promisify(fs.writeFile, tmpStoragePath, JSON.stringify(payload))
.then(() => promisify(fs.rename, tmpStoragePath, storagePath))
.then(() => promisify(fs.rename, tmpStoragePath, getStoragePath()))
if (isShutdown) {
p = p.then(module.exports.cleanSessionDataOnShutdown())
}
Expand Down Expand Up @@ -314,7 +310,7 @@ module.exports.loadAppState = () => {
return new Promise((resolve, reject) => {
let data
try {
data = fs.readFileSync(storagePath)
data = fs.readFileSync(getStoragePath())
} catch (e) {
}

Expand Down
14 changes: 14 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ If you'd like to see code run on each page load, you can edit `app/extensions/br
Calls to `console.log` and related functions go into the per page dev tools console mentioned above.


## Debugging Session Data

The session data is stored in OS specific user data directories. Within those directories there will be a `brave` directory for release builds and a `brave-development` directory for dev (from NODE_ENV). If you want to use a different directory for dev you can set the environment variable `USER_DATA_DIR` to the directory you want to use. Each test run goes in a new tmp directory inside the OS specific tmpdir. Normally these directories are removed when the test is finished, but if you want to keep them you can the enviroment variable `KEEP_USER_DATA_DIR` to true.

MacOS
~/Library/Application Support/brave

Linux
linux ~/.config/brave

Windows
C:\Users\username\AppData\Roaming\brave


## Profiling React code

The `Debug` menu has a `Toggle React Profiling` option which will start/stop the React addon for profiling.
Expand Down
4 changes: 2 additions & 2 deletions test/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('sessionStore', function () {
.waitUntil(function () {
return this.getValue(urlInput).then((val) => val === page1Url)
})
yield Brave.stopApp()
yield Brave.startApp(false)
yield Brave.stopApp(false)
yield Brave.startApp()
yield setup(Brave.app.client)
})

Expand Down
Loading

0 comments on commit 2a6d5b8

Please sign in to comment.