1
1
'use strict'
2
2
3
3
const Application = require ( 'spectron' ) . Application
4
+ const electron = require ( 'electron' )
4
5
const chai = require ( 'chai' )
5
6
const chaiAsPromised = require ( 'chai-as-promised' )
6
7
const path = require ( 'path' )
@@ -16,9 +17,24 @@ describe('demo app', function () {
16
17
17
18
let app
18
19
19
- const removeStoredPreferences = function ( ) {
20
+ const getUserDataPath = function ( ) {
20
21
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 ( )
22
38
try {
23
39
fs . unlinkSync ( path . join ( userDataPath , 'activeDemoButtonId.json' ) )
24
40
} catch ( error ) {
@@ -80,7 +96,7 @@ describe('demo app', function () {
80
96
81
97
const startApp = function ( ) {
82
98
app = new Application ( {
83
- path : path . join ( __dirname , '..' , 'node_modules' , '.bin' , ' electron' ) ,
99
+ path : electron ,
84
100
args : [
85
101
path . join ( __dirname , '..' )
86
102
] ,
@@ -105,6 +121,14 @@ describe('demo app', function () {
105
121
}
106
122
} )
107
123
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
+
108
132
it ( 'opens a window displaying the about page' , function ( ) {
109
133
return app . client . getWindowCount ( ) . should . eventually . equal ( 1 )
110
134
. browserWindow . isMinimized ( ) . should . eventually . be . false
0 commit comments