Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Jan 29, 2024
1 parent 645cbfa commit c58121c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/chronus/src/workspace-manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./npm.js";
export * from "./pnpm.js";
export { createPnpmWorkspaceManager } from "./pnpm.js";
export { createRushWorkspaceManager } from "./rush.js";
4 changes: 2 additions & 2 deletions packages/chronus/src/workspace-manager/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export function createPnpmWorkspaceManager(host: ChronusHost): WorkspaceManager
const config: PnpmWorkspaceConfig = load(file.content) as any;

if (config.packages === undefined) {
throw new ChronusError("packages entry missing in pnpm-workspace.yaml");
throw new ChronusError(`packages entry missing in ${workspaceFileName}`);
}
if (Array.isArray(config.packages) === false) {
throw new ChronusError("packages is not an array in pnpm-workspace.yaml");
throw new ChronusError(`packages is not an array in ${workspaceFileName}`);
}
const packages: Package[] = (
await Promise.all(config.packages.map((pattern) => findPackagesFromPattern(host, root, pattern)))
Expand Down
44 changes: 26 additions & 18 deletions packages/chronus/src/workspace-manager/rush.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import { dump } from "js-yaml";
import { beforeEach, describe, expect, it } from "vitest";
import { createTestHost, type TestHost } from "../testing/test-host.js";
import { createPnpmWorkspaceManager } from "./pnpm.js";
import { createRushWorkspaceManager } from "./rush.js";
import type { WorkspaceManager } from "./types.js";

describe("pnpm", () => {
describe("rush", () => {
let host: TestHost;
let pnpm: WorkspaceManager;
let rush: WorkspaceManager;
beforeEach(async () => {
host = createTestHost({
"proj/rush.json": dump({
packages: [
host = createTestHost({});

rush = createRushWorkspaceManager(host.host);
});

it("finds 0 packages when workspace has none", async () => {
host.addFile(
"proj/rush.json",
dump({
projects: [],
}),
);
const workspace = await rush.load("proj");
expect(workspace.packages).toEqual([]);
});

it("finds all packages", async () => {
host.addFile(
"proj/rush.json",
dump({
projects: [
{
packageName: "pkg-a",
projectFolder: "packages/pkg-a",
Expand All @@ -23,20 +41,10 @@ describe("pnpm", () => {
},
],
}),
});

pnpm = createPnpmWorkspaceManager(host.host);
});

it("finds 0 packages when workspace has none", async () => {
const workspace = await pnpm.load("proj");
expect(workspace.packages).toEqual([]);
});

it("finds all packages", async () => {
);
host.addFile("proj/packages/pkg-a/package.json", JSON.stringify({ name: "pkg-a", version: "1.0.0" }));
host.addFile("proj/packages/pkg-b/package.json", JSON.stringify({ name: "pkg-b", version: "1.2.0" }));
const workspace = await pnpm.load("proj");
const workspace = await rush.load("proj");
expect(workspace.packages).toHaveLength(2);
expect(workspace.packages[0]).toEqual({
name: "pkg-a",
Expand Down

0 comments on commit c58121c

Please sign in to comment.