import { defineConfig } from 'vitest/config'
/**
* Vitest Configuration - Optimized for Memory-Intensive Tests
*
* Handles ONNX transformer model testing (4-8GB memory requirement)
* Based on 2024-2025 best practices
* THE CORRECTNESS GATE: this is the config a bare `vitest run` (no
* `--config` flag) picks up — the delta gate and CI both invoke it that
* way. See CONTRIBUTING.md's "Test gate" section for the full picture.
* Wall-clock/scale benchmarks and tests whose outcome depends on the host
* machine or network rather than the code are excluded below and run on
* demand instead, in their own slot: `npm run test:perf`.
*/
export default defineConfig({
test: {
globals: true,
setupFiles: ['./tests/setup.ts'],
environment: 'node',
// MEMORY OPTIMIZATION: Use forks for better memory isolation
pool: 'forks',
poolOptions: {
forks: {
maxForks: 1, // One test file at a time
minForks: 1,
singleFork: true, // Sequential execution
isolate: true // Isolate test files
}
},
// TIMEOUTS: Extended for ONNX model loading
testTimeout: 120000, // 2 minutes per test
hookTimeout: 60000, // 1 minute for hooks
teardownTimeout: 10000,
// PARALLELISM: Disabled to prevent memory exhaustion
maxConcurrency: 1,
fileParallelism: false,
// INCLUDE/EXCLUDE
include: ['tests/**/*.{test,spec}.{js,ts}'],
exclude: [
'node_modules/**',
'dist/**',
'scripts/**',
'**/*.browser.test.ts',
// Wall-clock/scale benchmark family — timing assertions and scale
// sweeps whose pass/fail depends on the host machine's speed, not on
// the code. Whole files only (a file that mixes correctness describes
// with a perf describe stays in the gate). Run on demand via
// `npm run test:perf`, which targets exactly this list.
'tests/performance/**',
'tests/critical-performance-benchmark.test.ts',
'tests/api/performance-benchmarks.test.ts',
// Environment-dependent by construction, not timing-based:
// package-size-limit shells out to the `npm` CLI (not guaranteed
// present — the functional gate lane is Bun-only host-mode with no
// Node.js runtime) and parses npm-version-specific `npm pack` notice
// text; model-loading's "Real Model Download Integration" case makes
// a genuine, unmocked network call to HuggingFace (its own header
// says "Uses REAL transformer models - NO MOCKING"), and the whole
// file imports `../src/embeddings/model-manager.js`, which no longer
// exists anywhere under src/ — neither belongs in a gate that must be
// deterministic.
'tests/package-size-limit.test.ts',
'tests/model-loading.test.ts'
],
// REPORTERS: Dot for CI, verbose for local
reporters: process.env.CI ? ['dot'] : ['default'],
// RETRY: Once in CI for flaky tests
retry: process.env.CI ? 1 : 0,
// SHARDING: Support test splitting
// Use: VITEST_SHARD=1/4 npm test
shard: process.env.VITEST_SHARD
})