diff --git a/index.js b/index.js index 34cc70e..5d82f2e 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ function readAsJSON(fileName) { function yamlMerge(...from) { const files = from.map((path) => readAsJSON(path)); - const outputJSON = _.assign({}, ...files); + const outputJSON = _.merge({}, ...files); return jsYaml.dump(outputJSON); } diff --git a/test/fixtures/merge/a.yml b/test/fixtures/merge/a.yml new file mode 100644 index 0000000..dc12cff --- /dev/null +++ b/test/fixtures/merge/a.yml @@ -0,0 +1,3 @@ +key: + first_value: a + diff --git a/test/fixtures/merge/b.yml b/test/fixtures/merge/b.yml new file mode 100644 index 0000000..3f7708f --- /dev/null +++ b/test/fixtures/merge/b.yml @@ -0,0 +1,3 @@ +key: + second_value: b + diff --git a/test/lib-test.js b/test/lib-test.js index c74e16e..e7be997 100644 --- a/test/lib-test.js +++ b/test/lib-test.js @@ -31,5 +31,15 @@ describe('merge logic', function() { value: c ` + '\n'); }); + + it('allows keys to trickle in from all merge sources', function () { + const output = merge(...fixtureFiles('merge/a.yml', 'merge/b.yml')); + + expect(output).to.equal(stripIndent` + key: + first_value: a + second_value: b + ` + '\n'); + }); });