Skip to content

Commit 34a4cac

Browse files
authored
Merge pull request electron#284 from tiemevanveen/master
Fixes for tests for Windows
2 parents ce64c4a + 54e7dba commit 34a4cac

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/index.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const Application = require('spectron').Application
4+
const electron = require('electron')
45
const chai = require('chai')
56
const chaiAsPromised = require('chai-as-promised')
67
const path = require('path')
@@ -16,9 +17,24 @@ describe('demo app', function () {
1617

1718
let app
1819

19-
const removeStoredPreferences = function () {
20+
const getUserDataPath = function () {
2021
const productName = require('../package').productName
21-
const userDataPath = path.join(process.env.HOME, 'Library', 'Application Support', productName)
22+
switch (process.platform) {
23+
case 'darwin':
24+
return path.join(process.env.HOME, 'Library', 'Application Support', productName)
25+
case 'win32':
26+
return path.join(process.env.APPDATA, productName)
27+
case 'freebsd':
28+
case 'linux':
29+
case 'sunos':
30+
return path.join(process.env.HOME, '.config', productName)
31+
default:
32+
throw new Error(`Unknown userDataPath path for platform ${process.platform}`)
33+
}
34+
}
35+
36+
const removeStoredPreferences = function () {
37+
const userDataPath = getUserDataPath()
2238
try {
2339
fs.unlinkSync(path.join(userDataPath, 'activeDemoButtonId.json'))
2440
} catch (error) {
@@ -80,7 +96,7 @@ describe('demo app', function () {
8096

8197
const startApp = function () {
8298
app = new Application({
83-
path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron'),
99+
path: electron,
84100
args: [
85101
path.join(__dirname, '..')
86102
],
@@ -105,6 +121,14 @@ describe('demo app', function () {
105121
}
106122
})
107123

124+
it('checks hardcoded path for userData is correct', function () {
125+
return app.client.execute(function () {
126+
return require('electron').remote.app.getPath('userData')
127+
}).then(function (result) {
128+
return result.value
129+
}).should.eventually.equal(getUserDataPath())
130+
})
131+
108132
it('opens a window displaying the about page', function () {
109133
return app.client.getWindowCount().should.eventually.equal(1)
110134
.browserWindow.isMinimized().should.eventually.be.false

0 commit comments

Comments
 (0)