Skip to content

Commit 6d0a90d

Browse files
authored
Merge pull request #1050 from kriswest/1049-fix-config-loader-tests
2 parents 67663a9 + 174baae commit 6d0a90d

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

test/ConfigLoader.test.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import { configFile } from '../src/config/file';
34
import { expect } from 'chai';
45
import { ConfigLoader } from '../src/config/ConfigLoader';
56
import { isValidGitUrl, isValidPath, isValidBranchName } from '../src/config/ConfigLoader';
@@ -23,6 +24,18 @@ describe('ConfigLoader', () => {
2324
fs.rmSync(tempDir, { recursive: true });
2425
}
2526
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+
});
2639
});
2740

2841
describe('loadFromFile', () => {
@@ -168,7 +181,7 @@ describe('ConfigLoader', () => {
168181

169182
describe('initialize', () => {
170183
it('should initialize cache directory using env-paths', async () => {
171-
const configLoader = new ConfigLoader({});
184+
configLoader = new ConfigLoader({});
172185
await configLoader.initialize();
173186

174187
// Check that cacheDir is set and is a string
@@ -190,7 +203,7 @@ describe('ConfigLoader', () => {
190203
});
191204

192205
it('should create cache directory if it does not exist', async () => {
193-
const configLoader = new ConfigLoader({});
206+
configLoader = new ConfigLoader({});
194207
await configLoader.initialize();
195208

196209
// Check if directory exists
@@ -214,7 +227,7 @@ describe('ConfigLoader', () => {
214227
},
215228
};
216229

217-
const configLoader = new ConfigLoader(mockConfig);
230+
configLoader = new ConfigLoader(mockConfig);
218231
const spy = sinon.spy(configLoader, 'reloadConfiguration');
219232
await configLoader.start();
220233

@@ -235,7 +248,7 @@ describe('ConfigLoader', () => {
235248
},
236249
};
237250

238-
const configLoader = new ConfigLoader(mockConfig);
251+
configLoader = new ConfigLoader(mockConfig);
239252
configLoader.reloadTimer = setInterval(() => {}, 1000);
240253
await configLoader.start();
241254

@@ -257,7 +270,7 @@ describe('ConfigLoader', () => {
257270
},
258271
};
259272

260-
const configLoader = new ConfigLoader(mockConfig);
273+
configLoader = new ConfigLoader(mockConfig);
261274
const spy = sinon.spy(configLoader, 'reloadConfiguration');
262275
await configLoader.start();
263276

@@ -281,7 +294,7 @@ describe('ConfigLoader', () => {
281294
},
282295
};
283296

284-
const configLoader = new ConfigLoader(mockConfig);
297+
configLoader = new ConfigLoader(mockConfig);
285298
configLoader.reloadTimer = setInterval(() => {}, 1000);
286299
expect(configLoader.reloadTimer).to.not.be.null;
287300

@@ -291,7 +304,6 @@ describe('ConfigLoader', () => {
291304
});
292305

293306
describe('loadRemoteConfig', () => {
294-
let configLoader;
295307
beforeEach(async () => {
296308
const configFilePath = path.join(__dirname, '..', 'proxy.config.json');
297309
const config = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'));
@@ -379,7 +391,7 @@ describe('ConfigLoader', () => {
379391
branch: 'main',
380392
enabled: true,
381393
};
382-
394+
383395
try {
384396
await configLoader.loadFromSource(source);
385397
throw new Error('Expected error was not thrown');

0 commit comments

Comments
 (0)