Skip to content

Commit a30faaa

Browse files
committed
test: add test for initial config load and remove unused test
1 parent 438ec02 commit a30faaa

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

test/ConfigLoader.test.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,6 @@ describe('ConfigLoader', () => {
118118
expect(spy.firstCall.args[0]).to.deep.include(newConfig);
119119
});
120120

121-
it('should emit a single event when config changes', async () => {
122-
const initialConfig = {
123-
configurationSources: {
124-
enabled: true,
125-
sources: [
126-
{
127-
type: 'file',
128-
enabled: true,
129-
path: tempConfigFile,
130-
},
131-
],
132-
reloadIntervalSeconds: 0,
133-
},
134-
};
135-
136-
const newConfig = {
137-
proxyUrl: 'https://new-test.com',
138-
};
139-
140-
fs.writeFileSync(tempConfigFile, JSON.stringify(newConfig));
141-
142-
configLoader = new ConfigLoader(initialConfig);
143-
const spy = sinon.spy();
144-
configLoader.on('configurationChanged', spy);
145-
146-
await configLoader.reloadConfiguration();
147-
await configLoader.reloadConfiguration();
148-
149-
expect(spy.calledOnce).to.be.true;
150-
expect(spy.firstCall.args[0]).to.deep.include(newConfig);
151-
});
152-
153121
it('should not emit event if config has not changed', async () => {
154122
const testConfig = {
155123
proxyUrl: 'https://test.com',
@@ -212,9 +180,29 @@ describe('ConfigLoader', () => {
212180
// Check if directory exists
213181
expect(fs.existsSync(configLoader.cacheDir)).to.be.true;
214182
});
215-
});
216183

217-
describe('loadRemoteConfig', () => {
184+
it('should perform initial load on start if configurationSources is enabled', async () => {
185+
const mockConfig = {
186+
configurationSources: {
187+
enabled: true,
188+
sources: [
189+
{
190+
type: 'file',
191+
enabled: true,
192+
path: tempConfigFile,
193+
},
194+
],
195+
reloadIntervalSeconds: 30,
196+
},
197+
};
198+
199+
const configLoader = new ConfigLoader(mockConfig);
200+
const spy = sinon.spy(configLoader, 'reloadConfiguration');
201+
await configLoader.start();
202+
203+
expect(spy.calledOnce).to.be.true;
204+
});
205+
});
218206
let configLoader;
219207
beforeEach(async () => {
220208
const configFilePath = path.join(__dirname, '..', 'proxy.config.json');

0 commit comments

Comments
 (0)