Quellcode durchsuchen

test(core): Add test for mergeConfig array handling

Michael Bromley vor 4 Jahren
Ursprung
Commit
696e8e27ad

+ 11 - 0
packages/core/src/config/merge-config.spec.ts

@@ -29,6 +29,17 @@ describe('mergeConfig()', () => {
         });
     });
 
+    it('does not merge arrays', () => {
+        const input: any = {
+            a: [1],
+        };
+
+        const result = mergeConfig(input, { a: [2] } as any);
+        expect(result).toEqual({
+            a: [2],
+        });
+    });
+
     it('merges deep properties', () => {
         const input: any = {
             a: 1,

+ 7 - 0
packages/core/src/config/merge-config.ts

@@ -9,12 +9,19 @@ import { PartialVendureConfig, VendureConfig } from './vendure-config';
  * not mutated, instead the function returns a new object which is the result of deeply merging the
  * values of `source` into `target`.
  *
+ * Arrays do not get merged, they are treated as a single value that will be replaced. So if merging the
+ * `plugins` array, you must explicitly concatenate the array.
+ *
  * @example
  * ```TypeScript
  * const result = mergeConfig(defaultConfig, {
  *   assetOptions: {
  *     uploadMaxFileSize: 5000,
  *   },
+ *   plugins: [
+ *     ...defaultConfig.plugins,
+ *     MyPlugin,
+ *   ]
  * };
  * ```
  *