1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
+ import { configFile } from '../src/config/file' ;
3
4
import { expect } from 'chai' ;
4
5
import { ConfigLoader } from '../src/config/ConfigLoader' ;
5
6
import { isValidGitUrl , isValidPath , isValidBranchName } from '../src/config/ConfigLoader' ;
@@ -23,6 +24,18 @@ describe('ConfigLoader', () => {
23
24
fs . rmSync ( tempDir , { recursive : true } ) ;
24
25
}
25
26
sinon . restore ( ) ;
27
+ configLoader ?. stop ( ) ;
28
+ } ) ;
29
+
30
+ after ( async ( ) => {
31
+ // reset config to default after all tests have run
32
+ console . log ( `Restoring config to defaults from file ${ configFile } ` ) ;
33
+ configLoader = new ConfigLoader ( { } ) ;
34
+ await configLoader . loadFromFile ( {
35
+ type : 'file' ,
36
+ enabled : true ,
37
+ path : configFile ,
38
+ } ) ;
26
39
} ) ;
27
40
28
41
describe ( 'loadFromFile' , ( ) => {
@@ -168,7 +181,7 @@ describe('ConfigLoader', () => {
168
181
169
182
describe ( 'initialize' , ( ) => {
170
183
it ( 'should initialize cache directory using env-paths' , async ( ) => {
171
- const configLoader = new ConfigLoader ( { } ) ;
184
+ configLoader = new ConfigLoader ( { } ) ;
172
185
await configLoader . initialize ( ) ;
173
186
174
187
// Check that cacheDir is set and is a string
@@ -190,7 +203,7 @@ describe('ConfigLoader', () => {
190
203
} ) ;
191
204
192
205
it ( 'should create cache directory if it does not exist' , async ( ) => {
193
- const configLoader = new ConfigLoader ( { } ) ;
206
+ configLoader = new ConfigLoader ( { } ) ;
194
207
await configLoader . initialize ( ) ;
195
208
196
209
// Check if directory exists
@@ -214,7 +227,7 @@ describe('ConfigLoader', () => {
214
227
} ,
215
228
} ;
216
229
217
- const configLoader = new ConfigLoader ( mockConfig ) ;
230
+ configLoader = new ConfigLoader ( mockConfig ) ;
218
231
const spy = sinon . spy ( configLoader , 'reloadConfiguration' ) ;
219
232
await configLoader . start ( ) ;
220
233
@@ -235,7 +248,7 @@ describe('ConfigLoader', () => {
235
248
} ,
236
249
} ;
237
250
238
- const configLoader = new ConfigLoader ( mockConfig ) ;
251
+ configLoader = new ConfigLoader ( mockConfig ) ;
239
252
configLoader . reloadTimer = setInterval ( ( ) => { } , 1000 ) ;
240
253
await configLoader . start ( ) ;
241
254
@@ -257,7 +270,7 @@ describe('ConfigLoader', () => {
257
270
} ,
258
271
} ;
259
272
260
- const configLoader = new ConfigLoader ( mockConfig ) ;
273
+ configLoader = new ConfigLoader ( mockConfig ) ;
261
274
const spy = sinon . spy ( configLoader , 'reloadConfiguration' ) ;
262
275
await configLoader . start ( ) ;
263
276
@@ -281,7 +294,7 @@ describe('ConfigLoader', () => {
281
294
} ,
282
295
} ;
283
296
284
- const configLoader = new ConfigLoader ( mockConfig ) ;
297
+ configLoader = new ConfigLoader ( mockConfig ) ;
285
298
configLoader . reloadTimer = setInterval ( ( ) => { } , 1000 ) ;
286
299
expect ( configLoader . reloadTimer ) . to . not . be . null ;
287
300
@@ -291,7 +304,6 @@ describe('ConfigLoader', () => {
291
304
} ) ;
292
305
293
306
describe ( 'loadRemoteConfig' , ( ) => {
294
- let configLoader ;
295
307
beforeEach ( async ( ) => {
296
308
const configFilePath = path . join ( __dirname , '..' , 'proxy.config.json' ) ;
297
309
const config = JSON . parse ( fs . readFileSync ( configFilePath , 'utf-8' ) ) ;
@@ -379,7 +391,7 @@ describe('ConfigLoader', () => {
379
391
branch : 'main' ,
380
392
enabled : true ,
381
393
} ;
382
-
394
+
383
395
try {
384
396
await configLoader . loadFromSource ( source ) ;
385
397
throw new Error ( 'Expected error was not thrown' ) ;
0 commit comments