Skip to content

Commit 098db65

Browse files
committed
test: increase test coverage
1 parent ba40989 commit 098db65

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

test/ConfigLoader.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ describe('ConfigLoader', () => {
206206
}
207207
});
208208

209+
it('should return cacheDirPath via getter', async () => {
210+
configLoader = new ConfigLoader({});
211+
await configLoader.initialize();
212+
213+
const cacheDirPath = configLoader.cacheDirPath;
214+
expect(cacheDirPath).to.equal(configLoader.cacheDir);
215+
expect(cacheDirPath).to.be.a('string');
216+
});
217+
209218
it('should create cache directory if it does not exist', async () => {
210219
configLoader = new ConfigLoader({});
211220
await configLoader.initialize();

test/testConfig.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,56 @@ describe('validate config files', function () {
399399
}
400400
});
401401

402+
it('should validate using default config file when no path provided', function () {
403+
const originalConfigFile = config.configFile;
404+
const mainConfigPath = path.join(__dirname, '..', 'proxy.config.json');
405+
config.setConfigFile(mainConfigPath);
406+
407+
try {
408+
// default configFile
409+
expect(() => config.validate()).to.not.throw();
410+
} finally {
411+
// Restore original config file
412+
config.setConfigFile(originalConfigFile);
413+
}
414+
});
415+
402416
after(function () {
403417
delete require.cache[require.resolve('../src/config')];
404418
});
405419
});
406420

421+
describe('setConfigFile function', function () {
422+
const config = require('../src/config/file');
423+
let originalConfigFile;
424+
425+
beforeEach(function () {
426+
originalConfigFile = config.configFile;
427+
});
428+
429+
afterEach(function () {
430+
// Restore original config file
431+
config.setConfigFile(originalConfigFile);
432+
});
433+
434+
it('should set the config file path', function () {
435+
const newPath = '/tmp/new-config.json';
436+
config.setConfigFile(newPath);
437+
expect(config.configFile).to.equal(newPath);
438+
});
439+
440+
it('should allow changing config file multiple times', function () {
441+
const firstPath = '/tmp/first-config.json';
442+
const secondPath = '/tmp/second-config.json';
443+
444+
config.setConfigFile(firstPath);
445+
expect(config.configFile).to.equal(firstPath);
446+
447+
config.setConfigFile(secondPath);
448+
expect(config.configFile).to.equal(secondPath);
449+
});
450+
});
451+
407452
describe('Configuration Update Handling', function () {
408453
let tempDir;
409454
let tempUserFile;

0 commit comments

Comments
 (0)