|
1 | | -import { describe, it, expect, vi } from "vitest"; |
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; |
| 2 | +import fs from "fs"; |
| 3 | +import path from "path"; |
| 4 | +import os from "os"; |
2 | 5 | import { |
3 | 6 | parseSemver, |
4 | 7 | computeNextStableVersion, |
5 | 8 | computePrereleaseVersion, |
| 9 | + bumpPackages, |
6 | 10 | } from "./versions.js"; |
7 | 11 |
|
8 | | -// Mock loadConfig for computePrereleaseVersion |
9 | | -vi.mock("./config.js", () => ({ |
10 | | - ROOT: "/mock", |
11 | | - loadConfig: () => ({ |
12 | | - prereleaseTag: "canary", |
13 | | - scopes: { |
14 | | - monorepo: { |
15 | | - packages: [], |
16 | | - versionSource: "@copilotkit/react-core", |
17 | | - sharedVersion: true, |
18 | | - }, |
19 | | - cli: { packages: [], versionSource: "copilotkit", sharedVersion: false }, |
20 | | - angular: { |
21 | | - packages: [], |
22 | | - versionSource: "@copilotkitnext/angular", |
23 | | - sharedVersion: false, |
24 | | - }, |
| 12 | +let tmpDir: string; |
| 13 | + |
| 14 | +// Mock config — ROOT points to a temp dir for bumpPackages tests |
| 15 | +vi.mock("./config.js", async () => { |
| 16 | + return { |
| 17 | + get ROOT() { |
| 18 | + return tmpDir || "/mock"; |
25 | 19 | }, |
26 | | - }), |
27 | | - getScopeConfig: (scope: string) => { |
28 | | - const scopes: Record<string, any> = { |
29 | | - monorepo: { |
30 | | - packages: [], |
31 | | - versionSource: "@copilotkit/react-core", |
32 | | - sharedVersion: true, |
33 | | - }, |
34 | | - cli: { packages: [], versionSource: "copilotkit", sharedVersion: false }, |
35 | | - angular: { |
36 | | - packages: [], |
37 | | - versionSource: "@copilotkitnext/angular", |
38 | | - sharedVersion: false, |
| 20 | + loadConfig: () => ({ |
| 21 | + prereleaseTag: "canary", |
| 22 | + scopes: { |
| 23 | + monorepo: { |
| 24 | + packages: ["@copilotkit/shared", "@copilotkit/react-core"], |
| 25 | + versionSource: "@copilotkit/react-core", |
| 26 | + sharedVersion: true, |
| 27 | + }, |
| 28 | + cli: { |
| 29 | + packages: ["copilotkit"], |
| 30 | + versionSource: "copilotkit", |
| 31 | + sharedVersion: false, |
| 32 | + }, |
| 33 | + angular: { |
| 34 | + packages: ["@copilotkitnext/angular"], |
| 35 | + versionSource: "@copilotkitnext/angular", |
| 36 | + sharedVersion: false, |
| 37 | + }, |
39 | 38 | }, |
40 | | - }; |
41 | | - return scopes[scope]; |
42 | | - }, |
43 | | -})); |
| 39 | + }), |
| 40 | + getScopeConfig: (scope: string) => { |
| 41 | + const scopes: Record<string, any> = { |
| 42 | + monorepo: { |
| 43 | + packages: ["@copilotkit/shared", "@copilotkit/react-core"], |
| 44 | + versionSource: "@copilotkit/react-core", |
| 45 | + sharedVersion: true, |
| 46 | + }, |
| 47 | + cli: { |
| 48 | + packages: ["copilotkit"], |
| 49 | + versionSource: "copilotkit", |
| 50 | + sharedVersion: false, |
| 51 | + }, |
| 52 | + angular: { |
| 53 | + packages: ["@copilotkitnext/angular"], |
| 54 | + versionSource: "@copilotkitnext/angular", |
| 55 | + sharedVersion: false, |
| 56 | + }, |
| 57 | + }; |
| 58 | + return scopes[scope]; |
| 59 | + }, |
| 60 | + }; |
| 61 | +}); |
44 | 62 |
|
45 | 63 | describe("parseSemver", () => { |
46 | 64 | it("parses a stable version", () => { |
@@ -134,3 +152,89 @@ describe("computePrereleaseVersion", () => { |
134 | 152 | ); |
135 | 153 | }); |
136 | 154 | }); |
| 155 | + |
| 156 | +describe("bumpPackages", () => { |
| 157 | + beforeEach(() => { |
| 158 | + tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "release-test-")); |
| 159 | + const packagesDir = path.join(tmpDir, "packages"); |
| 160 | + |
| 161 | + // Create shared package |
| 162 | + const sharedDir = path.join(packagesDir, "shared"); |
| 163 | + fs.mkdirSync(sharedDir, { recursive: true }); |
| 164 | + fs.writeFileSync( |
| 165 | + path.join(sharedDir, "package.json"), |
| 166 | + JSON.stringify({ |
| 167 | + name: "@copilotkit/shared", |
| 168 | + version: "1.55.2", |
| 169 | + }), |
| 170 | + ); |
| 171 | + |
| 172 | + // Create react-core with workspace:* dep on shared |
| 173 | + const reactCoreDir = path.join(packagesDir, "react-core"); |
| 174 | + fs.mkdirSync(reactCoreDir, { recursive: true }); |
| 175 | + fs.writeFileSync( |
| 176 | + path.join(reactCoreDir, "package.json"), |
| 177 | + JSON.stringify({ |
| 178 | + name: "@copilotkit/react-core", |
| 179 | + version: "1.55.2", |
| 180 | + dependencies: { |
| 181 | + "@copilotkit/shared": "workspace:*", |
| 182 | + }, |
| 183 | + }), |
| 184 | + ); |
| 185 | + }); |
| 186 | + |
| 187 | + afterEach(() => { |
| 188 | + fs.rmSync(tmpDir, { recursive: true, force: true }); |
| 189 | + }); |
| 190 | + |
| 191 | + it("bumps version fields", () => { |
| 192 | + const result = bumpPackages("monorepo", "1.55.3"); |
| 193 | + expect(result).toHaveLength(2); |
| 194 | + expect(result[0].newVersion).toBe("1.55.3"); |
| 195 | + |
| 196 | + const pkg = JSON.parse( |
| 197 | + fs.readFileSync( |
| 198 | + path.join(tmpDir, "packages/shared/package.json"), |
| 199 | + "utf8", |
| 200 | + ), |
| 201 | + ); |
| 202 | + expect(pkg.version).toBe("1.55.3"); |
| 203 | + }); |
| 204 | + |
| 205 | + it("preserves workspace:* protocol in dependencies", () => { |
| 206 | + bumpPackages("monorepo", "1.55.3"); |
| 207 | + |
| 208 | + const pkg = JSON.parse( |
| 209 | + fs.readFileSync( |
| 210 | + path.join(tmpDir, "packages/react-core/package.json"), |
| 211 | + "utf8", |
| 212 | + ), |
| 213 | + ); |
| 214 | + expect(pkg.dependencies["@copilotkit/shared"]).toBe("workspace:*"); |
| 215 | + }); |
| 216 | + |
| 217 | + it("updates exact version deps (not workspace protocol)", () => { |
| 218 | + // Write react-core with an exact version dep instead of workspace:* |
| 219 | + fs.writeFileSync( |
| 220 | + path.join(tmpDir, "packages/react-core/package.json"), |
| 221 | + JSON.stringify({ |
| 222 | + name: "@copilotkit/react-core", |
| 223 | + version: "1.55.2", |
| 224 | + dependencies: { |
| 225 | + "@copilotkit/shared": "1.55.2", |
| 226 | + }, |
| 227 | + }), |
| 228 | + ); |
| 229 | + |
| 230 | + bumpPackages("monorepo", "1.55.3"); |
| 231 | + |
| 232 | + const pkg = JSON.parse( |
| 233 | + fs.readFileSync( |
| 234 | + path.join(tmpDir, "packages/react-core/package.json"), |
| 235 | + "utf8", |
| 236 | + ), |
| 237 | + ); |
| 238 | + expect(pkg.dependencies["@copilotkit/shared"]).toBe("1.55.3"); |
| 239 | + }); |
| 240 | +}); |
0 commit comments