@@ -7,6 +7,16 @@ import * as util from "../../../src/node/util"
7
7
8
8
describe ( "getEnvPaths" , ( ) => {
9
9
describe ( "on darwin" , ( ) => {
10
+ let ORIGINAL_PLATFORM = ""
11
+
12
+ beforeAll ( ( ) => {
13
+ ORIGINAL_PLATFORM = process . platform
14
+
15
+ Object . defineProperty ( process , "platform" , {
16
+ value : "darwin" ,
17
+ } )
18
+ } )
19
+
10
20
beforeEach ( ( ) => {
11
21
jest . resetModules ( )
12
22
jest . mock ( "env-paths" , ( ) => {
@@ -17,14 +27,23 @@ describe("getEnvPaths", () => {
17
27
} )
18
28
} )
19
29
} )
30
+
31
+ afterAll ( ( ) => {
32
+ // Restore old platform
33
+
34
+ Object . defineProperty ( process , "platform" , {
35
+ value : ORIGINAL_PLATFORM ,
36
+ } )
37
+ } )
38
+
20
39
it ( "should return the env paths using xdgBasedir" , ( ) => {
21
40
jest . mock ( "xdg-basedir" , ( ) => ( {
22
41
data : "/home/usr/.local/share" ,
23
42
config : "/home/usr/.config" ,
24
43
runtime : "/tmp/runtime" ,
25
44
} ) )
26
45
const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
27
- const envPaths = getEnvPaths ( "darwin" )
46
+ const envPaths = getEnvPaths ( )
28
47
29
48
expect ( envPaths . data ) . toEqual ( "/home/usr/.local/share/code-server" )
30
49
expect ( envPaths . config ) . toEqual ( "/home/usr/.config/code-server" )
@@ -34,14 +53,24 @@ describe("getEnvPaths", () => {
34
53
it ( "should return the env paths using envPaths when xdgBasedir is undefined" , ( ) => {
35
54
jest . mock ( "xdg-basedir" , ( ) => ( { } ) )
36
55
const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
37
- const envPaths = getEnvPaths ( "darwin" )
56
+ const envPaths = getEnvPaths ( )
38
57
39
58
expect ( envPaths . data ) . toEqual ( "/home/envPath/.local/share" )
40
59
expect ( envPaths . config ) . toEqual ( "/home/envPath/.config" )
41
60
expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime" )
42
61
} )
43
62
} )
44
63
describe ( "on win32" , ( ) => {
64
+ let ORIGINAL_PLATFORM = ""
65
+
66
+ beforeAll ( ( ) => {
67
+ ORIGINAL_PLATFORM = process . platform
68
+
69
+ Object . defineProperty ( process , "platform" , {
70
+ value : "win32" ,
71
+ } )
72
+ } )
73
+
45
74
beforeEach ( ( ) => {
46
75
jest . resetModules ( )
47
76
jest . mock ( "env-paths" , ( ) => {
@@ -53,16 +82,34 @@ describe("getEnvPaths", () => {
53
82
} )
54
83
} )
55
84
85
+ afterAll ( ( ) => {
86
+ // Restore old platform
87
+
88
+ Object . defineProperty ( process , "platform" , {
89
+ value : ORIGINAL_PLATFORM ,
90
+ } )
91
+ } )
92
+
56
93
it ( "should return the env paths using envPaths" , ( ) => {
57
94
const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
58
- const envPaths = getEnvPaths ( "win32" )
95
+ const envPaths = getEnvPaths ( )
59
96
60
97
expect ( envPaths . data ) . toEqual ( "/windows/envPath/.local/share" )
61
98
expect ( envPaths . config ) . toEqual ( "/windows/envPath/.config" )
62
99
expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime" )
63
100
} )
64
101
} )
65
102
describe ( "on other platforms" , ( ) => {
103
+ let ORIGINAL_PLATFORM = ""
104
+
105
+ beforeAll ( ( ) => {
106
+ ORIGINAL_PLATFORM = process . platform
107
+
108
+ Object . defineProperty ( process , "platform" , {
109
+ value : "linux" ,
110
+ } )
111
+ } )
112
+
66
113
beforeEach ( ( ) => {
67
114
jest . resetModules ( )
68
115
jest . mock ( "env-paths" , ( ) => {
@@ -74,12 +121,20 @@ describe("getEnvPaths", () => {
74
121
} )
75
122
} )
76
123
124
+ afterAll ( ( ) => {
125
+ // Restore old platform
126
+
127
+ Object . defineProperty ( process , "platform" , {
128
+ value : ORIGINAL_PLATFORM ,
129
+ } )
130
+ } )
131
+
77
132
it ( "should return the runtime using xdgBasedir if it exists" , ( ) => {
78
133
jest . mock ( "xdg-basedir" , ( ) => ( {
79
134
runtime : "/tmp/runtime" ,
80
135
} ) )
81
136
const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
82
- const envPaths = getEnvPaths ( "linux" )
137
+ const envPaths = getEnvPaths ( )
83
138
84
139
expect ( envPaths . data ) . toEqual ( "/linux/envPath/.local/share" )
85
140
expect ( envPaths . config ) . toEqual ( "/linux/envPath/.config" )
@@ -89,7 +144,7 @@ describe("getEnvPaths", () => {
89
144
it ( "should return the env paths using envPaths when xdgBasedir is undefined" , ( ) => {
90
145
jest . mock ( "xdg-basedir" , ( ) => ( { } ) )
91
146
const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
92
- const envPaths = getEnvPaths ( "linux" )
147
+ const envPaths = getEnvPaths ( )
93
148
94
149
expect ( envPaths . data ) . toEqual ( "/linux/envPath/.local/share" )
95
150
expect ( envPaths . config ) . toEqual ( "/linux/envPath/.config" )
@@ -141,16 +196,16 @@ describe("isHashMatch", () => {
141
196
const actual = await util . isHashMatch ( password , _hash )
142
197
expect ( actual ) . toBe ( false )
143
198
} )
144
- it ( "should return false if the hash doesn't start with a $" , async ( ) => {
199
+ it ( "should return false and not throw an error if the hash doesn't start with a $" , async ( ) => {
145
200
const password = "hellowpasssword"
146
201
const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
202
+ expect ( async ( ) => await util . isHashMatch ( password , _hash ) ) . not . toThrow ( )
147
203
expect ( await util . isHashMatch ( password , _hash ) ) . toBe ( false )
148
204
} )
149
- it ( "should return false if the password and hash don't match " , async ( ) => {
205
+ it ( "should reject the promise and throw if error " , async ( ) => {
150
206
const password = "hellowpasssword"
151
207
const _hash = "$ar2i"
152
- const actual = await util . isHashMatch ( password , _hash )
153
- expect ( actual ) . toBe ( false )
208
+ expect ( async ( ) => await util . isHashMatch ( password , _hash ) ) . rejects . toThrow ( )
154
209
} )
155
210
} )
156
211
0 commit comments