91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import { existsSync, readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, test } from "vitest";
|
|
|
|
const root = existsSync(join(process.cwd(), "turbo.json"))
|
|
? process.cwd()
|
|
: join(process.cwd(), "..", "..");
|
|
|
|
describe("workspace boundaries", () => {
|
|
test("declares the root as a turbo-managed bun workspace", () => {
|
|
const packageJson = JSON.parse(
|
|
readFileSync(join(root, "package.json"), "utf8"),
|
|
) as {
|
|
private?: boolean;
|
|
scripts?: Record<string, string>;
|
|
workspaces?: string[];
|
|
};
|
|
|
|
expect(packageJson.private).toBe(true);
|
|
expect(packageJson.workspaces).toEqual(["apps/*", "packages/*"]);
|
|
expect(packageJson.scripts?.build).toBe("turbo run build");
|
|
expect(existsSync(join(root, "turbo.json"))).toBe(true);
|
|
});
|
|
|
|
test("keeps release orchestration in the root turbo task graph", () => {
|
|
const rootPackage = JSON.parse(
|
|
readFileSync(join(root, "package.json"), "utf8"),
|
|
) as {
|
|
scripts?: Record<string, string>;
|
|
};
|
|
const webPackage = JSON.parse(
|
|
readFileSync(join(root, "apps/web/package.json"), "utf8"),
|
|
) as { scripts?: Record<string, string> };
|
|
const turboConfig = JSON.parse(
|
|
readFileSync(join(root, "turbo.json"), "utf8"),
|
|
) as {
|
|
globalDependencies?: string[];
|
|
tasks?: Record<string, { env?: string[] }>;
|
|
};
|
|
|
|
expect(rootPackage.scripts?.["test:qa"]).toBe(
|
|
"turbo run check test:unit build @dimensionlab/ui#build-storybook @dimensionlab/web#test:e2e",
|
|
);
|
|
expect(webPackage.scripts).not.toHaveProperty("test:qa");
|
|
expect(turboConfig.tasks).not.toHaveProperty("test:qa");
|
|
expect(turboConfig.globalDependencies).toEqual(
|
|
expect.arrayContaining(["bun.lock", "tsconfig.base.json"]),
|
|
);
|
|
expect(turboConfig.tasks?.["test:e2e"]?.env).toEqual(
|
|
expect.arrayContaining([
|
|
"CI",
|
|
"PLAYWRIGHT_DATABASE_URL",
|
|
"PLAYWRIGHT_PORT",
|
|
"PLAYWRIGHT_STORYBOOK_PORT",
|
|
]),
|
|
);
|
|
});
|
|
|
|
test("lets turbo build app and Storybook artifacts before e2e serves them", () => {
|
|
const playwrightConfig = readFileSync(
|
|
join(root, "apps/web/playwright.config.ts"),
|
|
"utf8",
|
|
);
|
|
const turboConfig = JSON.parse(
|
|
readFileSync(join(root, "turbo.json"), "utf8"),
|
|
) as {
|
|
tasks?: Record<string, { dependsOn?: string[] }>;
|
|
};
|
|
|
|
expect(playwrightConfig).not.toContain("bun run build &&");
|
|
expect(playwrightConfig).not.toContain("bun run build-storybook");
|
|
expect(turboConfig.tasks?.["test:e2e"]?.dependsOn).toEqual(
|
|
expect.arrayContaining(["@dimensionlab/ui#build-storybook"]),
|
|
);
|
|
});
|
|
|
|
test("keeps the website app and reusable UI library as separate packages", () => {
|
|
const webPackage = JSON.parse(
|
|
readFileSync(join(root, "apps/web/package.json"), "utf8"),
|
|
) as { dependencies?: Record<string, string>; name?: string };
|
|
const uiPackage = JSON.parse(
|
|
readFileSync(join(root, "packages/ui/package.json"), "utf8"),
|
|
) as { exports?: Record<string, unknown>; name?: string };
|
|
|
|
expect(webPackage.name).toBe("@dimensionlab/web");
|
|
expect(webPackage.dependencies?.["@dimensionlab/ui"]).toBe("workspace:*");
|
|
expect(uiPackage.name).toBe("@dimensionlab/ui");
|
|
expect(uiPackage.exports).toHaveProperty(".");
|
|
expect(uiPackage.exports).toHaveProperty("./styles.css");
|
|
});
|
|
});
|