Part 17 / Topic 3 of 8
Gotcha #2: .env.local isn't loaded automatically either
With the server-only alias in place, the first attempt at a Server Action test hit a second, different import-time failure — not from the action file itself, but from a module two hops away in its import graph (actions.ts → ../account/lib/auth → ./session → ./session-config, Part 15's own files):
$ npm run test
FAIL app/quickcart/actions.test.ts [ app/quickcart/actions.test.ts ]
Error: SESSION_PASSWORD is not set — see harness/README's Part 15 setup note.
❯ app/account/lib/session-config.ts:21:9
next dev/next build/next start all load harness/.env.local into process.env themselves — that's Next's own behavior, not something process.env.SESSION_PASSWORD does on its own. Vite does not do the equivalent for plain process.env reads by default (it only auto-populates import.meta.env.VITE_*-prefixed variables). Fix: vitest.config.mts calls Vite's own exported loadEnv("test", process.cwd(), "") helper and copies the result into process.env before the config's test block is even evaluated (examples/01-vitest-config.mts). This is the same .env.local file Part 15 already required you to create by hand with openssl rand -base64 32 — nothing new to set up, just a config-time read Vitest doesn't do for free.
Done here? The practice set for Part 17 — including the solutions — is on the part page.