Add tests for config module and extract loadConfigFrom for testability#277
Open
coding-creed-technologies wants to merge 1 commit into
Open
Conversation
Add unit tests for all exported functions in config.ts. To make the configuration loading logic easier to test, `loadConfig` was refactored by extracting the file-loading logic into a new `loadConfigFrom(configPath)` function. This allows tests to provide custom config file paths without mocking `getConfigPath`. Tests cover: - getConfigPath - loadConfig - loadConfigFrom - saveConfig - resolvePath - createConfig They verify config loading, default merging, treasury validation, path resolution, and config persistence behavior. The refactor does not change runtime behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds unit tests for the configuration module and introduces a small refactor to make the loading logic easier to test.
loadConfigwas split so the file parsing logic is handled by a new function:loadConfigFrom(configPath: string)This allows tests to provide custom config files directly without mocking
getConfigPath.Changes
config.tsloadConfigFromfromloadConfigsaveConfigresolvePathcreateConfigTest Isolation
To make the tests deterministic and independent of the runtime environment:
fs) are mocked.wallet.tswas added so thatgetAutomatonDir()can be controlled during tests.This allows the configuration logic to be tested without relying on the real user environment.
Notes
The refactor is purely structural and does not change runtime behavior.
Impact
Improves test coverage and makes the configuration logic easier to maintain and refactor safely.
Attribution
This contribution was generated with assistance from 3TG
3TG is a behavior-first test generation tool for TypeScript functions that creates clean, maintainable tests and improves developer productivity.