Skip to content

Commit 75453ea

Browse files
add e2e to make sure validation takes place
1 parent 8c9bc7d commit 75453ea

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
async fetch() {
3+
return new Response("Hello World!");
4+
},
5+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@vite-plugin-cloudflare-e2e/invalid-worker-env-configs",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite dev"
7+
},
8+
"devDependencies": {
9+
"@cloudflare/vite-plugin": "*",
10+
"vite": "^6.2.3"
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { cloudflare } from "@cloudflare/vite-plugin";
2+
import { defineConfig } from "vite";
3+
4+
export default defineConfig({
5+
plugins: [
6+
cloudflare({
7+
inspectorPort: false,
8+
persistState: false,
9+
viteEnvironment: { name: "worker" },
10+
}),
11+
],
12+
environments: {
13+
worker: {
14+
optimizeDeps: {
15+
exclude: ["pkg"],
16+
},
17+
},
18+
},
19+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "worker"
2+
main = "./index.js"
3+
compatibility_date = "2024-12-30"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { describe } from "vitest";
2+
import { test } from "./helpers.js";
3+
4+
// Note: the test here just makes sure that the validation does take place, for more fine grained
5+
// testing regarding the validation there are unit tests in src/__tests__/validate_worker_environments_resolved_configs.spec.ts
6+
7+
describe("during development wrangler config files are validated", () => {
8+
test("for the entry worker", async ({ expect, seed, viteDev }) => {
9+
const projectPath = await seed("invalid-worker-env-configs", "pnpm");
10+
11+
const proc = viteDev(projectPath);
12+
13+
expect(await proc.exitCode).not.toBe(0);
14+
expect(proc.stderr).toContain(
15+
"The following environment configurations are incompatible with the Cloudflare vite plugin"
16+
);
17+
});
18+
});

0 commit comments

Comments
 (0)