mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-04 03:41:54 +00:00
Add unit tests for loadTorchConfig with dependency injection
Refactored `loadTorchConfig` to support dependency injection for `fs`, enabling true unit tests without disk I/O. Added comprehensive unit tests in `test/torch-config-unit.test.mjs`. - Refactored `loadTorchConfig` to accept optional `fileSystem` argument. - Created `test/torch-config-unit.test.mjs` with mocked fs tests. - Verified existing tests pass. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
695adb6dc9
commit
3a48c76a6c
2 files changed
+74
-3
No files matched your search
@@ -84,15 +84,15 @@ export function _resetTorchConfigCache() {
|
||||
cachedConfig = null;
|
||||
}
|
||||
|
||||
export function loadTorchConfig() {
|
||||
export function loadTorchConfig(fileSystem = fs) {
|
||||
if (cachedConfig) return cachedConfig;
|
||||
|
||||
const configPath = getTorchConfigPath();
|
||||
let raw = {};
|
||||
|
||||
if (fs.existsSync(configPath)) {
|
||||
if (fileSystem.existsSync(configPath)) {
|
||||
try {
|
||||
raw = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
raw = JSON.parse(fileSystem.readFileSync(configPath, 'utf8'));
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to parse ${configPath}: ${err.message}`, { cause: err });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user