diff --git a/.changeset/pretty-cherries-relate.md b/.changeset/pretty-cherries-relate.md new file mode 100644 index 000000000000..abcee5441352 --- /dev/null +++ b/.changeset/pretty-cherries-relate.md @@ -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 diff --git a/fixtures/vitest-pool-workers-examples/pages-with-config/README.md b/fixtures/vitest-pool-workers-examples/pages-with-config/README.md new file mode 100644 index 000000000000..4ca02e864f1e --- /dev/null +++ b/fixtures/vitest-pool-workers-examples/pages-with-config/README.md @@ -0,0 +1,3 @@ +# pages-with-config + +Tests for regression of [#5768](https://github.com/cloudflare/workers-sdk/issues/5768) diff --git a/fixtures/vitest-pool-workers-examples/pages-with-config/pages-config.test.ts b/fixtures/vitest-pool-workers-examples/pages-with-config/pages-config.test.ts new file mode 100644 index 000000000000..1dc4818111f2 --- /dev/null +++ b/fixtures/vitest-pool-workers-examples/pages-with-config/pages-config.test.ts @@ -0,0 +1,5 @@ +import { expect, it } from "vitest"; + +it("should run tests even if Pages project specifies wrangler.toml", () => { + expect(1).toBe(1); +}); diff --git a/fixtures/vitest-pool-workers-examples/pages-with-config/tsconfig.json b/fixtures/vitest-pool-workers-examples/pages-with-config/tsconfig.json new file mode 100644 index 000000000000..90e58bf03ef0 --- /dev/null +++ b/fixtures/vitest-pool-workers-examples/pages-with-config/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.node.json", + "include": ["./*.ts"] +} diff --git a/fixtures/vitest-pool-workers-examples/pages-with-config/vitest.config.ts b/fixtures/vitest-pool-workers-examples/pages-with-config/vitest.config.ts new file mode 100644 index 000000000000..3f34c9327a9d --- /dev/null +++ b/fixtures/vitest-pool-workers-examples/pages-with-config/vitest.config.ts @@ -0,0 +1,11 @@ +import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config"; + +export default defineWorkersProject({ + test: { + poolOptions: { + workers: { + wrangler: { configPath: "./wrangler.toml" }, + }, + }, + }, +}); diff --git a/fixtures/vitest-pool-workers-examples/pages-with-config/wrangler.toml b/fixtures/vitest-pool-workers-examples/pages-with-config/wrangler.toml new file mode 100644 index 000000000000..03a5499d8753 --- /dev/null +++ b/fixtures/vitest-pool-workers-examples/pages-with-config/wrangler.toml @@ -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" + diff --git a/packages/wrangler/src/api/integrations/platform/index.ts b/packages/wrangler/src/api/integrations/platform/index.ts index b4c730bfbb9f..df384094e939 100644 --- a/packages/wrangler/src/api/integrations/platform/index.ts +++ b/packages/wrangler/src/api/integrations/platform/index.ts @@ -247,8 +247,15 @@ export function unstable_getMiniflareWorkerOptions( define: Record; 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, });