|
1 | | -import { getAvailableCommands, resolveCommandOptions } from '../config-file'; |
| 1 | +import { getAvailableCommands, mergeConfigFiles, resolveCommandOptions } from '../config-file'; |
2 | 2 |
|
3 | 3 | describe('resolveCommandOptions', () => { |
4 | 4 | it('should return null for an unknown command', () => { |
@@ -117,6 +117,55 @@ describe('resolveCommandOptions', () => { |
117 | 117 | }); |
118 | 118 | }); |
119 | 119 |
|
| 120 | +describe('mergeConfigFiles', () => { |
| 121 | + it('should merge sections by field, not replace them', () => { |
| 122 | + const merged = mergeConfigFiles( |
| 123 | + { docker: { registry: 'registry.example', baseImage: 'base:1.0.0' } }, |
| 124 | + { docker: { baseImage: 'base:2.0.0' } }, |
| 125 | + ); |
| 126 | + |
| 127 | + expect(merged).toEqual({ |
| 128 | + docker: { registry: 'registry.example', baseImage: 'base:2.0.0' }, |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should merge commands by name and keep the ones declared only once', () => { |
| 133 | + const merged = mergeConfigFiles( |
| 134 | + { |
| 135 | + commands: { |
| 136 | + 'archive-build': { build: { removeDevDependencies: true } }, |
| 137 | + 'docker-build': { serverPort: 3000 }, |
| 138 | + }, |
| 139 | + }, |
| 140 | + { |
| 141 | + commands: { |
| 142 | + 'archive-build': { archive: { name: 'app.tar' } }, |
| 143 | + 'docker-build:server': { artifact: 'docker' }, |
| 144 | + }, |
| 145 | + }, |
| 146 | + ); |
| 147 | + |
| 148 | + expect(merged.commands).toEqual({ |
| 149 | + 'archive-build': { |
| 150 | + build: { removeDevDependencies: true }, |
| 151 | + archive: { name: 'app.tar' }, |
| 152 | + }, |
| 153 | + 'docker-build': { serverPort: 3000 }, |
| 154 | + 'docker-build:server': { artifact: 'docker' }, |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + it('should not add an empty commands section', () => { |
| 159 | + expect(mergeConfigFiles({ serverPort: 3000 }, {})).not.toHaveProperty('commands'); |
| 160 | + }); |
| 161 | + |
| 162 | + it('should let the last config win for scalar options', () => { |
| 163 | + expect(mergeConfigFiles({ serverPort: 3000 }, { serverPort: 4000 })).toEqual({ |
| 164 | + serverPort: 4000, |
| 165 | + }); |
| 166 | + }); |
| 167 | +}); |
| 168 | + |
120 | 169 | describe('getAvailableCommands', () => { |
121 | 170 | it('should list built-in and declared commands without duplicates', () => { |
122 | 171 | const commands = getAvailableCommands({ |
|
0 commit comments