Skip to content

Commit 9a50486

Browse files
CarmenPopoviciudario-piotrowicz
authored andcommitted
fix(create-cloudflare): Ensure that C3 e2e tests are running against local wrangler
1 parent d7210ec commit 9a50486

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

packages/create-cloudflare/e2e-tests/helpers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "assert";
2+
import { execSync } from "child_process";
23
import {
34
createWriteStream,
45
mkdirSync,
@@ -47,6 +48,7 @@ const testEnv = {
4748
npm_config_cache: "./.npm/cache",
4849
// unset the VITEST env variable as this causes e2e issues with some frameworks
4950
VITEST: undefined,
51+
WRANGLER: packWrangler(),
5052
};
5153

5254
export type PromptHandler = {
@@ -508,3 +510,16 @@ export function kill(proc: ChildProcess) {
508510
(resolve) => proc.pid && treeKill(proc.pid, "SIGINT", () => resolve()),
509511
);
510512
}
513+
514+
export function packWrangler(): string {
515+
const pathToWrangler = path.resolve(__dirname, "../../wrangler");
516+
execSync("pnpm pack --pack-destination ./.pack", { cwd: pathToWrangler });
517+
518+
const versions = execSync("ls -1 .pack", {
519+
encoding: "utf-8",
520+
cwd: pathToWrangler,
521+
});
522+
const wranglerVersion = versions.trim().split("\n").at(-1); // get last wrangler version
523+
assert(wranglerVersion);
524+
return path.join(pathToWrangler, ".pack", wranglerVersion);
525+
}

packages/create-cloudflare/src/helpers/__tests__/packages.test.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe("Package Helpers", () => {
1818
vi.mocked(existsSync).mockImplementation(() => false);
1919
});
2020

21-
afterEach(() => {});
21+
afterEach(() => {
22+
vi.unstubAllEnvs();
23+
});
2224

2325
describe("npmInstall", () => {
2426
test("npm", async () => {
@@ -87,12 +89,26 @@ describe("Package Helpers", () => {
8789
);
8890
});
8991

90-
test("installWrangler", async () => {
91-
await installWrangler();
92+
describe("installWrangler", async () => {
93+
test("install latest wrangler version if not in CI", async () => {
94+
vi.stubEnv("CI", undefined);
95+
await installWrangler();
9296

93-
expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
94-
["npm", "install", "--save-dev", "wrangler@latest"],
95-
expect.anything(),
96-
);
97+
expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
98+
["npm", "install", "--save-dev", "wrangler@latest"],
99+
expect.anything(),
100+
);
101+
});
102+
103+
test("install local wrangler version if in CI", async () => {
104+
vi.stubEnv("CI", "true");
105+
vi.stubEnv("WRANGLER", "local-wrangler.tar.gz");
106+
await installWrangler();
107+
108+
expect(vi.mocked(runCommand)).toHaveBeenCalledWith(
109+
["npm", "install", "--save-dev", "file:local-wrangler.tar.gz"],
110+
expect.anything(),
111+
);
112+
});
97113
});
98114
});

packages/create-cloudflare/src/helpers/packages.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { existsSync } from "fs";
22
import path from "path";
3+
import { log } from "@cloudflare/cli";
34
import { brandColor, dim } from "@cloudflare/cli/colors";
45
import { fetch } from "undici";
56
import { runCommand } from "./command";
@@ -88,9 +89,14 @@ export async function getLatestPackageVersion(packageSpecifier: string) {
8889
*/
8990
export const installWrangler = async () => {
9091
const { npm } = detectPackageManager();
92+
const wrangler = process.env.CI
93+
? `file:${process.env.WRANGLER}`
94+
: "wrangler@latest";
95+
96+
log(`Using wrangler ${wrangler}`);
9197

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

packages/create-cloudflare/turbo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"E2E_RETRIES",
2525
"E2E_NO_DEPLOY",
2626
"E2E_EXPERIMENTAL",
27-
"TEST_PM"
27+
"TEST_PM",
28+
"WRANGLER"
2829
],
2930
"dependsOn": ["build"],
3031
"outputs": [".e2e-logs", ".e2e-logs-experimental"]

0 commit comments

Comments
 (0)