Skip to content

Commit ca684a8

Browse files
make it easier to run wrangler e2e locally (#9959)
1 parent 558405c commit ca684a8

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

packages/wrangler/e2e/README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
# E2E tests
22

3-
This folder contains e2e tests for Wrangler. The tests run in CI against a specific Cloudflare account.
3+
This folder contains e2e tests for Wrangler.
44

5-
You can also run these tests locally, but you'll need access to the `8d783f274e1f82dc46744c297b015a2f` (DevProd Testing) Cloudflare account. Once you have access, generate an API token for the account with the same scopes Wrangler requests.
5+
## Run the tests
66

7-
You can then run the e2e test suite with the following commands (run them in root of the repo):
7+
Run each of the test files as a separately cached turbo task.
88

99
```zsh
10-
CLOUDFLARE_ACCOUNT_ID=8d783f274e1f82dc46744c297b015a2f CLOUDFLARE_API_TOKEN=<cloudflare-testing-api-token> WRANGLER="node --no-warnings $PWD/packages/wrangler/bin/wrangler.js" WRANGLER_IMPORT="$PWD/packages/wrangler/wrangler-dist/cli.js" pnpm test:e2e -F wrangler
10+
pnpm test:e2e:wrangler
1111
```
1212

13-
> Make sure you have run `pnpm i` since any changes to package dependencies - common when switching git branches or pulling updates from GitHub.
14-
> Also, remember to replace `<cloudflare-testing-api-token>` with the actual API token you generated.
13+
## Configuration
1514

16-
If you want to run a subset of tests (e.g. just one) while retaining the turborepo cache for the builds of the dependencies, you can provide the list of test files via the `WRANGLER_E2E_TEST_FILE` environment variable. For example (eliding the other env vars for clarity):
15+
You can configure how these e2e tests are run, in terms of the backend Cloudflare account, Wrangler and Miniflare distributable binaries and libraries, and which test file to run.
16+
17+
### Cloudflare Credentials
18+
19+
Cloudflare credentials are provided to the tests by setting `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`.
20+
21+
- If you don't provide these then only the local e2e tests are executed.
22+
- If you don't provide the "DevProd Testing" Cloudflare account (as `CLOUDFLARE_ACCOUNT_ID=8d783f274e1f82dc46744c297b015a2f`), tests that require that specific account are not executed.
23+
24+
To fully run the tests you should generate an API token for the "DevProd Testing" account:
25+
26+
```zsh
27+
CLOUDFLARE_ACCOUNT_ID=8d783f274e1f82dc46744c297b015a2f CLOUDFLARE_API_TOKEN=<cloudflare-testing-api-token> pnpm test:e2e:wrangler
28+
```
29+
30+
### Focusing on a single e2e test file
31+
32+
If you want to run a subset of tests (e.g. just one) while retaining the turborepo cache for the builds of the dependencies, you can provide the list of test files via the `WRANGLER_E2E_TEST_FILE` environment variable.
33+
For example to run the C3 integration test file only:
1734

1835
```zsh
19-
CLOUDFLARE_ACCOUNT_ID=... CLOUDFLARE_API_TOKEN=... WRANGLER=... WRANGLER_IMPORT=... WRANGLER_E2E_TEST_FILE=c3-integration.test pnpm test:e2e -F wrangler
36+
WRANGLER_E2E_TEST_FILE=c3-integration.test pnpm test:e2e:wrangler
2037
```
2138

2239
## How tests are written

packages/wrangler/e2e/helpers/wrangler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import assert from "node:assert";
2+
import { resolve } from "node:path";
23
import { pathToFileURL } from "node:url";
34
import { LongLivedCommand, runCommand } from "./command";
45
import type { CommandOptions } from "./command";
56

67
// Replace all backslashes with forward slashes to ensure that their use
78
// in scripts doesn't break.
8-
export const WRANGLER = process.env.WRANGLER?.replaceAll("\\", "/") ?? "";
9+
export const WRANGLER =
10+
process.env.WRANGLER?.replaceAll("\\", "/") ??
11+
`node ${resolve("packages/wrangler/bin/wrangler.js")}`;
912
export const WRANGLER_IMPORT = pathToFileURL(
10-
process.env.WRANGLER_IMPORT?.replaceAll("\\", "/") ?? ""
13+
process.env.WRANGLER_IMPORT?.replaceAll("\\", "/") ??
14+
resolve("packages/wrangler/wrangler-dist/cli.js")
1115
);
1216
export const MINIFLARE_IMPORT = pathToFileURL(
13-
process.env.MINIFLARE_IMPORT?.replaceAll("\\", "/") ?? ""
17+
process.env.MINIFLARE_IMPORT?.replaceAll("\\", "/") ??
18+
resolve("packages/miniflare/dist/src/index.js")
1419
);
1520

1621
export type WranglerCommandOptions = CommandOptions & { debug?: boolean };
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import assert from "node:assert";
2-
3-
assert(
4-
process.env.WRANGLER,
5-
'You must provide a way to run Wrangler (WRANGLER="pnpm --silent dlx wrangler@beta" will run the latest beta)'
6-
);
1+
if (!process.env.WRANGLER) {
2+
console.warn(
3+
"No `WRANGLER` process environment variable provided - running local build of Wrangler"
4+
);
5+
}
6+
if (!process.env.WRANGLER_IMPORT) {
7+
console.warn(
8+
"No `WRANGLER_IMPORT` process environment variable provided - importing from the local build of Wrangler"
9+
);
10+
}
711

812
if (!process.env.CLOUDFLARE_ACCOUNT_ID) {
913
console.warn(
@@ -15,4 +19,5 @@ if (!process.env.CLOUDFLARE_API_TOKEN) {
1519
console.warn("No CLOUDFLARE_API_TOKEN variable provided, skipping API tests");
1620
}
1721

22+
// Exporting noop vitest setup function allows it to be loaded as a setup file.
1823
export const setup = () => {};

0 commit comments

Comments
 (0)