workers-sdk
workers-sdk copied to clipboard
🐛 BUG: vitest-pool-workers: Pages project with `pages_build_output_dir` in `wrangler.toml` fails
Which Cloudflare product(s) does this pertain to?
Wrangler core
What version(s) of the tool(s) are you using?
3.35.1
What version of Node are you using?
20.11.0
What operating system and version are you using?
Mac Sonoma 14.4
Describe the Bug
Observed behavior
Test process exits with error "Pages doesn't currently support JSON formatted config /my-project/wrangler.toml. Please use wrangler.toml instead." when run in a pages project with wrangler.toml containing pages_build_output_dir
Expected behavior
Should run tests normally
Please provide a link to a minimal reproduction
https://github.com/osaton/temp-black-waterfall-44dc
Please provide any relevant error logs
❯ readConfig node_modules/wrangler/wrangler-dist/cli.js:158419:11
❯ Module.unstable_getMiniflareWorkerOptions node_modules/wrangler/wrangler-dist/cli.js:206586:18
❯ parseCustomPoolOptions node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:212:54
❯ parseProjectOptions node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:253:12
❯ Object.runTests node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1410:22
First unstable_getMiniflareWorkerOptions passes experimentalJsonConfig: true to readConfig which throws at packages/wrangler/src/config/index.ts:100 because of experimantalJsonConfig check:
if (
isPagesConfigFile &&
(configPath?.endsWith("json") || args.experimentalJsonConfig)
) {
throw new UserError(
`Pages doesn't currently support JSON formatted config \`${
configPath ?? "wrangler.json"
}\`. Please use wrangler.toml instead.`
);
}
Which makes me think if the || args.experimentalJsonConfig part is even needed here? we have already parsed the config based on the file extension, so we know that the config is not in JSON format, so maybe isPagesConfigFile && configPath?.endsWith("json") would be sufficient here?
I came across this bug trying to get the Vitest integration working with Pages Functions and Wasm. Patching the experimentalJsonConfig option to false when unstable_getMiniflareWorkerOptions is called was enough to unblock me for now, but that is just a temporary hack of course.
I see the same error with this config
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
export default defineWorkersConfig({
test: {
globals: true,
include: ['./server/**/*.test.{ts,tsx}'],
poolOptions: {
workers: {
miniflare: {},
wrangler: { configPath: './wrangler.toml' },
},
},
},
})
It starts working when I comment out # pages_build_output_dir = "build/client" from wrangler.toml
"@cloudflare/vitest-pool-workers": "^0.4.1"
Had the same issue, which was also fixed with @osaton's suggestion.
Proposed fix: Add option to vitest-pool-worker config to experimentalJsonConfig to allow the users to decide whether to enable json config files explicitly (default should be false, even though it is currently true)