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