import { defineConfig } from "vitest/config"; /** * One worker per shard. A shard owns its whole topology — in-process freight * app, database, payment API, gateway mock, broker vhost — so files can run in * parallel without sharing anything mutable. See src/app.ts. */ const SHARDS = Number(process.env.IT_SHARDS ?? 1); export default defineConfig({ test: { include: ["src/**/*.it.ts"], globalSetup: ["src/global-setup.ts"], pool: "forks", // Pinned min = max: VITEST_POOL_ID is the shard key, and a worker that vitest // declines to spawn is a shard whose containers are idling. poolOptions: { forks: { minForks: SHARDS, maxForks: SHARDS } }, fileParallelism: SHARDS > 1, // The freight app boots ONCE per worker and is memoised in module scope. // With isolation on, every file would pay a fresh Nest boot (60 modules, // TypeORM, 5 seeders) — 25 boots instead of `SHARDS`. isolate: false, testTimeout: 180_000, hookTimeout: 180_000, // Booking/scheduling steps are not idempotent — a retry would assert // against a half-advanced booking. (A whole-RUN retry is now safe, because // `it.mjs test` re-clones every shard database first.) retry: 0, // Workers hold a pg pool, three Socket.IO gateways, a RabbitMQ channel and // live cron timers; don't wait on those handles to unwind. teardownTimeout: 20_000, reporters: ["verbose"], }, });