@@ -7,6 +7,16 @@ import * as util from "../../../src/node/util"
77
88describe ( "getEnvPaths" , ( ) => {
99 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+
1020 beforeEach ( ( ) => {
1121 jest . resetModules ( )
1222 jest . mock ( "env-paths" , ( ) => {
@@ -17,14 +27,23 @@ describe("getEnvPaths", () => {
1727 } )
1828 } )
1929 } )
30+
31+ afterAll ( ( ) => {
32+ // Restore old platform
33+
34+ Object . defineProperty ( process , "platform" , {
35+ value : ORIGINAL_PLATFORM ,
36+ } )
37+ } )
38+
2039 it ( "should return the env paths using xdgBasedir" , ( ) => {
2140 jest . mock ( "xdg-basedir" , ( ) => ( {
2241 data : "/home/usr/.local/share" ,
2342 config : "/home/usr/.config" ,
2443 runtime : "/tmp/runtime" ,
2544 } ) )
2645 const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
27- const envPaths = getEnvPaths ( "darwin" )
46+ const envPaths = getEnvPaths ( )
2847
2948 expect ( envPaths . data ) . toEqual ( "/home/usr/.local/share/code-server" )
3049 expect ( envPaths . config ) . toEqual ( "/home/usr/.config/code-server" )
@@ -34,14 +53,24 @@ describe("getEnvPaths", () => {
3453 it ( "should return the env paths using envPaths when xdgBasedir is undefined" , ( ) => {
3554 jest . mock ( "xdg-basedir" , ( ) => ( { } ) )
3655 const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
37- const envPaths = getEnvPaths ( "darwin" )
56+ const envPaths = getEnvPaths ( )
3857
3958 expect ( envPaths . data ) . toEqual ( "/home/envPath/.local/share" )
4059 expect ( envPaths . config ) . toEqual ( "/home/envPath/.config" )
4160 expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime" )
4261 } )
4362 } )
4463 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+
4574 beforeEach ( ( ) => {
4675 jest . resetModules ( )
4776 jest . mock ( "env-paths" , ( ) => {
@@ -53,16 +82,34 @@ describe("getEnvPaths", () => {
5382 } )
5483 } )
5584
85+ afterAll ( ( ) => {
86+ // Restore old platform
87+
88+ Object . defineProperty ( process , "platform" , {
89+ value : ORIGINAL_PLATFORM ,
90+ } )
91+ } )
92+
5693 it ( "should return the env paths using envPaths" , ( ) => {
5794 const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
58- const envPaths = getEnvPaths ( "win32" )
95+ const envPaths = getEnvPaths ( )
5996
6097 expect ( envPaths . data ) . toEqual ( "/windows/envPath/.local/share" )
6198 expect ( envPaths . config ) . toEqual ( "/windows/envPath/.config" )
6299 expect ( envPaths . runtime ) . toEqual ( "/tmp/envPath/runtime" )
63100 } )
64101 } )
65102 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+
66113 beforeEach ( ( ) => {
67114 jest . resetModules ( )
68115 jest . mock ( "env-paths" , ( ) => {
@@ -74,12 +121,20 @@ describe("getEnvPaths", () => {
74121 } )
75122 } )
76123
124+ afterAll ( ( ) => {
125+ // Restore old platform
126+
127+ Object . defineProperty ( process , "platform" , {
128+ value : ORIGINAL_PLATFORM ,
129+ } )
130+ } )
131+
77132 it ( "should return the runtime using xdgBasedir if it exists" , ( ) => {
78133 jest . mock ( "xdg-basedir" , ( ) => ( {
79134 runtime : "/tmp/runtime" ,
80135 } ) )
81136 const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
82- const envPaths = getEnvPaths ( "linux" )
137+ const envPaths = getEnvPaths ( )
83138
84139 expect ( envPaths . data ) . toEqual ( "/linux/envPath/.local/share" )
85140 expect ( envPaths . config ) . toEqual ( "/linux/envPath/.config" )
@@ -89,7 +144,7 @@ describe("getEnvPaths", () => {
89144 it ( "should return the env paths using envPaths when xdgBasedir is undefined" , ( ) => {
90145 jest . mock ( "xdg-basedir" , ( ) => ( { } ) )
91146 const getEnvPaths = require ( "../../../src/node/util" ) . getEnvPaths
92- const envPaths = getEnvPaths ( "linux" )
147+ const envPaths = getEnvPaths ( )
93148
94149 expect ( envPaths . data ) . toEqual ( "/linux/envPath/.local/share" )
95150 expect ( envPaths . config ) . toEqual ( "/linux/envPath/.config" )
@@ -141,16 +196,16 @@ describe("isHashMatch", () => {
141196 const actual = await util . isHashMatch ( password , _hash )
142197 expect ( actual ) . toBe ( false )
143198 } )
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 ( ) => {
145200 const password = "hellowpasssword"
146201 const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
202+ expect ( async ( ) => await util . isHashMatch ( password , _hash ) ) . not . toThrow ( )
147203 expect ( await util . isHashMatch ( password , _hash ) ) . toBe ( false )
148204 } )
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 ( ) => {
150206 const password = "hellowpasssword"
151207 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 ( )
154209 } )
155210} )
156211
0 commit comments