1
- import { getEnvPaths , Paths } from "../../../src/node/util"
2
-
3
1
/*
4
2
5
3
TODOS
@@ -15,42 +13,14 @@ runtime: /tmp/runtime
15
13
16
14
*/
17
15
18
- // jest.mock("env-paths", () => ({
19
- // data: "/home/envPath/.local/share",
20
- // config: "/home/envPath/.config",
21
- // runtime: "/tmp/envPath/runtime",
22
- // }))
23
-
24
- jest . mock ( "xdg-basedir" , ( ) => ( {
25
- data : "/home/usr/.local/share" ,
26
- config : "/home/usr/.config" ,
27
- runtime : "/tmp/runtime" ,
28
- } ) )
29
-
30
- jest . mock ( "env-paths" , ( ) => {
31
- return ( ) => ( {
32
- data : "yo" ,
33
- config : "yo" ,
34
- runtime : "yo" ,
35
- } )
36
- } )
37
- // jest.mock("env-paths", () => mockedEnvPaths)
38
16
describe ( "getEnvPaths" , ( ) => {
39
- afterAll ( ( ) => {
40
- jest . clearAllMocks ( )
41
- jest . resetModules ( )
42
- } )
43
- it ( "should return an object with the data, config and runtime path" , ( ) => {
44
- const actualPaths = getEnvPaths ( )
45
- const expectedProperties = [ "data" , "config" , "runtime" ]
46
- expectedProperties . forEach ( ( property ) => {
47
- expect ( actualPaths [ property as keyof Paths ] ) . toBeDefined ( )
48
- } )
49
- } )
50
-
51
17
describe ( "on darwin" , ( ) => {
52
18
let ORIGINAL_PLATFORM = ""
53
-
19
+ let getEnvPaths : ( ) => {
20
+ data : string
21
+ config : string
22
+ runtime : string
23
+ }
54
24
beforeAll ( ( ) => {
55
25
ORIGINAL_PLATFORM = process . platform
56
26
@@ -59,6 +29,28 @@ describe("getEnvPaths", () => {
59
29
} )
60
30
} )
61
31
32
+ beforeEach ( ( ) => {
33
+ jest . mock ( "xdg-basedir" , ( ) => ( {
34
+ data : "/home/usr/.local/share" ,
35
+ config : "/home/usr/.config" ,
36
+ runtime : "/tmp/runtime" ,
37
+ } ) )
38
+
39
+ jest . mock ( "env-paths" , ( ) => {
40
+ return ( ) => ( {
41
+ data : "/home/envPath/.local/share" ,
42
+ config : "/home/envPath/.config" ,
43
+ temp : "/tmp/envPath/runtime" ,
44
+ } )
45
+ } )
46
+
47
+ getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
48
+ } )
49
+
50
+ afterEach ( ( ) => {
51
+ jest . resetModules ( )
52
+ } )
53
+
62
54
afterAll ( ( ) => {
63
55
// Restore old platform
64
56
@@ -78,16 +70,37 @@ describe("getEnvPaths", () => {
78
70
79
71
describe ( "on darwin" , ( ) => {
80
72
let ORIGINAL_PLATFORM = ""
81
-
73
+ let getEnvPaths : ( ) => {
74
+ data : string
75
+ config : string
76
+ runtime : string
77
+ }
82
78
beforeAll ( ( ) => {
83
- jest . unmock ( "xdg-basedir" )
84
79
ORIGINAL_PLATFORM = process . platform
85
80
86
81
Object . defineProperty ( process , "platform" , {
87
82
value : "darwin" ,
88
83
} )
89
84
} )
90
85
86
+ beforeEach ( ( ) => {
87
+ jest . mock ( "xdg-basedir" , ( ) => ( { } ) )
88
+
89
+ jest . mock ( "env-paths" , ( ) => {
90
+ return ( ) => ( {
91
+ data : "/home/envPath/.local/share" ,
92
+ config : "/home/envPath/.config" ,
93
+ temp : "/tmp/envPath/runtime" ,
94
+ } )
95
+ } )
96
+
97
+ getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
98
+ } )
99
+
100
+ afterEach ( ( ) => {
101
+ jest . resetModules ( )
102
+ } )
103
+
91
104
afterAll ( ( ) => {
92
105
// Restore old platform
93
106
@@ -99,9 +112,9 @@ describe("getEnvPaths", () => {
99
112
it ( "should return the env paths using envPaths" , ( ) => {
100
113
const envPaths = getEnvPaths ( )
101
114
102
- expect ( envPaths . data ) . toEqual ( "/home/envPath/.local/share/code-server " )
103
- expect ( envPaths . config ) . toEqual ( "/home/envPath/.config/code-server " )
104
- expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime/code-server " )
115
+ expect ( envPaths . data ) . toEqual ( "/home/envPath/.local/share" )
116
+ expect ( envPaths . config ) . toEqual ( "/home/envPath/.config" )
117
+ expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime" )
105
118
} )
106
119
} )
107
120
} )
0 commit comments