Skip to content

Commit 7214ba4

Browse files
committed
test: onConflict: extend and onConflict: hardReset test
1 parent d4e0db8 commit 7214ba4

File tree

1 file changed

+119
-25
lines changed

1 file changed

+119
-25
lines changed

packages/yarnpkg-core/tests/Configuration.test.ts

Lines changed: 119 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ describe(`Configuration`, () => {
474474
});
475475

476476
describe(`Multiple RC files`, () => {
477-
it(`it should correctly extend or reset or skip the values`, async() => {
477+
it(`it should correctly resolve the rc files`, async() => {
478478
const {plugins, pluginConfiguration} = await initConfigurationPlugin(`{
479479
string: {
480480
description: "",
@@ -486,7 +486,12 @@ describe(`Configuration`, () => {
486486
type: "STRING",
487487
default: "",
488488
},
489-
stringSkip: {
489+
stringExtend: {
490+
description: "",
491+
type: "STRING",
492+
default: "",
493+
},
494+
stringHardReset: {
490495
description: "",
491496
type: "STRING",
492497
default: "",
@@ -503,7 +508,13 @@ describe(`Configuration`, () => {
503508
isArray: true,
504509
default: [],
505510
},
506-
stringArraySkip: {
511+
stringArrayExtend: {
512+
description: "",
513+
type: "STRING",
514+
isArray: true,
515+
default: [],
516+
},
517+
stringArrayHardReset: {
507518
description: "",
508519
type: "STRING",
509520
isArray: true,
@@ -541,7 +552,23 @@ describe(`Configuration`, () => {
541552
},
542553
},
543554
},
544-
shapeSkip: {
555+
shapeExtend: {
556+
description: "",
557+
type: "SHAPE",
558+
properties: {
559+
number: {
560+
description: "",
561+
type: "NUMBER",
562+
default: 0,
563+
},
564+
string: {
565+
description: "",
566+
type: "STRING",
567+
default: "default",
568+
},
569+
},
570+
},
571+
shapeHardReset: {
545572
description: "",
546573
type: "SHAPE",
547574
properties: {
@@ -597,7 +624,27 @@ describe(`Configuration`, () => {
597624
},
598625
},
599626
},
600-
mapSkip: {
627+
mapExtend: {
628+
description: "",
629+
type: "MAP",
630+
valueDefinition: {
631+
description: "",
632+
type: "SHAPE",
633+
properties: {
634+
number: {
635+
description: "",
636+
type: "NUMBER",
637+
default: 0,
638+
},
639+
string: {
640+
description: "",
641+
type: "STRING",
642+
default: "default",
643+
},
644+
},
645+
},
646+
},
647+
mapHardReset: {
601648
description: "",
602649
type: "MAP",
603650
valueDefinition: {
@@ -623,17 +670,22 @@ describe(`Configuration`, () => {
623670
plugins,
624671
string: `foo`,
625672
stringReset: `foo`,
626-
stringSkip: `foo`,
673+
stringExtend: `foo`,
674+
stringHardReset: `foo`,
627675
stringArray: [`foo`],
628676
stringArrayReset: [`foo`],
629-
stringArraySkip: [`foo`],
677+
stringArrayExtend: [`foo`],
678+
stringArrayHardReset: [`foo`],
630679
shape: {
631680
string: `foo`,
632681
},
633682
shapeReset: {
634683
string: `foo`,
635684
},
636-
shapeSkip: {
685+
shapeExtend: {
686+
string: `foo`,
687+
},
688+
shapeHardReset: {
637689
string: `foo`,
638690
},
639691
map: {
@@ -642,30 +694,40 @@ describe(`Configuration`, () => {
642694
mapReset: {
643695
foo: {string: `foo`},
644696
},
645-
mapSkip: {
697+
mapExtend: {
698+
foo: {string: `foo`},
699+
},
700+
mapHardReset: {
646701
foo: {string: `foo`},
647702
},
648703
}, async dir => {
649704
const workspaceDirectory = `${dir}/workspace` as PortablePath;
650-
651705
await xfs.mkdirPromise(workspaceDirectory);
652706
await xfs.writeFilePromise(`${workspaceDirectory}/.yarnrc.yml` as PortablePath, stringifySyml({
653707
string: `bar`,
654708
stringReset: {
655709
onConflict: `reset`,
656710
value: `bar`,
657711
},
658-
stringSkip: {
659-
onConflict: `skip`,
712+
stringExtend: {
713+
onConflict: `extend`,
714+
value: `bar`,
715+
},
716+
stringHardReset: {
717+
onConflict: `reset`,
660718
value: `bar`,
661719
},
662720
stringArray: [`bar`],
663721
stringArrayReset: {
664722
onConflict: `reset`,
665723
value: [`bar`],
666724
},
667-
stringArraySkip: {
668-
onConflict: `skip`,
725+
stringArrayExtend: {
726+
onConflict: `extend`,
727+
value: [`bar`],
728+
},
729+
stringArrayHardReset: {
730+
onConflict: `hardReset`,
669731
value: [`bar`],
670732
},
671733
shape: {
@@ -677,8 +739,14 @@ describe(`Configuration`, () => {
677739
number: 2,
678740
},
679741
},
680-
shapeSkip: {
681-
onConflict: `skip`,
742+
shapeExtend: {
743+
onConflict: `extend`,
744+
value: {
745+
number: 2,
746+
},
747+
},
748+
shapeHardReset: {
749+
onConflict: `hardReset`,
682750
value: {
683751
number: 2,
684752
},
@@ -692,37 +760,63 @@ describe(`Configuration`, () => {
692760
bar: {number: 2, string: `bar`},
693761
},
694762
},
695-
mapSkip: {
696-
onConflict: `skip`,
763+
mapExtend: {
764+
onConflict: `extend`,
765+
value: {
766+
bar: {number: 2, string: `bar`},
767+
},
768+
},
769+
mapHardReset: {
770+
onConflict: `hardReset`,
697771
value: {
698772
bar: {number: 2, string: `bar`},
699773
},
700774
},
701775
}));
702776

703-
const configuration = await Configuration.find(workspaceDirectory, pluginConfiguration);
777+
const workspaceDirectory2 = `${dir}/workspace/workspace` as PortablePath;
778+
await xfs.mkdirPromise(workspaceDirectory2);
779+
await xfs.writeFilePromise(`${workspaceDirectory2}/.yarnrc.yml` as PortablePath, stringifySyml({
780+
stringHardReset: `baz`,
781+
stringArrayHardReset: [`baz`],
782+
shapeHardReset: {
783+
string: `baz`,
784+
},
785+
mapHardReset: {
786+
baz: {string: `baz`},
787+
},
788+
}));
789+
790+
const configuration = await Configuration.find(workspaceDirectory2, pluginConfiguration);
704791

705792
expect(configuration.get(`string`)).toBe(`bar`);
706793
expect(configuration.get(`stringReset`)).toBe(`bar`);
707-
expect(configuration.get(`stringSkip`)).toBe(`foo`);
794+
expect(configuration.get(`stringExtend`)).toBe(`bar`);
795+
expect(configuration.get(`stringHardReset`)).toBe(`baz`);
796+
708797
expect(configuration.get(`stringArray`)).toEqual([`foo`, `bar`]);
709798
expect(configuration.get(`stringArrayReset`)).toEqual([`bar`]);
710-
expect(configuration.get(`stringArraySkip`)).toEqual([`foo`]);
799+
expect(configuration.get(`stringArrayExtend`)).toEqual([`foo`, `bar`]);
800+
expect(configuration.get(`stringArrayHardReset`)).toEqual([`baz`]);
801+
711802
expect(configuration.get(`shape`)).toEqual(new Map<string, any>([[`number`, 2], [`string`, `foo`]]));
712803
expect(configuration.get(`shapeReset`)).toEqual(new Map<string, any>([[`number`, 2], [`string`, `default`]]));
713-
expect(configuration.get(`shapeSkip`)).toEqual(new Map<string, any>([[`number`, 0], [`string`, `foo`]]));
804+
expect(configuration.get(`shapeExtend`)).toEqual(new Map<string, any>([[`number`, 2], [`string`, `foo`]]));
805+
expect(configuration.get(`shapeHardReset`)).toEqual(new Map<string, any>([[`number`, 0], [`string`, `baz`]]));
714806

715807
expect(configuration.get(`map`)).toEqual(new Map([
716808
[`foo`, new Map<string, any>([[`number`, 0], [`string`, `foo`]])],
717809
[`bar`, new Map<string, any>([[`number`, 2], [`string`, `bar`]])],
718810
]));
719-
720811
expect(configuration.get(`mapReset`)).toEqual(new Map([
721812
[`bar`, new Map<string, any>([[`number`, 2], [`string`, `bar`]])],
722813
]));
723-
724-
expect(configuration.get(`mapSkip`)).toEqual(new Map([
814+
expect(configuration.get(`mapExtend`)).toEqual(new Map([
725815
[`foo`, new Map<string, any>([[`number`, 0], [`string`, `foo`]])],
816+
[`bar`, new Map<string, any>([[`number`, 2], [`string`, `bar`]])],
817+
]));
818+
expect(configuration.get(`mapHardReset`)).toEqual(new Map([
819+
[`baz`, new Map<string, any>([[`number`, 0], [`string`, `baz`]])],
726820
]));
727821
});
728822
});

0 commit comments

Comments
 (0)