|
| 1 | +import { createFixture } from "fs-fixture"; |
1 | 2 | import { expect, test } from "vitest"; |
2 | | -import { BumpLevels, getChangelogEntry, sortTheThings } from "./utils.ts"; |
| 3 | +import { |
| 4 | + BumpLevels, |
| 5 | + getChangelogEntry, |
| 6 | + sortTheThings, |
| 7 | + validateChangesetsCliVersion, |
| 8 | +} from "./utils.ts"; |
3 | 9 |
|
4 | 10 | let changelog = `# @keystone-alpha/email |
5 | 11 |
|
@@ -100,3 +106,49 @@ test("it sorts the things right", () => { |
100 | 106 | ]; |
101 | 107 | expect(things.sort(sortTheThings)).toMatchSnapshot(); |
102 | 108 | }); |
| 109 | + |
| 110 | +test("throws when the project declares Changesets CLI v2", async () => { |
| 111 | + await using fixture = await createFixture({ |
| 112 | + "package.json": JSON.stringify({ |
| 113 | + name: "project", |
| 114 | + devDependencies: { "@changesets/cli": "^2.29.7" }, |
| 115 | + }), |
| 116 | + "package-lock.json": "", |
| 117 | + }); |
| 118 | + |
| 119 | + await expect(validateChangesetsCliVersion(fixture.path)).rejects.toThrow( |
| 120 | + "This version of the Changesets action is designed to work with Changesets CLI v3. Changesets CLI v2 is not supported; use Changesets action v1 instead, which is compatible with CLI v2.", |
| 121 | + ); |
| 122 | +}); |
| 123 | + |
| 124 | +test("accepts a Changesets CLI v3 contract without an installed CLI", async () => { |
| 125 | + await using fixture = await createFixture({ |
| 126 | + "package.json": JSON.stringify({ |
| 127 | + name: "project", |
| 128 | + devDependencies: { "@changesets/cli": "^3.0.0" }, |
| 129 | + }), |
| 130 | + "package-lock.json": "", |
| 131 | + }); |
| 132 | + |
| 133 | + await expect( |
| 134 | + validateChangesetsCliVersion(fixture.path), |
| 135 | + ).resolves.toBeUndefined(); |
| 136 | +}); |
| 137 | + |
| 138 | +test("throws when the project has Changesets CLI v2 installed", async () => { |
| 139 | + await using fixture = await createFixture({ |
| 140 | + "package.json": JSON.stringify({ |
| 141 | + name: "project", |
| 142 | + devDependencies: { "@changesets/cli": "^3.0.0" }, |
| 143 | + }), |
| 144 | + "package-lock.json": "", |
| 145 | + "node_modules/@changesets/cli/package.json": JSON.stringify({ |
| 146 | + name: "@changesets/cli", |
| 147 | + version: "2.29.7", |
| 148 | + }), |
| 149 | + }); |
| 150 | + |
| 151 | + await expect(validateChangesetsCliVersion(fixture.path)).rejects.toThrow( |
| 152 | + "This version of the Changesets action is designed to work with Changesets CLI v3. Changesets CLI v2 is not supported; use Changesets action v1 instead, which is compatible with CLI v2.", |
| 153 | + ); |
| 154 | +}); |
0 commit comments