Skip to content

Commit e22562a

Browse files
authored
Updates tests for the merge conflict resolution v5 (#6892)
## What's the problem this PR addresses? This PR updates the tests to account for changes in the v5+ releases, which will use `--theirs` as merge conflict resolution strategy to fix bugs in which users could end up erasing changes from the upstream branch when merging their own changes (due to us trying to override existing ranges). ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent 794f94b commit e22562a

File tree

3 files changed

+75
-167
lines changed

3 files changed

+75
-167
lines changed

packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function isAtLeastMajor(major: number) {
3838
export const FEATURE_CHECKS = {
3939
jsonLockfile: isAtLeastMajor(5),
4040
prologConstraints: !isAtLeastMajor(5),
41+
mergeConflictTheirs: isAtLeastMajor(5),
4142
} as const;
4243

4344
// Testing things inside a big-endian container takes forever

packages/acceptance-tests/pkg-tests-specs/sources/features/__snapshots__/mergeConflictResolution.test.ts.snap

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts 1`] = `
4-
"# This file is generated by running "yarn install" inside your project.
5-
# Manual changes might be lost - proceed with caution!
6-
7-
__metadata:
8-
version: X
9-
cacheKey: 0c0
10-
11-
"no-deps@npm:*":
12-
<<<<<<< HEAD
13-
version: 1.0.0
14-
resolution: "no-deps@npm:1.0.0"
15-
checksum: <checksum stripped>
16-
=======
17-
version: 2.0.0
18-
resolution: "no-deps@npm:2.0.0"
19-
checksum: <checksum stripped>
20-
>>>>>>> 2.0.0
21-
languageName: node
22-
linkType: hard
23-
24-
"root-workspace-0b6124@workspace:.":
25-
version: 0.0.0-use.local
26-
resolution: "root-workspace-0b6124@workspace:."
27-
dependencies:
28-
no-deps: "npm:*"
29-
languageName: unknown
30-
linkType: soft
31-
"
32-
`;
33-
34-
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts 2`] = `
35-
{
36-
"code": 0,
37-
"stderr": "",
38-
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍
39-
40-
YN0000: · Yarn 0.0.0
41-
YN0000: ┌ Resolution step
42-
YN0000: └ Completed
43-
YN0000: ┌ Fetch step
44-
YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
45-
YN0000: └ Completed
46-
YN0000: ┌ Link step
47-
YN0000: └ Completed
48-
YN0000: · Done
49-
",
50-
}
51-
`;
52-
533
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 1`] = `
544
"# This file is generated by running "yarn install" inside your project.
555
# Manual changes might be lost - proceed with caution!
566
57-
__metadata:
58-
version: X
59-
cacheKey: 0c0
60-
617
<<<<<<< HEAD
628
no-deps@*:
639
version "2.0.0"
6410
resolved "http://localhost:64572/no-deps/-/no-deps-2.0.0.tgz#f3b8f24d76b21b04748e6888672752b872236fa7"
6511
integrity sha1-87jyTXayGwR0jmiIZydSuHIjb6c=
6612
=======
67-
"no-deps@npm:*":
68-
version: 2.0.0
69-
resolution: "no-deps@npm:2.0.0"
70-
checksum: <checksum stripped>
71-
languageName: node
72-
linkType: hard
73-
74-
"root-workspace-0b6124@workspace:.":
75-
version: 0.0.0-use.local
76-
resolution: "root-workspace-0b6124@workspace:."
77-
dependencies:
78-
no-deps: "npm:*"
79-
languageName: unknown
80-
linkType: soft
81-
>>>>>>> yarn2
82-
"
83-
`;
84-
85-
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 2`] = `
86-
{
87-
"code": 0,
88-
"stderr": "",
89-
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍
90-
91-
YN0000: · Yarn 0.0.0
92-
YN0000: ┌ Resolution step
93-
YN0000: └ Completed
94-
YN0000: ┌ Fetch step
95-
YN0000: └ Completed
96-
YN0000: ┌ Link step
97-
YN0000: └ Completed
98-
YN0000: · Done
99-
",
100-
}
101-
`;
102-
103-
exports[`Features Merge Conflict Resolution it should support fixing cherry-pick conflicts 1`] = `
104-
"# This file is generated by running "yarn install" inside your project.
105-
# Manual changes might be lost - proceed with caution!
106-
107-
__metadata:
108-
version: X
109-
cacheKey: 0c0
110-
111-
"no-deps@npm:*":
112-
<<<<<<< HEAD
113-
version: 1.0.0
114-
resolution: "no-deps@npm:1.0.0"
115-
checksum: <checksum stripped>
116-
=======
117-
version: 2.0.0
118-
resolution: "no-deps@npm:2.0.0"
119-
checksum: <checksum stripped>
120-
>>>>>>> 0000000 (commit-2.0.0)
121-
languageName: node
122-
linkType: hard
123-
124-
"root-workspace-0b6124@workspace:.":
125-
version: 0.0.0-use.local
126-
resolution: "root-workspace-0b6124@workspace:."
127-
dependencies:
128-
no-deps: "npm:*"
129-
languageName: unknown
130-
linkType: soft
131-
"
132-
`;
133-
134-
exports[`Features Merge Conflict Resolution it should support fixing cherry-pick conflicts 2`] = `
135-
{
136-
"code": 0,
137-
"stderr": "",
138-
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍
139-
140-
YN0000: · Yarn 0.0.0
141-
YN0000: ┌ Resolution step
142-
YN0000: └ Completed
143-
YN0000: ┌ Fetch step
144-
YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
145-
YN0000: └ Completed
146-
YN0000: ┌ Link step
147-
YN0000: └ Completed
148-
YN0000: · Done
149-
",
150-
}
151-
`;
152-
153-
exports[`Features Merge Conflict Resolution it should support fixing rebase conflicts 1`] = `
154-
"# This file is generated by running "yarn install" inside your project.
155-
# Manual changes might be lost - proceed with caution!
156-
15713
__metadata:
15814
version: X
15915
cacheKey: 0c0
16016
16117
"no-deps@npm:*":
162-
<<<<<<< HEAD
163-
version: 2.0.0
164-
resolution: "no-deps@npm:2.0.0"
165-
checksum: <checksum stripped>
166-
=======
16718
version: 1.0.0
16819
resolution: "no-deps@npm:1.0.0"
16920
checksum: <checksum stripped>
170-
>>>>>>> 0000000 (commit-1.0.0)
17121
languageName: node
17222
linkType: hard
17323
@@ -178,10 +28,11 @@ __metadata:
17828
no-deps: "npm:*"
17929
languageName: unknown
18030
linkType: soft
31+
>>>>>>> yarn2
18132
"
18233
`;
18334
184-
exports[`Features Merge Conflict Resolution it should support fixing rebase conflicts 2`] = `
35+
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 2`] = `
18536
{
18637
"code": 0,
18738
"stderr": "",
@@ -191,7 +42,6 @@ exports[`Features Merge Conflict Resolution it should support fixing rebase conf
19142
YN0000: ┌ Resolution step
19243
YN0000: └ Completed
19344
YN0000: ┌ Fetch step
194-
YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
19545
YN0000: └ Completed
19646
YN0000: ┌ Link step
19747
YN0000: └ Completed

packages/acceptance-tests/pkg-tests-specs/sources/features/mergeConflictResolution.test.ts

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Filename, ppath, xfs} from '@yarnpkg/fslib';
2-
import {exec} from 'pkg-tests-core';
2+
import {exec, tests} from 'pkg-tests-core';
33

44
const LOCKFILE_1_0_0 = `
55
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
@@ -9,7 +9,7 @@ no-deps@*:
99
version "1.0.0"
1010
resolved "http://localhost:64572/no-deps/-/no-deps-1.0.0.tgz#8d556c1e3e6c953ea16689c506073d5fa26b957f"
1111
integrity sha1-jVVsHj5slT6hZonFBgc9X6JrlX8=
12-
`;
12+
`.trimStart();
1313

1414
const LOCKFILE_2_0_0 = `
1515
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
@@ -19,7 +19,7 @@ no-deps@*:
1919
version "2.0.0"
2020
resolved "http://localhost:64572/no-deps/-/no-deps-2.0.0.tgz#f3b8f24d76b21b04748e6888672752b872236fa7"
2121
integrity sha1-87jyTXayGwR0jmiIZydSuHIjb6c=
22-
`;
22+
`.trimStart();
2323

2424
function cleanLockfile(lockfile: string) {
2525
lockfile = lockfile.replace(/(^ {2}version: )[0-9]+$/m, `$1X`);
@@ -51,25 +51,61 @@ describe(`Features`, () => {
5151

5252
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
5353
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});
54+
5455
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
56+
const expectedV1Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
57+
5558
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
5659
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});
5760

5861
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
5962
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});
63+
6064
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
65+
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
66+
6167
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
6268
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});
6369

64-
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
65-
await exec.execFile(`git`, [`merge`, `1.0.0`], {cwd: path});
70+
/* Merging 1.0 first, then 2.0 */{
71+
await exec.execFile(`git`, [`checkout`, `-b`, `merge-1-then-2`, `master`], {cwd: path});
72+
await exec.execFile(`git`, [`merge`, `1.0.0`], {cwd: path});
6673

67-
await expect(exec.execFile(`git`, [`merge`, `2.0.0`], {cwd: path, env: {LC_ALL: `C`}})).rejects.toThrow(/CONFLICT/);
74+
await expect(exec.execFile(`git`, [`merge`, `2.0.0`], {cwd: path, env: {LC_ALL: `C`}})).rejects.toThrow(/CONFLICT/);
6875

69-
const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
70-
expect(cleanLockfile(lockfile)).toMatchSnapshot();
76+
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
77+
expect(preFixLockfile).toContain(`<<<<<<<`);
7178

72-
await expect(run(`install`)).resolves.toMatchSnapshot();
79+
await run(`install`);
80+
81+
const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
82+
? expectedV2Lockfile
83+
: expectedV1Lockfile;
84+
85+
const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
86+
expect(postFixLockfile).toEqual(expectedLockfile);
87+
88+
await exec.execFile(`git`, [`merge`, `--abort`], {cwd: path});
89+
}
90+
91+
/* Merging 2.0 first, then 1.0 */ {
92+
await exec.execFile(`git`, [`checkout`, `-b`, `merge-2-then-1`, `master`], {cwd: path});
93+
await exec.execFile(`git`, [`merge`, `2.0.0`], {cwd: path});
94+
95+
await expect(exec.execFile(`git`, [`merge`, `1.0.0`], {cwd: path, env: {LC_ALL: `C`}})).rejects.toThrow(/CONFLICT/);
96+
97+
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
98+
expect(preFixLockfile).toContain(`<<<<<<<`);
99+
100+
await run(`install`);
101+
102+
const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
103+
? expectedV1Lockfile
104+
: expectedV2Lockfile;
105+
106+
const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
107+
expect(postFixLockfile).toEqual(expectedLockfile);
108+
}
73109
},
74110
),
75111
);
@@ -127,13 +163,18 @@ describe(`Features`, () => {
127163

128164
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
129165
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});
166+
130167
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
168+
131169
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
132170
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});
133171

134172
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
135173
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});
174+
136175
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
176+
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
177+
137178
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
138179
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});
139180

@@ -142,10 +183,13 @@ describe(`Features`, () => {
142183

143184
await expect(exec.execFile(`git`, [`rebase`, `2.0.0`], {cwd: path, env: {LC_ALL: `C`}})).rejects.toThrow(/CONFLICT/);
144185

145-
const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
146-
expect(cleanLockfile(lockfile)).toMatchSnapshot();
186+
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
187+
expect(preFixLockfile).toContain(`<<<<<<<`);
147188

148-
await expect(run(`install`)).resolves.toMatchSnapshot();
189+
await run(`install`);
190+
191+
const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
192+
expect(postFixLockfile).toEqual(expectedV2Lockfile);
149193
},
150194
),
151195
);
@@ -165,13 +209,19 @@ describe(`Features`, () => {
165209

166210
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
167211
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});
212+
168213
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
214+
const expectedV1Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
215+
169216
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
170217
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});
171218

172219
await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
173220
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});
221+
174222
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
223+
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
224+
175225
await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
176226
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});
177227

@@ -180,10 +230,17 @@ describe(`Features`, () => {
180230

181231
await expect(exec.execFile(`git`, [`cherry-pick`, `2.0.0`], {cwd: path, env: {LC_ALL: `C`}})).rejects.toThrow(/CONFLICT/);
182232

183-
const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
184-
expect(cleanLockfile(lockfile)).toMatchSnapshot();
233+
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
234+
expect(preFixLockfile).toContain(`<<<<<<<`);
185235

186-
await expect(run(`install`)).resolves.toMatchSnapshot();
236+
await run(`install`);
237+
238+
const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
239+
? expectedV2Lockfile
240+
: expectedV1Lockfile;
241+
242+
const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
243+
expect(postFixLockfile).toEqual(expectedLockfile);
187244
},
188245
),
189246
);

0 commit comments

Comments
 (0)