Worker Typescript test debugging in VS Code

I have the most basic of cloudflare vitest test setups and want to be able to debug my tests in VS Code.
As per this CloudFlare doc on configuring vitest tests for workers in Typescript,
https://developers.cloudflare.com/workers/testing/vitest-integration/get-started/write-your-first-test/

I have package.json, typescript / vitest configuration matching what's described in that doc.

I have a single test which contains this reference to the
cloudflare:test
module
import { env, createExecutionContext, waitOnExecutionContext } from "cloudflare:test";

As per the documentation.

Now, when I run this test from the vitest cli, no problem. Test runs and works as expected.

However, when I then attempt to debug that test in VS Code, using the vitest-recommended debug config
https://vitest.dev/guide/debugging#vs-code

{
  "type": "node",
  "request": "launch",
  "name": "Debug Current Test File",
  "autoAttachChildProcesses": true,
  "skipFiles": ["<node_internals>/**", "**/node_modules/**"],
  "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
  "args": ["run", "${relativeFile}"],
  "smartStep": true,
  "console": "integratedTerminal"
}


And I try to debug my test (and again, ONLY if the above
"cloudflare:test"
module is referenced), the debugger barfs with
FAIL  index.test.ts [ src/tests/index.test.ts ]
Error: Failed to load url cloudflare:test (resolved id: cloudflare:test) in tests/index.test.ts. Does the file exist?


Anyone with better cloudflare/vitest/typescript/vs code debugging knowledge than I know why this would be the case?
Cloudflare Docs
Write unit tests against Workers.
Next generation testing framework powered by Vite
Was this page helpful?