Skip to content

Commit

Permalink
fix(create-cloudflare): Ensure that C3 e2e tests run against `wrangle…
Browse files Browse the repository at this point in the history
…r@beta` in CI
  • Loading branch information
CarmenPopoviciu committed Jan 23, 2025
1 parent a7163b3 commit 1a3f773
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
29 changes: 22 additions & 7 deletions packages/create-cloudflare/src/helpers/__tests__/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe("Package Helpers", () => {
vi.mocked(existsSync).mockImplementation(() => false);
});

afterEach(() => {});
afterEach(() => {
vi.unstubAllEnvs();
});

describe("npmInstall", () => {
test("npm", async () => {
Expand Down Expand Up @@ -87,12 +89,25 @@ describe("Package Helpers", () => {
);
});

test("installWrangler", async () => {
await installWrangler();
describe("installWrangler", async () => {
test("install wrangler@beta if in CI", async () => {
vi.stubEnv("CI", "true");
await installWrangler();

expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
["npm", "install", "--save-dev", "wrangler@latest"],
expect.anything(),
);
expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
["npm", "install", "--save-dev", "wrangler@beta"],
expect.anything(),
);
});

test("install wrangler@latest if not in CI", async () => {
vi.stubEnv("CI", undefined);
await installWrangler();

expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
["npm", "install", "--save-dev", "wrangler@latest"],
expect.anything(),
);
});
});
});
3 changes: 2 additions & 1 deletion packages/create-cloudflare/src/helpers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ export async function getLatestPackageVersion(packageSpecifier: string) {
*/
export const installWrangler = async () => {
const { npm } = detectPackageManager();
const wrangler = process.env.CI ? `wrangler@beta` : "wrangler@latest";

// Even if Wrangler is already installed, make sure we install the latest version, as some framework CLIs are pinned to an older version
await installPackages([`wrangler@latest`], {
await installPackages([`${wrangler}`], {
dev: true,
startText: `Installing wrangler ${dim(
"A command line tool for building Cloudflare Workers",
Expand Down

0 comments on commit 1a3f773

Please sign in to comment.