test: add unit tests for config-loader module#277
test: add unit tests for config-loader module#277nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
Conversation
|
@nikolasdehor is attempting to deploy a commit to the Pedro Valério Lopez's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds Jest unit test coverage for the legacy core/config/config-loader module, focusing on its lazy-loading behavior, caching, agent-specific section selection, validation, and performance metrics (per Issue #276).
Changes:
- Added a new test suite covering exported constants and all exported loader/utility functions.
- Added coverage for cache hit/miss behavior, unknown-agent fallbacks, and error logging/throwing paths.
- Added basic assertions around performance metrics shape/format.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| describe('config-loader', () => { | ||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| jest.spyOn(console, 'log').mockImplementation(); | ||
| jest.spyOn(console, 'error').mockImplementation(); | ||
| // Clear cache between tests | ||
| clearCache(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
console.log/console.error are spied in beforeEach but never restored. Even though Jest isolates test files, leaving spies active for the whole suite can cause confusing interactions within this file (and is inconsistent with other tests that call jest.restoreAllMocks() / mockRestore() in afterEach). Add an afterEach to restore mocks/spies (or store the spies and call mockRestore() on them).
| describe('config-loader', () => { | |
| beforeEach(() => { | |
| jest.resetAllMocks(); | |
| jest.spyOn(console, 'log').mockImplementation(); | |
| jest.spyOn(console, 'error').mockImplementation(); | |
| // Clear cache between tests | |
| clearCache(); | |
| }); | |
| let consoleLogSpy; | |
| let consoleErrorSpy; | |
| describe('config-loader', () => { | |
| beforeEach(() => { | |
| jest.resetAllMocks(); | |
| consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(); | |
| consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); | |
| // Clear cache between tests | |
| clearCache(); | |
| }); | |
| afterEach(() => { | |
| if (consoleLogSpy && typeof consoleLogSpy.mockRestore === 'function') { | |
| consoleLogSpy.mockRestore(); | |
| } | |
| if (consoleErrorSpy && typeof consoleErrorSpy.mockRestore === 'function') { | |
| consoleErrorSpy.mockRestore(); | |
| } | |
| }); |
| test('logs error message on failure', async () => { | ||
| fs.readFile.mockRejectedValue(new Error('ENOENT')); | ||
|
|
||
| try { await loadFullConfig(); } catch {} |
There was a problem hiding this comment.
Avoid the empty catch {} block here: it triggers the ESLint no-empty rule and can hide unexpected failures. You can keep the intent (assert logging) by using await expect(loadFullConfig()).rejects.toThrow(...) and then asserting console.error was called, or by providing a non-empty catch handler.
| try { await loadFullConfig(); } catch {} | |
| await expect(loadFullConfig()).rejects.toThrow('Config load failed'); |
|
Consolidated into #424 |
Summary
core/config/config-loadermoduleTest Coverage
Test Plan
Closes #276