Files
Nathan Disidore 21e780785e Move the test toolchain to Vitest 5 (#810)
* Await the share-link rejection assertions that never ran

Four tests built an expect(...).rejects chain without awaiting it, so the
assertion settled after the test had already passed. Vitest 5 fails such
floating assertions; await them so they actually check something.

* Move the test toolchain to Vitest 5 and @cloudflare/vitest-plugin

@vitest/browser-playwright 5 needs Vitest 5, and @cloudflare/vitest-pool-workers
never supported it: the package was renamed @cloudflare/vitest-plugin, which
added Vitest 5 in 1.4.0. Rename it everywhere and move vitest to ^5.0.5.

vite-plus goes to ^1.2.0, which bundles Vitest 5.0.4 rather than 1.0.0's
5.0.1. 1.3.0 bundles 5.0.5 and would remove the last duplicate copy, but is
still inside the release-age window.

The plugin keeps running on the current Wrangler/Miniflare stack: the
cloudflare-toolchain bumps (#785) make google-hooks-upgrade flaky (ECONNRESET,
3-5 failures in 8 runs against none on main) and are left for their own change.

vitest-evals 0.17 still declares vitest <5 but works unchanged on it (harness,
judges, reporter and JSON output checked), so a peerDependencyRules entry
allows it until a release widens the range.

Supersedes #791 and #786.

* Run vp's vitest tasks without Vitest 5's filesystem module cache

Vitest 5 turns fsModuleCache on by default, and every package's vitest shares
one cache under the workspace root's node_modules. vp runs those tasks in
parallel, so when one run invalidates the cache it deletes the directory while
another is writing into it, and that run fails to start with ENOTEMPTY. vp
already caches the whole task, so the builder appends --no-fsModuleCache to
each vitest command, as it already pins the reporter.

* Turn off Vitest 5's filesystem module cache for the backend's Workers suite

vp's tasks already run without it, but a direct vitest run in the package
still uses it, and under the Workers pool every run after the first fails:
cached .txt modules come back with root-relative ids the textModules plugin
cannot read, and the pool's WebSocket rejects the larger cached modules
(1009, Message is too large).
2026-10-16 15:33:58 -05:00

18 lines
942 B
TypeScript

// Fails the suite unless it is genuinely executing inside workerd.
//
// Every package that lists this in `setupFiles` runs its tests through @cloudflare/vitest-plugin
// so they exercise the production runtime. When that pool cannot start, vitest falls back to running
// the files under Node -- and only the suites that import `cloudflare:test` or `cloudflare:workers`
// notice. `router` and `typed-storage` import neither, so they would stay green while silently
// testing the wrong runtime.
//
// `navigator.userAgent` is the cheapest unambiguous probe: workerd hardcodes it, Node does not define
// `navigator.userAgent` as this value.
if (navigator.userAgent !== "Cloudflare-Workers") {
throw new Error(
`Expected to be running inside workerd, but navigator.userAgent is ${JSON.stringify(
navigator.userAgent,
)}. The @cloudflare/vitest-plugin pool did not start -- fix that rather than deleting this check.`,
);
}