Skip to content

Commit

Permalink
Add deep merge test and merge_env_config utility
Browse files Browse the repository at this point in the history
- Implemented test for deep_merge_no_overwrite with nested objects
- Created merge_env_config utility for flexible environment configuration merging
- Supports array concatenation and non-destructive object merging
- Added warning for overwriting existing configuration properties
  • Loading branch information
Brian Joseph Petro committed Feb 21, 2025
1 parent c116a8b commit ec3f045
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions smart-environment/utils/deep_merge_no_overwrite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,28 @@ test('is_plain_object checks for simple object types', (t) => {
t.false(is_plain_object(null), 'null returns false');
t.false(is_plain_object(new Date()), 'Date object returns false');
});

test('deep_merge_no_overwrite handles deeply nested objects', (t) => {
const target = {
a: {
b: {
c: {
d: 'existing',
},
},
},
};
const source = {
a: {
b: {
c: {
e: 'new',
},
},
},
};

deep_merge_no_overwrite(target, source);
t.is(target.a.b.c.d, 'existing', 'existing key d remains');
t.is(target.a.b.c.e, 'new', 'new key e merged');
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deep_merge_no_overwrite } from './deep_merge_no_overwrite.js';

export function merge_options(target, incoming) {
export function merge_env_config(target, incoming) {
for (const [key, value] of Object.entries(incoming)) {
if (key === 'global_ref') continue;
if (typeof value === 'object' && value !== null) {
Expand Down

0 comments on commit ec3f045

Please sign in to comment.