Skip to content

Commit

Permalink
fix bug with vitest + pages with wrangler.toml (#6911)
Browse files Browse the repository at this point in the history
* infer experimentalJsonConfig from file ext

* changeset
  • Loading branch information
emily-shen authored Oct 7, 2024
1 parent d696850 commit 30b7328
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/pretty-cherries-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: infer experimentalJsonConfig from file extension

Fixes [#5768](https://github.com/cloudflare/workers-sdk/issues/5768) - issue with vitest and Pages projects with wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pages-with-config

Tests for regression of [#5768](https://github.com/cloudflare/workers-sdk/issues/5768)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, it } from "vitest";

it("should run tests even if Pages project specifies wrangler.toml", () => {
expect(1).toBe(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.node.json",
"include": ["./*.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersProject({
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.toml" },
},
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#:schema node_modules/wrangler/config-schema.json
name = "pages-with-config"
compatibility_date = "2024-09-19"
compatibility_flags = ["nodejs_compat"]
pages_build_output_dir = "public"

9 changes: 8 additions & 1 deletion packages/wrangler/src/api/integrations/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,15 @@ export function unstable_getMiniflareWorkerOptions(
define: Record<string, string>;
main?: string;
} {
// experimental json is usually enabled via a cli arg,
// so it cannot be passed to the vitest integration.
// instead we infer it from the config path (instead of setting a default)
// because wrangler.json is not compatible with pages.
const isJsonConfigFile =
configPath.endsWith(".json") || configPath.endsWith(".jsonc");

const config = readConfig(configPath, {
experimentalJsonConfig: true,
experimentalJsonConfig: isJsonConfigFile,
env,
});

Expand Down

0 comments on commit 30b7328

Please sign in to comment.