Skip to content

Commit 791b48a

Browse files
test: do not require remote bindings in basic vite e2e tests (#10759)
1 parent 9427511 commit 791b48a

File tree

7 files changed

+43
-48
lines changed

7 files changed

+43
-48
lines changed

.github/workflows/e2e.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ jobs:
109109
runs-on: ${{ matrix.os }}
110110
steps:
111111
- name: Checkout Repo
112-
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
113112
uses: actions/checkout@v4
114113
with:
115114
fetch-depth: 0
@@ -122,7 +121,7 @@ jobs:
122121
- '!**/*.md'
123122
124123
- name: Install Dependencies
125-
if: (github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group') && steps.changes.outputs.everything_but_markdown == 'true'
124+
if: steps.changes.outputs.everything_but_markdown == 'true'
126125
uses: ./.github/actions/install-dependencies
127126
with:
128127
node-version: ${{ matrix.node }}
@@ -132,18 +131,18 @@ jobs:
132131
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
133132

134133
- name: Bump package versions
135-
if: (github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group') && steps.changes.outputs.everything_but_markdown == 'true'
134+
if: steps.changes.outputs.everything_but_markdown == 'true'
136135
run: node .github/changeset-version.js
137136
env:
138137
GITHUB_TOKEN: ${{ github.token }}
139138

140139
- name: Run Vite E2E tests
141-
if: (github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group') && steps.changes.outputs.everything_but_markdown == 'true'
140+
if: steps.changes.outputs.everything_but_markdown == 'true'
142141
run: pnpm test:e2e -F @cloudflare/vite-plugin --log-order=stream
143142
timeout-minutes: 15
144143
env:
145144
NODE_DEBUG: "vite-plugin:test"
146-
# The AI tests need to connect to Cloudflare
145+
# The remote-binding tests need to connect to Cloudflare
147146
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
148147
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
149148
NODE_OPTIONS: "--max_old_space_size=8192"

packages/vite-plugin-cloudflare/e2e/basic.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,6 @@ describe("basic e2e tests", () => {
170170
});
171171
}
172172
);
173-
174-
// This test checks that wrapped bindings which rely on additional workers with an authed connection to the CF API work
175-
// They are skipped if you have not provided the necessary account id and api token.
176-
describe.skipIf(
177-
!process.env.CLOUDFLARE_ACCOUNT_ID || !process.env.CLOUDFLARE_API_TOKEN
178-
)("Workers AI", () => {
179-
test.skipIf(isBuildAndPreviewOnWindows(command))(
180-
"can serve a Worker request",
181-
async ({ expect }) => {
182-
const proc = await runLongLived(pm, command, projectPath);
183-
const url = await waitForReady(proc);
184-
185-
expect(await fetchJson(url + "/ai/")).toEqual({
186-
response: expect.stringContaining("Workers AI"),
187-
});
188-
}
189-
);
190-
});
191173
});
192174
});
193175
});

packages/vite-plugin-cloudflare/e2e/fixtures/basic/api/index.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,6 @@ export default {
2121
return Response.json(env);
2222
}
2323

24-
if (url.pathname.startsWith("/ai/")) {
25-
const messages = [
26-
{
27-
role: "user",
28-
// This prompt generates the same output relatively reliably
29-
content:
30-
"Respond with the exact text 'This is a response from Workers AI.'. Do not include any other text",
31-
},
32-
];
33-
34-
const content = await env.AI.run("@hf/thebloke/zephyr-7b-beta-awq", {
35-
messages,
36-
});
37-
if ("response" in content) {
38-
return Response.json({
39-
response: content.response,
40-
});
41-
} else {
42-
return new Response("", { status: 500 });
43-
}
44-
}
45-
4624
return env.ASSETS.fetch(request);
4725
},
4826
} satisfies ExportedHandler<Env>;

packages/vite-plugin-cloudflare/e2e/fixtures/basic/wrangler.jsonc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"binding": "ASSETS",
88
},
99
"main": "./api/index.ts",
10-
"ai": {
11-
"binding": "AI",
12-
},
1310
"vars": {
1411
"VAR_1": "var-1",
1512
},

packages/vite-plugin-cloudflare/e2e/fixtures/remote-bindings/entry-worker/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
export default {
22
async fetch(req, env) {
3+
const url = new URL(req.url);
4+
if (url.pathname.startsWith("/ai/")) {
5+
const messages = [
6+
{
7+
role: "user",
8+
// This prompt generates the same output relatively reliably
9+
content:
10+
"Respond with the exact text 'This is a response from Workers AI.'. Do not include any other text",
11+
},
12+
];
13+
14+
const content = await env.AI.run("@hf/thebloke/zephyr-7b-beta-awq", {
15+
messages,
16+
});
17+
if ("response" in content) {
18+
return Response.json({
19+
response: content.response,
20+
});
21+
} else {
22+
return new Response("", { status: 500 });
23+
}
24+
}
25+
326
return Response.json({
427
localWorkerResponse: await (await env["LOCAL_WORKER"].fetch(req)).json(),
528
remoteWorkerResponse: await (

packages/vite-plugin-cloudflare/e2e/fixtures/remote-bindings/entry-worker/wrangler.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"main": "./src/index.ts",
44
"compatibility_date": "2024-12-30",
55
"compatibility_flags": ["nodejs_compat"],
6+
"ai": {
7+
"binding": "AI",
8+
},
69
"services": [
710
{
811
"binding": "LOCAL_WORKER",

packages/vite-plugin-cloudflare/e2e/remote-bindings.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ if (!process.env.CLOUDFLARE_ACCOUNT_ID || !process.env.CLOUDFLARE_API_TOKEN) {
6666
});
6767
}
6868
);
69+
70+
// This test checks that wrapped bindings (e.g. AI) which rely on additional workers with an authed connection to the CF API work
71+
test.skipIf(isBuildAndPreviewOnWindows(command))(
72+
"Wrapped bindings (e.g. Workers AI) can serve a request",
73+
async ({ expect }) => {
74+
const proc = await runLongLived("pnpm", command, projectPath);
75+
const url = await waitForReady(proc);
76+
77+
expect(await fetchJson(url + "/ai/")).toEqual({
78+
response: expect.stringContaining("Workers AI"),
79+
});
80+
}
81+
);
6982
});
7083

7184
test("reflects changes applied during dev", async ({ expect }) => {

0 commit comments

Comments
 (0)