Files
hermes-agent/web/vitest.config.ts
zhengpeng 3cf2eb1c94 test(web): run the dashboard test project in development mode
React 19 only ships `act` in its development build. The jsdom suites in
`web/` drive components through `act()`, so when vitest inherits an
ambient `NODE_ENV=production` — the shell that launched the app, a
packaged CI step, an editor terminal — `React.act` resolves to undefined
and every `createRoot` test in the project fails with
`TypeError: act is not a function`.

Pin the test worker to `NODE_ENV=development` via the project's
`test.env` so the suite no longer depends on the ambient environment.
App runtime and production builds are unaffected; this only applies to
the vitest worker.

Same class of failure as #77409 (and the same fix shape as #77421), one
workspace over: that issue and PR cover `apps/desktop/vitest.config.ts`,
while `web/vitest.config.ts` has no equivalent guard.

Before (clean main, NODE_ENV=production):
  Test Files  3 failed | 33 passed (36)
  Tests      43 failed | 232 passed (275)

After:
  Test Files  36 passed (36)
  Tests      275 passed (275)
2026-09-28 21:54:03 -05:00

42 lines
1.6 KiB
TypeScript

import { defineConfig } from "vitest/config";
import babel from "@rolldown/plugin-babel";
import react, { reactCompilerPreset } from "@vitejs/plugin-react";
/** Same component/hook-scoped compiler preset as vite.config.ts. */
function compilerPreset() {
const preset = reactCompilerPreset();
preset.rolldown.filter.code = /\/>|<\/|from\s*['"][^'"]*react/;
return preset;
}
import path from "path";
export default defineConfig({
plugins: [react(), babel({ presets: [compilerPreset()] })],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
test: {
environment: "node",
include: ["src/**/*.test.{ts,tsx}"],
// The first test in a file pays env init + full module transform, and page
// suites (SessionsPage) legitimately run 3.5-4.5s on green CI runners —
// right against vitest's 5s default, so a loaded runner tips them into a
// timeout (main run 34600757569: 5079ms). Same headroom rationale as
// apps/desktop/vitest.config.ts; genuinely hung tests still fail.
testTimeout: 15_000,
// React 19 ships `act` only in its development build, and the jsdom suites
// here drive components through `act()`. A shell that already exports
// NODE_ENV=production (the one that launched the app, a packaged CI step,
// an editor terminal) is inherited by vitest, `React.act` resolves to
// undefined, and every `createRoot` test in this project fails with
// "act is not a function". Pin the worker to development so the suite is
// independent of the ambient environment; app runtime and production
// builds are untouched.
env: {
NODE_ENV: "development",
},
},
});