Skip to content

test: stop the config loader and restore defaults after tests have run #1050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions test/ConfigLoader.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import { configFile } from '../src/config/file';
import { expect } from 'chai';
import { ConfigLoader } from '../src/config/ConfigLoader';
import { isValidGitUrl, isValidPath, isValidBranchName } from '../src/config/ConfigLoader';
Expand All @@ -23,6 +24,18 @@ describe('ConfigLoader', () => {
fs.rmSync(tempDir, { recursive: true });
}
sinon.restore();
configLoader?.stop();
});

after(async () => {
// reset config to default after all tests have run
console.log(`Restoring config to defaults from file ${configFile}`);
configLoader = new ConfigLoader({});
await configLoader.loadFromFile({
type: 'file',
enabled: true,
path: configFile,
});
});

describe('loadFromFile', () => {
Expand Down Expand Up @@ -168,7 +181,7 @@ describe('ConfigLoader', () => {

describe('initialize', () => {
it('should initialize cache directory using env-paths', async () => {
const configLoader = new ConfigLoader({});
configLoader = new ConfigLoader({});
await configLoader.initialize();

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

it('should create cache directory if it does not exist', async () => {
const configLoader = new ConfigLoader({});
configLoader = new ConfigLoader({});
await configLoader.initialize();

// Check if directory exists
Expand All @@ -214,7 +227,7 @@ describe('ConfigLoader', () => {
},
};

const configLoader = new ConfigLoader(mockConfig);
configLoader = new ConfigLoader(mockConfig);
const spy = sinon.spy(configLoader, 'reloadConfiguration');
await configLoader.start();

Expand All @@ -235,7 +248,7 @@ describe('ConfigLoader', () => {
},
};

const configLoader = new ConfigLoader(mockConfig);
configLoader = new ConfigLoader(mockConfig);
configLoader.reloadTimer = setInterval(() => {}, 1000);
await configLoader.start();

Expand All @@ -257,7 +270,7 @@ describe('ConfigLoader', () => {
},
};

const configLoader = new ConfigLoader(mockConfig);
configLoader = new ConfigLoader(mockConfig);
const spy = sinon.spy(configLoader, 'reloadConfiguration');
await configLoader.start();

Expand All @@ -281,7 +294,7 @@ describe('ConfigLoader', () => {
},
};

const configLoader = new ConfigLoader(mockConfig);
configLoader = new ConfigLoader(mockConfig);
configLoader.reloadTimer = setInterval(() => {}, 1000);
expect(configLoader.reloadTimer).to.not.be.null;

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

describe('loadRemoteConfig', () => {
let configLoader;
beforeEach(async () => {
const configFilePath = path.join(__dirname, '..', 'proxy.config.json');
const config = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'));
Expand Down Expand Up @@ -379,7 +391,7 @@ describe('ConfigLoader', () => {
branch: 'main',
enabled: true,
};

try {
await configLoader.loadFromSource(source);
throw new Error('Expected error was not thrown');
Expand Down
Loading