|
| 1 | +import { expect, it } from "@jest/globals"; |
| 2 | +import sandbox from "./utils/sandbox.js"; |
| 3 | +import json from "./utils/json.js"; |
| 4 | +import { CONVER } from "./utils/binary.js"; |
| 5 | + |
| 6 | +it("bumps only affected packages", async () => { |
| 7 | + await sandbox(async (sandbox) => { |
| 8 | + // package.json |
| 9 | + await sandbox.writeFiles({ |
| 10 | + "package.json": json({ |
| 11 | + name: "my-workspace", |
| 12 | + version: "0.0.0", |
| 13 | + workspaces: ["package-a", "package-b"], |
| 14 | + }), |
| 15 | + "package-a/package.json": json({ |
| 16 | + name: "package-a", |
| 17 | + version: "1.2.3", |
| 18 | + }), |
| 19 | + "package-b/package.json": json({ |
| 20 | + name: "package-b", |
| 21 | + version: "1.2.3", |
| 22 | + }), |
| 23 | + }); |
| 24 | + |
| 25 | + // init sandbox |
| 26 | + await sandbox.$`git init`; |
| 27 | + await sandbox.$`${CONVER} init --yes`; |
| 28 | + await sandbox.$`git commit -m ${"chore: first commit"} --allow-empty`; |
| 29 | + |
| 30 | + // add commit for package A |
| 31 | + await sandbox.writeFiles({ |
| 32 | + "package-a/foo.txt": "foo", |
| 33 | + }); |
| 34 | + await sandbox.$`git add package-a/foo.txt`; |
| 35 | + await sandbox.$`git commit -m ${"patch: fix foo"}`; |
| 36 | + |
| 37 | + // add commit for package B |
| 38 | + await sandbox.writeFiles({ |
| 39 | + "package-b/bar.txt": "bar", |
| 40 | + }); |
| 41 | + await sandbox.$`git add package-b/bar.txt`; |
| 42 | + await sandbox.$`git commit -m ${"feat: add bar"}`; |
| 43 | + |
| 44 | + // versioning |
| 45 | + await sandbox.$`${CONVER} version`; |
| 46 | + |
| 47 | + // check version for package A |
| 48 | + const pkgA = (await sandbox.readJsoncFile("package-a/package.json")) as { |
| 49 | + version?: string; |
| 50 | + }; |
| 51 | + expect(pkgA.version).toBe("1.2.4"); |
| 52 | + |
| 53 | + // check version for package B |
| 54 | + const pkgB = (await sandbox.readJsoncFile("package-b/package.json")) as { |
| 55 | + version?: string; |
| 56 | + }; |
| 57 | + expect(pkgB.version).toBe("1.3.0"); |
| 58 | + }); |
| 59 | +}); |
| 60 | + |
| 61 | +it("bumps nested packages", async () => { |
| 62 | + await sandbox(async (sandbox) => { |
| 63 | + // package.json |
| 64 | + await sandbox.writeFiles({ |
| 65 | + "package.json": json({ |
| 66 | + name: "my-workspace", |
| 67 | + version: "0.0.0", |
| 68 | + workspaces: ["package-a", "package-a/package-b"], |
| 69 | + }), |
| 70 | + "package-a/package.json": json({ |
| 71 | + name: "package-a", |
| 72 | + version: "1.2.3", |
| 73 | + }), |
| 74 | + "package-a/package-b/package.json": json({ |
| 75 | + name: "package-b", |
| 76 | + version: "1.2.3", |
| 77 | + }), |
| 78 | + }); |
| 79 | + |
| 80 | + // init sandbox |
| 81 | + await sandbox.$`git init`; |
| 82 | + await sandbox.$`${CONVER} init --yes`; |
| 83 | + await sandbox.$`git commit -m ${"chore: first commit"} --allow-empty`; |
| 84 | + |
| 85 | + // add commit |
| 86 | + await sandbox.writeFiles({ |
| 87 | + "package-a/package-b/foo.txt": "foo", |
| 88 | + }); |
| 89 | + await sandbox.$`git add package-a/package-b/foo.txt`; |
| 90 | + await sandbox.$`git commit -m ${"patch: fix foo"}`; |
| 91 | + |
| 92 | + // versioning |
| 93 | + await sandbox.$`${CONVER} version`; |
| 94 | + |
| 95 | + // check version for package A |
| 96 | + const pkgA = (await sandbox.readJsoncFile("package-a/package.json")) as { |
| 97 | + version?: string; |
| 98 | + }; |
| 99 | + expect(pkgA.version).toBe("1.2.4"); |
| 100 | + |
| 101 | + // check version for package B |
| 102 | + const pkgB = (await sandbox.readJsoncFile( |
| 103 | + "package-a/package-b/package.json", |
| 104 | + )) as { |
| 105 | + version?: string; |
| 106 | + }; |
| 107 | + expect(pkgB.version).toBe("1.2.4"); |
| 108 | + }); |
| 109 | +}); |
0 commit comments