Skip to content

Commit 7049bc0

Browse files
authored
Merge branch 'main' into push-oxmlnmluomut
2 parents 87aca00 + a447d67 commit 7049bc0

24 files changed

+922
-801
lines changed

.changeset/heavy-wasps-switch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Preview Aliases: Force alias generation to meet stricter naming requirements.
6+
7+
For cases where CI is requesting Wrangler to generate the alias based on the branch name, we want a stricter check around the generated alias name in order to avoid version upload failures. If a valid alias name was not able to be generated, we warn and do not provide an alias (avoiding a version upload failure).

.github/workflows/e2e.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ jobs:
3232
runs-on: ${{ matrix.os }}
3333
steps:
3434
- name: Checkout Repo
35-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
3635
uses: actions/checkout@v4
3736
with:
3837
fetch-depth: 0
3938

4039
- name: Install Dependencies
41-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
4240
uses: ./.github/actions/install-dependencies
4341
with:
4442
node-version: ${{ matrix.node }}
@@ -48,21 +46,16 @@ jobs:
4846
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
4947

5048
- name: Bump package versions
51-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
5249
run: node .github/changeset-version.js
5350
env:
5451
GITHUB_TOKEN: ${{ github.token }}
5552

5653
- name: Run Wrangler E2E tests
57-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
5854
run: pnpm run test:e2e:wrangler
5955
env:
6056
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
6157
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
6258
HYPERDRIVE_DATABASE_URL: ${{ secrets.TEST_HYPERDRIVE_DATABASE_URL}}
63-
WRANGLER: node --no-warnings ${{ github.workspace}}/packages/wrangler/bin/wrangler.js
64-
WRANGLER_IMPORT: ${{ github.workspace}}/packages/wrangler/wrangler-dist/cli.js
65-
MINIFLARE_IMPORT: ${{ github.workspace}}/packages/miniflare/dist/src/index.js
6659
NODE_OPTIONS: "--max_old_space_size=8192"
6760
WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/
6861
TEST_REPORT_PATH: ${{ runner.temp }}/test-report/index.html

CONTRIBUTING.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,42 +330,51 @@ export default mergeConfig(
330330

331331
If you need to test the interaction of Wrangler with a real Cloudflare account, you can add an E2E test within the `packages/wrangler/e2e` folder. This lets you add a test for functionality that requires real credentials (i.e. testing whether a worker deployed from Wrangler can be accessed over the internet).
332332

333-
When you open a PR to the `workers-sdk` repo, you should expect several checks to run in CI. For most PRs (except for those which trigger the **C3 E2E (Quarantine)** Action), every check should pass (although some will be skipped).
333+
A summary of this repositories actions can be found [in the `.github/workflows` folder](.github/workflows/README.md)
334334

335-
A summary of this repositories actions can be found [here](.github/workflows/README.md)
335+
## Running E2E tests locally
336336

337-
## Running e2e tests locally
337+
A large number of Wrangler & Vite's E2E tests don't require any authentication, and can be run with no Cloudflare account credentials. These can be run as follows:
338338

339-
To run the e2e tests locally, you'll need a Cloudflare API Token and run:
339+
- **Vite:** `pnpm test:e2e -F @cloudflare/vite-plugin`, optionally providing [`CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` environment variables.](#creating-an-api-token)
340340

341-
```sh
342-
WRANGLER="node ~/path/to/workers-sdk/packages/wrangler/wrangler-dist/cli.js" CLOUDFLARE_ACCOUNT_ID=$CLOUDFLARE_TESTING_ACCOUNT_ID CLOUDFLARE_API_TOKEN=$CLOUDFLARE_TESTING_API_TOKEN pnpm run test:e2e
343-
```
341+
- **Wrangler:** `pnpm test:e2e:wrangler`, optionally providing [`CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` environment variables.](#creating-an-api-token)
344342

345343
You may optionally want to append a filename pattern to limit which e2e tests are run. Also you may want to set `--bail=n` to limit the number of fails tests to show the error before the rest of the tests finish running and to limit the noise in that output:
346344

347345
```sh
348-
WRANGLER="node ~/path/to/workers-sdk/packages/wrangler/wrangler-dist/cli.js" CLOUDFLARE_ACCOUNT_ID=$CLOUDFLARE_TESTING_ACCOUNT_ID CLOUDFLARE_API_TOKEN=$CLOUDFLARE_TESTING_API_TOKEN pnpm run test:e2e [file-pattern] --bail=1
346+
# Vite
347+
pnpm test:e2e -F @cloudflare/vite-plugin [file-pattern] --bail=1
348+
349+
# Wrangler
350+
pnpm test:e2e:wrangler [file-pattern] --bail=1
349351
```
350352

351353
### Creating an API Token
352354

355+
If you want to run the E2E tests that access the Cloudflare API (e.g. for testing Worker deployment and interaction with bindings), you can create an API token for running the tests:
356+
353357
1. Go to ["My Profile" > "User API Tokens"](https://dash.cloudflare.com/profile/api-tokens)
354358
1. Click "Create Token"
355359
1. Use the "Edit Cloudflare Workers" template
356360
1. Set "Account Resources" to "Include" the account you want to use for running the test
357-
(Note for the internal wrangler team, here we use the "DevProd Testing" account)
358-
1. Set "Zone Resources" to "All zones from an account" and the same account as above
361+
(for internal and CI use, this needs to be the "DevProd Testing" account)
362+
1. No "Zone Resources" are required for general use (for internal and CI use, this needs to be set to "All Zones")
359363
1. Click "Continue to summary"
360364
1. Verify your token works by running the curl command provided
361-
1. Set the environment variables in your terminal or in your profile file (e.g. ~/.zshrc, ~/.bashrc, ~/.profile, etc):
365+
366+
Once you've created the token, you can use it when running E2E tests to test against the API:
362367

363368
```sh
364-
export CLOUDFLARE_TESTING_ACCOUNT_ID="<Account ID for the token you just created>"
365-
export CLOUDFLARE_TESTING_API_TOKEN="<Token you just created>"
369+
# Vite
370+
CLOUDFLARE_ACCOUNT_ID="<Account ID for the token you just created>" CLOUDFLARE_API_TOKEN="<Token you just created>" pnpm test:e2e -F @cloudflare/vite-plugin [file-pattern] --bail=1
371+
372+
# Wrangler
373+
CLOUDFLARE_ACCOUNT_ID="<Account ID for the token you just created>" CLOUDFLARE_API_TOKEN="<Token you just created>" pnpm test:e2e:wrangler [file-pattern] --bail=1
366374
```
367375

368-
Note: Workers created in the e2e tests that fail might not always be cleaned up (deleted). Internal users with access to the "DevProd Testing" account can rely on an automated job to clean up the Workers based on the format of the name. If you use another account, please be aware you may want to manually delete the Workers yourself.
376+
> [!NOTE]
377+
> Workers and other resources created in the E2E tests might not always be cleaned up. Internal users with access to the "DevProd Testing" account can rely on an automated job to clean up the Workers and other resources, but if you use another account, please be aware you may want to manually delete the Workers and other resources yourself.
369378
370379
## Changesets
371380

packages/wrangler/e2e/cert.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it } from "vitest";
2+
import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id";
23
import {
34
generateCaCertName,
45
generateLeafCertificate,
@@ -9,7 +10,7 @@ import {
910
import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test";
1011
import { normalizeOutput } from "./helpers/normalize";
1112

12-
describe("cert", () => {
13+
describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("cert", () => {
1314
const normalize = (str: string) =>
1415
normalizeOutput(str, {
1516
[process.env.CLOUDFLARE_ACCOUNT_ID as string]: "CLOUDFLARE_ACCOUNT_ID",

packages/wrangler/e2e/deployments.test.ts

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,61 @@ const normalize = (str: string) =>
1414
[CLOUDFLARE_ACCOUNT_ID]: "CLOUDFLARE_ACCOUNT_ID",
1515
}).replaceAll(/^Author:.*$/gm, "Author: [email protected]");
1616

17-
describe("deployments", { timeout: TIMEOUT }, () => {
18-
// Note that we are sharing the workerName and helper across all these tests,
19-
// which means that these tests are not isolated from each other.
20-
// Seeded files will leak between tests.
21-
const workerName = generateResourceName();
22-
const helper = new WranglerE2ETestHelper();
23-
let deployedUrl: string;
24-
25-
it("deploys a Worker", async () => {
26-
await helper.seed({
27-
"wrangler.toml": dedent`
17+
describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)(
18+
"deployments",
19+
{ timeout: TIMEOUT },
20+
() => {
21+
// Note that we are sharing the workerName and helper across all these tests,
22+
// which means that these tests are not isolated from each other.
23+
// Seeded files will leak between tests.
24+
const workerName = generateResourceName();
25+
const helper = new WranglerE2ETestHelper();
26+
let deployedUrl: string;
27+
28+
it("deploys a Worker", async () => {
29+
await helper.seed({
30+
"wrangler.toml": dedent`
2831
name = "${workerName}"
2932
main = "src/index.ts"
3033
compatibility_date = "2023-01-01"
3134
`,
32-
"src/index.ts": dedent`
35+
"src/index.ts": dedent`
3336
export default {
3437
fetch(request) {
3538
return new Response("Hello World!")
3639
}
3740
}`,
38-
"package.json": dedent`
41+
"package.json": dedent`
3942
{
4043
"name": "${workerName}",
4144
"version": "0.0.0",
4245
"private": true
4346
}
4447
`,
45-
});
48+
});
4649

47-
const output = await helper.run(`wrangler deploy`);
50+
const output = await helper.run(`wrangler deploy`);
4851

49-
const match = output.stdout.match(
50-
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
51-
);
52-
assert(match?.groups);
53-
deployedUrl = match.groups.url;
52+
const match = output.stdout.match(
53+
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
54+
);
55+
assert(match?.groups);
56+
deployedUrl = match.groups.url;
5457

55-
const { text } = await retry(
56-
(s) => s.status !== 200,
57-
async () => {
58-
const r = await fetch(deployedUrl);
59-
return { text: await r.text(), status: r.status };
60-
}
61-
);
62-
expect(text).toMatchInlineSnapshot('"Hello World!"');
63-
});
58+
const { text } = await retry(
59+
(s) => s.status !== 200,
60+
async () => {
61+
const r = await fetch(deployedUrl);
62+
return { text: await r.text(), status: r.status };
63+
}
64+
);
65+
expect(text).toMatchInlineSnapshot('"Hello World!"');
66+
});
6467

65-
it("lists 1 deployment", async () => {
66-
const output = await helper.run(`wrangler deployments list`);
68+
it("lists 1 deployment", async () => {
69+
const output = await helper.run(`wrangler deployments list`);
6770

68-
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
71+
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
6972
"Created: TIMESTAMP
7073
7174
Source: Upload
@@ -75,38 +78,38 @@ describe("deployments", { timeout: TIMEOUT }, () => {
7578
Tag: -
7679
Message: -"
7780
`);
78-
});
81+
});
7982

80-
it("modifies & deploys a Worker", async () => {
81-
await helper.seed({
82-
"src/index.ts": dedent`
83+
it("modifies & deploys a Worker", async () => {
84+
await helper.seed({
85+
"src/index.ts": dedent`
8386
export default {
8487
fetch(request) {
8588
return new Response("Updated Worker!")
8689
}
8790
}`,
88-
});
89-
const output = await helper.run(`wrangler deploy`);
91+
});
92+
const output = await helper.run(`wrangler deploy`);
9093

91-
const match = output.stdout.match(
92-
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
93-
);
94-
assert(match?.groups);
95-
deployedUrl = match.groups.url;
94+
const match = output.stdout.match(
95+
/(?<url>https:\/\/tmp-e2e-.+?\..+?\.workers\.dev)/
96+
);
97+
assert(match?.groups);
98+
deployedUrl = match.groups.url;
9699

97-
const { text } = await retry(
98-
(s) => s.status !== 200 || s.text === "Hello World!",
99-
async () => {
100-
const r = await fetch(deployedUrl);
101-
return { text: await r.text(), status: r.status };
102-
}
103-
);
104-
expect(text).toMatchInlineSnapshot('"Updated Worker!"');
105-
});
100+
const { text } = await retry(
101+
(s) => s.status !== 200 || s.text === "Hello World!",
102+
async () => {
103+
const r = await fetch(deployedUrl);
104+
return { text: await r.text(), status: r.status };
105+
}
106+
);
107+
expect(text).toMatchInlineSnapshot('"Updated Worker!"');
108+
});
106109

107-
it("lists 2 deployments", async () => {
108-
const dep = await helper.run(`wrangler deployments list`);
109-
expect(normalize(dep.stdout)).toMatchInlineSnapshot(`
110+
it("lists 2 deployments", async () => {
111+
const dep = await helper.run(`wrangler deployments list`);
112+
expect(normalize(dep.stdout)).toMatchInlineSnapshot(`
110113
"Created: TIMESTAMP
111114
112115
Source: Upload
@@ -124,13 +127,13 @@ describe("deployments", { timeout: TIMEOUT }, () => {
124127
Tag: -
125128
Message: -"
126129
`);
127-
});
130+
});
128131

129-
it("rolls back", async () => {
130-
const output = await helper.run(
131-
`wrangler rollback --message "A test message"`
132-
);
133-
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
132+
it("rolls back", async () => {
133+
const output = await helper.run(
134+
`wrangler rollback --message "A test message"`
135+
);
136+
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
134137
"├ Fetching latest deployment
135138
136139
├ Your current deployment has 1 version(s):
@@ -163,11 +166,11 @@ describe("deployments", { timeout: TIMEOUT }, () => {
163166
╰ SUCCESS Worker Version 00000000-0000-0000-0000-000000000000 has been deployed to 100% of traffic.
164167
Current Version ID: 00000000-0000-0000-0000-000000000000"
165168
`);
166-
});
169+
});
167170

168-
it("lists deployments", async () => {
169-
const dep = await helper.run(`wrangler deployments list`);
170-
expect(normalize(dep.stdout)).toMatchInlineSnapshot(`
171+
it("lists deployments", async () => {
172+
const dep = await helper.run(`wrangler deployments list`);
173+
expect(normalize(dep.stdout)).toMatchInlineSnapshot(`
171174
"Created: TIMESTAMP
172175
173176
Source: Upload
@@ -193,8 +196,9 @@ describe("deployments", { timeout: TIMEOUT }, () => {
193196
Tag: -
194197
Message: -"
195198
`);
196-
});
197-
});
199+
});
200+
}
201+
);
198202

199203
type AssetTestCase = {
200204
path: string;
@@ -253,7 +257,7 @@ async function checkAssets(testCases: AssetTestCase[], deployedUrl: string) {
253257
}
254258
}
255259

256-
describe("Workers + Assets deployment", () => {
260+
describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("Workers + Assets deployment", () => {
257261
let helper: WranglerE2ETestHelper;
258262
let workerName: string;
259263

packages/wrangler/e2e/dev-env.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id";
55
import { makeRoot, seed } from "./helpers/setup";
66
import { WRANGLER_IMPORT } from "./helpers/wrangler";
77

8-
describe("switching runtimes", () => {
8+
describe.skipIf(!CLOUDFLARE_ACCOUNT_ID)("switching runtimes", () => {
99
let root: string;
1010
beforeEach(async () => {
1111
root = await makeRoot();

0 commit comments

Comments
 (0)