Skip to content

Commit 76e6014

Browse files
authored
Support serving HTML in experimental.bundledDev (#14883)
1 parent e353367 commit 76e6014

15 files changed

Lines changed: 525 additions & 432 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@cloudflare/vite-plugin": minor
3+
---
4+
5+
Serve the bundled client HTML in dev when Vite's `experimental.bundledDev` is enabled
6+
7+
Note that this feature is experimental and subject to change.
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import { test, vi } from "vitest";
22
import { page, WAIT_FOR_OPTIONS } from "../../__test-utils__";
33

4-
test("returns the correct home page", async ({ expect }) => {
5-
const content = await page.textContent("h1");
6-
expect(content).toBe("Vite + React");
7-
});
4+
export function runBaseTests() {
5+
test("returns the correct home page", async ({ expect }) => {
6+
const content = await page.textContent("h1");
7+
expect(content).toBe("Vite + React");
8+
});
89

9-
test("returns the response from the API", async ({ expect }) => {
10-
const button = page.getByRole("button", { name: "get-name" });
11-
const contentBefore = await button.innerText();
12-
expect(contentBefore).toBe("Name from API is: unknown");
13-
await button.click();
14-
await vi.waitFor(async () => {
15-
const contentAfter = await button.innerText();
16-
expect(contentAfter).toBe("Name from API is: Cloudflare");
17-
}, WAIT_FOR_OPTIONS);
18-
});
10+
test("returns the response from the API", async ({ expect }) => {
11+
const button = page.getByRole("button", { name: "get-name" });
12+
const contentBefore = await button.innerText();
13+
expect(contentBefore).toBe("Name from API is: unknown");
14+
// The outer `waitFor` re-clicks in case the initial-build `full-reload`
15+
// under `experimental.bundledDev` resets the SPA state and discards an
16+
// earlier click. The inner `waitFor` then waits for the API response after
17+
// each click so latency is tolerated.
18+
await vi.waitFor(async () => {
19+
await button.click();
20+
await vi.waitFor(
21+
async () => {
22+
const contentAfter = await button.innerText();
23+
expect(contentAfter).toBe("Name from API is: Cloudflare");
24+
},
25+
{ timeout: 1_000, interval: 100 }
26+
);
27+
}, WAIT_FOR_OPTIONS);
28+
});
29+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
import "../base-tests";
1+
import { runBaseTests } from "../base-tests";
2+
3+
runBaseTests();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe } from "vitest";
2+
import { satisfiesMinimumViteVersion } from "../../../__test-utils__";
3+
import { runBaseTests } from "../base-tests";
4+
5+
// `experimental.bundledDev` is a Vite 8+ feature, so this variant is only
6+
// exercised there. On older Vite versions the tests are skipped.
7+
describe.runIf(satisfiesMinimumViteVersion("8.0.0"))(
8+
"client-bundled-dev",
9+
() => {
10+
runBaseTests();
11+
}
12+
);

packages/vite-plugin-cloudflare/playground/spa-with-api/__tests__/custom-output-directories/spa-with-api.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as fs from "node:fs";
22
import * as path from "node:path";
33
import { describe, test, vi } from "vitest";
44
import { isBuild, rootDir, WAIT_FOR_OPTIONS } from "../../../__test-utils__";
5-
import "../base-tests";
5+
import { runBaseTests } from "../base-tests";
6+
7+
runBaseTests();
68

79
describe.runIf(isBuild)("output directories", () => {
810
test("creates the correct output directories", async ({ expect }) => {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
import "../base-tests";
1+
import { runBaseTests } from "../base-tests";
2+
3+
runBaseTests();

packages/vite-plugin-cloudflare/playground/spa-with-api/__tests__/run-worker-first/spa-with-api.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
isBuild,
77
viteTestUrl,
88
} from "../../../__test-utils__";
9-
import "../base-tests";
9+
import { runBaseTests } from "../base-tests";
10+
11+
runBaseTests();
1012

1113
test("returns the home page via the Worker", async ({ expect }) => {
1214
const response = await getResponse();

packages/vite-plugin-cloudflare/playground/spa-with-api/__tests__/spa-with-api.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
rootDir,
1010
viteTestUrl,
1111
} from "../../__test-utils__";
12-
import "./base-tests";
12+
import { runBaseTests } from "./base-tests";
13+
14+
runBaseTests();
1315

1416
test("returns the home page directly without invoking the Worker", async ({
1517
expect,

packages/vite-plugin-cloudflare/playground/spa-with-api/__tests__/static-routing/spa-with-api.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
isBuild,
77
viteTestUrl,
88
} from "../../../__test-utils__";
9-
import "../base-tests";
9+
import { runBaseTests } from "../base-tests";
10+
11+
runBaseTests();
1012

1113
test("returns the home page directly without invoking the Worker", async ({
1214
expect,

packages/vite-plugin-cloudflare/playground/spa-with-api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6+
"build:client-bundled-dev": "vite build -c ./vite.config.client-bundled-dev.ts",
67
"build:custom-output-directories": "vite build -c ./vite.config.custom-output-directories.ts",
78
"build:default": "vite build",
89
"build:https": "vite build -c ./vite.config.https.ts",
910
"build:run-worker-first": "vite build -c ./vite.config.run-worker-first.ts",
1011
"build:static-routing": "vite build -c ./vite.config.static-routing.ts",
1112
"check:type": "tsc --build",
1213
"dev": "vite dev",
14+
"dev:client-bundled-dev": "vite dev -c ./vite.config.client-bundled-dev.ts",
1315
"dev:https": "vite dev -c ./vite.config.https.ts",
1416
"dev:run-worker-first": "vite dev -c ./vite.config.run-worker-first.ts",
1517
"dev:static-routing": "vite dev -c ./vite.config.static-routing.ts",

0 commit comments

Comments
 (0)