Skip to content

Commit 438ec02

Browse files
committed
test: add test for ConfigLoader loading in progress
1 parent fc6f166 commit 438ec02

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/ConfigLoader.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,38 @@ 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+
121153
it('should not emit event if config has not changed', async () => {
122154
const testConfig = {
123155
proxyUrl: 'https://test.com',

0 commit comments

Comments
 (0)