70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { runInTempDir, seed } from "@cloudflare/workers-utils/test-helpers";
|
|
import { describe, it } from "vitest";
|
|
import { detectFramework } from "../../../src/details/framework-detection";
|
|
import { createMockContext } from "../../helpers/mock-context";
|
|
|
|
describe("detectFramework() / workspace root handling", () => {
|
|
runInTempDir();
|
|
const context = createMockContext();
|
|
|
|
it("sets isWorkspaceRoot to false for regular (non-monorepo) projects", async ({
|
|
expect,
|
|
}) => {
|
|
await seed({
|
|
"package.json": JSON.stringify({ name: "my-app" }),
|
|
"package-lock.json": JSON.stringify({ lockfileVersion: 3 }),
|
|
});
|
|
|
|
const result = await detectFramework(process.cwd(), context);
|
|
|
|
expect(result.isWorkspaceRoot).toBe(false);
|
|
});
|
|
|
|
it("sets isWorkspaceRoot to true when the workspace root is itself a workspace package", async ({
|
|
expect,
|
|
}) => {
|
|
await seed({
|
|
"pnpm-workspace.yaml": "packages:\n - 'packages/*'\n - '.'\n",
|
|
"package.json": JSON.stringify({
|
|
name: "my-workspace",
|
|
workspaces: ["packages/*", "."],
|
|
}),
|
|
"packages/my-app/package.json": JSON.stringify({ name: "my-app" }),
|
|
});
|
|
|
|
const result = await detectFramework(process.cwd(), context);
|
|
|
|
expect(result.isWorkspaceRoot).toBe(true);
|
|
});
|
|
|
|
it("throws UserError when run from a workspace root that does not include the root as a package", async ({
|
|
expect,
|
|
}) => {
|
|
await seed({
|
|
"pnpm-workspace.yaml": "packages:\n - 'packages/*'\n",
|
|
"package.json": JSON.stringify({
|
|
name: "my-workspace",
|
|
workspaces: ["packages/*"],
|
|
}),
|
|
"packages/my-app/package.json": JSON.stringify({ name: "my-app" }),
|
|
"packages/my-app/index.html": "<h1>Hello World</h1>",
|
|
});
|
|
|
|
await expect(
|
|
detectFramework(process.cwd(), context)
|
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
`[Error: The Cloudflare application detection logic has been run in the root of a workspace instead of targeting a specific project. Change your working directory to one of the applications in the workspace and try again.]`
|
|
);
|
|
});
|
|
});
|