Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function isAtLeastMajor(major: number) {
export const FEATURE_CHECKS = {
jsonLockfile: isAtLeastMajor(5),
prologConstraints: !isAtLeastMajor(5),
mergeConflictTheirs: isAtLeastMajor(5),
} as const;

// Testing things inside a big-endian container takes forever
Expand Down
Original file line number Diff line number Diff line change
@@ -1,173 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Features Merge Conflict Resolution it should properly fix merge conflicts 1`] = `
"# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: X
cacheKey: 0c0

"no-deps@npm:*":
<<<<<<< HEAD
version: 1.0.0
resolution: "no-deps@npm:1.0.0"
checksum: <checksum stripped>
=======
version: 2.0.0
resolution: "no-deps@npm:2.0.0"
checksum: <checksum stripped>
>>>>>>> 2.0.0
languageName: node
linkType: hard

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
no-deps: "npm:*"
languageName: unknown
linkType: soft
"
`;

exports[`Features Merge Conflict Resolution it should properly fix merge conflicts 2`] = `
{
"code": 0,
"stderr": "",
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍

➤ YN0000: · Yarn 0.0.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done
",
}
`;

exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 1`] = `
"# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: X
cacheKey: 0c0

<<<<<<< HEAD
no-deps@*:
version "2.0.0"
resolved "http://localhost:64572/no-deps/-/no-deps-2.0.0.tgz#f3b8f24d76b21b04748e6888672752b872236fa7"
integrity sha1-87jyTXayGwR0jmiIZydSuHIjb6c=
=======
"no-deps@npm:*":
version: 2.0.0
resolution: "no-deps@npm:2.0.0"
checksum: <checksum stripped>
languageName: node
linkType: hard

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
no-deps: "npm:*"
languageName: unknown
linkType: soft
>>>>>>> yarn2
"
`;

exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 2`] = `
{
"code": 0,
"stderr": "",
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍

➤ YN0000: · Yarn 0.0.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done
",
}
`;

exports[`Features Merge Conflict Resolution it should support fixing cherry-pick conflicts 1`] = `
"# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: X
cacheKey: 0c0

"no-deps@npm:*":
<<<<<<< HEAD
version: 1.0.0
resolution: "no-deps@npm:1.0.0"
checksum: <checksum stripped>
=======
version: 2.0.0
resolution: "no-deps@npm:2.0.0"
checksum: <checksum stripped>
>>>>>>> 0000000 (commit-2.0.0)
languageName: node
linkType: hard

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
dependencies:
no-deps: "npm:*"
languageName: unknown
linkType: soft
"
`;

exports[`Features Merge Conflict Resolution it should support fixing cherry-pick conflicts 2`] = `
{
"code": 0,
"stderr": "",
"stdout": "➤ YN0048: Automatically fixed merge conflicts 👍

➤ YN0000: · Yarn 0.0.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done
",
}
`;

exports[`Features Merge Conflict Resolution it should support fixing rebase conflicts 1`] = `
"# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: X
cacheKey: 0c0

"no-deps@npm:*":
<<<<<<< HEAD
version: 2.0.0
resolution: "no-deps@npm:2.0.0"
checksum: <checksum stripped>
=======
version: 1.0.0
resolution: "no-deps@npm:1.0.0"
checksum: <checksum stripped>
>>>>>>> 0000000 (commit-1.0.0)
languageName: node
linkType: hard

Expand All @@ -178,10 +28,11 @@ __metadata:
no-deps: "npm:*"
languageName: unknown
linkType: soft
>>>>>>> yarn2
"
`;

exports[`Features Merge Conflict Resolution it should support fixing rebase conflicts 2`] = `
exports[`Features Merge Conflict Resolution it should properly fix merge conflicts when old is Yarn 1 and new is Yarn 2 2`] = `
{
"code": 0,
"stderr": "",
Expand All @@ -191,7 +42,6 @@ exports[`Features Merge Conflict Resolution it should support fixing rebase conf
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ No new packages added to the project, but one was removed (- 0.78 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Filename, ppath, xfs} from '@yarnpkg/fslib';
import {exec} from 'pkg-tests-core';
import {exec, tests} from 'pkg-tests-core';

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

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

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

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
const expectedV1Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});

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

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

const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(cleanLockfile(lockfile)).toMatchSnapshot();
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(preFixLockfile).toContain(`<<<<<<<`);

await expect(run(`install`)).resolves.toMatchSnapshot();
await run(`install`);

const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
? expectedV2Lockfile
: expectedV1Lockfile;

const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(postFixLockfile).toEqual(expectedLockfile);

await exec.execFile(`git`, [`merge`, `--abort`], {cwd: path});
}

/* Merging 2.0 first, then 1.0 */ {
await exec.execFile(`git`, [`checkout`, `-b`, `merge-2-then-1`, `master`], {cwd: path});
await exec.execFile(`git`, [`merge`, `2.0.0`], {cwd: path});

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

const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(preFixLockfile).toContain(`<<<<<<<`);

await run(`install`);

const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
? expectedV1Lockfile
: expectedV2Lockfile;

const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(postFixLockfile).toEqual(expectedLockfile);
}
},
),
);
Expand Down Expand Up @@ -127,13 +163,18 @@ describe(`Features`, () => {

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});

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

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

const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(cleanLockfile(lockfile)).toMatchSnapshot();
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(preFixLockfile).toContain(`<<<<<<<`);

await expect(run(`install`)).resolves.toMatchSnapshot();
await run(`install`);

const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(postFixLockfile).toEqual(expectedV2Lockfile);
},
),
);
Expand All @@ -165,13 +209,19 @@ describe(`Features`, () => {

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
const expectedV1Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});

await exec.execFile(`git`, [`checkout`, `master`], {cwd: path});
await exec.execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});

await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
const expectedV2Lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);

await exec.execFile(`git`, [`add`, `-A`], {cwd: path});
await exec.execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});

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

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

const lockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(cleanLockfile(lockfile)).toMatchSnapshot();
const preFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(preFixLockfile).toContain(`<<<<<<<`);

await expect(run(`install`)).resolves.toMatchSnapshot();
await run(`install`);

const expectedLockfile = tests.FEATURE_CHECKS.mergeConflictTheirs
? expectedV2Lockfile
: expectedV1Lockfile;

const postFixLockfile = await xfs.readFilePromise(ppath.join(path, Filename.lockfile), `utf8`);
expect(postFixLockfile).toEqual(expectedLockfile);
},
),
);
Expand Down
Loading