Skip to content

Commit

Permalink
fix(core-kernel): override array on merge (#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner authored Jan 21, 2021
1 parent 2f493d7 commit e9cee04
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
51 changes: 44 additions & 7 deletions __tests__/unit/core-kernel/providers/plugin-configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ describe("PluginConfiguration", () => {
expect(pluginConfiguration.all()).toEqual({ defaultKey: "defaultValue" });
});

it("should merge the given value", () => {
pluginConfiguration.set("key", "value");
pluginConfiguration.merge({ some: "value" });

expect(pluginConfiguration.all()).toEqual({ some: "value", key: "value" });
});

it("should set and get the given value", () => {
pluginConfiguration.set("key", "value");

Expand All @@ -59,4 +52,48 @@ describe("PluginConfiguration", () => {
it("should throw when using deprecated get default value argument", () => {
expect(() => pluginConfiguration.get("key", "default value")).toThrow();
});

describe("merge", () => {
it("should merge the given value", () => {
pluginConfiguration.set("key", "value");
pluginConfiguration.merge({ some: "value" });

expect(pluginConfiguration.all()).toEqual({ some: "value", key: "value" });
});

it("should merge nested object", () => {
pluginConfiguration.set("key", {
"1": {
"1.1": "test",
},
});
pluginConfiguration.merge({
key: {
"1": {
"1.2": "test",
},
},
});

expect(pluginConfiguration.all()).toEqual({
key: {
"1": {
"1.1": "test",
"1.2": "test",
},
},
});
});

it("should override array", () => {
pluginConfiguration.set("key", [1, 2, 3]);
pluginConfiguration.merge({
key: [3, 4, 5],
});

expect(pluginConfiguration.all()).toEqual({
key: [3, 4, 5],
});
});
});
});
4 changes: 3 additions & 1 deletion packages/core-kernel/src/providers/plugin-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class PluginConfiguration {
*/
public merge(values: JsonObject | undefined): this {
if (values) {
this.items = deepmerge(this.items, values);
this.items = deepmerge(this.items, values, {
arrayMerge: (destination, source) => source,
});
}

return this;
Expand Down

0 comments on commit e9cee04

Please sign in to comment.