Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug with vitest + pages with wrangler.toml #6911

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading