Skip to content

Sending too much data via vitest's provide configuration causes opaque/silent failures #9957

@samscott89

Description

@samscott89

What versions & operating system are you using?

wrangler 4.24.3, node v24.4.0, macOS

Please provide a link to a minimal reproduction

https://github.com/samscott89/cf-workers-bug-repro

Describe the Bug

Should be reproducible by comparing:

  • npm test-passing
  • npm test-failing
  • npm test-silently-failing
    I'll attach example logs below.

The context is: I was trying to pass in fixture data for tests so I could mock out API responses. After trying various payloads I would observe these three different results: success, a loud but opaque error, and the tests just being silently omitted entirely.

To reproduce this I have a stupid simple tests that passes in arrays of varying length based on an environment variable to simulate different size payloads.

What I'm observing is:

  • test-passing: pass
  • test-failing: I get an opaque error message of AssertionError: The expression evaluated to a falsy value: assert4(webSocket !== null)
  • test-silently-failing: seems to make the tests not even show up as tests somehow

After attaching a debugger, the webSocket !== null check is coming from here:

const res = await stub.fetch("http://placeholder", {
headers: {
Upgrade: "websocket",
"MF-Vitest-Worker-Data": structuredSerializableStringify({
filePath: pathToFileURL(workerPath).href,
name: method,
data,
cwd: process.cwd(),
}),
},
});
const webSocket = res.webSocket;
assert(webSocket !== null);

I'm pretty sure what is happening is that when the payload gets large enough it leads to the websocket connection failing which triggers the assert.

I'm not sure about the silently failing one though. Possibly a race condition which leads to the test framework not seeing the error?

In terms of expected behaviour: it might be nice if the assert was a bit more descriptive? Or perhaps there could be an explicit error if the payload for "MF-Vitest-Worker-Data" is too large.

On the other hand, I'm still wrapping my head around how to be effective with Workers when not having access to things like node/the filesystem in the typical way. So the way I'm trying to use provide to pass in data might be an anti-pattern. As an aside if you have any pointers that would be appreciated :)

Please provide any relevant error logs

cf-workers-bug-repro on  main via  v24.4.0
❯ npm run test-passing

> cf-workers-bug-repro@0.0.0 test-passing
> ARRAY_LENGTH=100 vitest run

Using array length: 100

 RUN  v3.2.4 /Users/sam/work/cf-workers-bug-repro

[vpw:info] Starting isolated runtimes for vitest.config.mts...
[mf:warn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-07-09",
but you've requested "2025-07-12". Falling back to "2025-07-09"...
 ✓ test/index.spec.ts (2 tests) 13ms
   ✓ Hello World worker > responds with Hello World! (unit style) 6ms
   ✓ Hello World worker > responds with Hello World! (integration style) 3ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  12:49:52
   Duration  620ms (transform 19ms, setup 0ms, collect 19ms, tests 13ms, environment 0ms, prepare 91ms)

[vpw:debug] Shutting down runtimes...



cf-workers-bug-repro on  main via  v24.4.0
❯ npm run test-failing

> cf-workers-bug-repro@0.0.0 test-failing
> ARRAY_LENGTH=64000 vitest run

Using array length: 64000

 RUN  v3.2.4 /Users/sam/work/cf-workers-bug-repro

[vpw:info] Starting isolated runtimes for vitest.config.mts...
[mf:warn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-07-09",
but you've requested "2025-07-12". Falling back to "2025-07-09"...
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
AssertionError: The expression evaluated to a falsy value:

  assert4(webSocket !== null)

 ❯ runTests node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1588:3
 ❯ process.processTicksAndRejections node:internal/process/task_queues:105:5
 ❯ executeMethod node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1831:19
 ❯ Object.runTests node_modules/@cloudflare/vitest-pool-workers/dist/pool/index.mjs:1850:7
 ❯ executeTests node_modules/vitest/dist/chunks/coverage.DL5VHqXY.js:3421:4
 ❯ node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:9638:6
 ❯ Vitest.runFiles node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:9666:10
 ❯ Vitest.start node_modules/vitest/dist/chunks/cli-api.BkDphVBG.js:9554:18

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯


 Test Files   (1)
      Tests  no tests
     Errors  1 error
   Start at  12:49:55
   Duration  1.40s (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)

[vpw:debug] Shutting down runtimes...



cf-workers-bug-repro on  main via  v24.4.0
❯ npm run test-silently-failing

> cf-workers-bug-repro@0.0.0 test-silently-failing
> ARRAY_LENGTH=128000 vitest run

Using array length: 128000

 RUN  v3.2.4 /Users/sam/work/cf-workers-bug-repro

[vpw:info] Starting isolated runtimes for vitest.config.mts...
[mf:warn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-07-09",
but you've requested "2025-07-12". Falling back to "2025-07-09"...

 Test Files 0 passed (1)
      Tests 0 passed (0)
   Start at 12:49:58
   Duration 376ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that isn't workingvitestRelating to the Workers Vitest integration

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions