brainy/tests/configs/vitest.unit.config.ts

73 lines
No EOL
2.3 KiB
TypeScript

import { defineConfig } from 'vitest/config'
/**
* Unit Test Configuration - NO REAL AI MODELS
*
* Based on industry practices from HuggingFace, sentence-transformers, etc.
* Unit tests use mocks to avoid memory issues entirely.
*/
export default defineConfig({
test: {
globals: true,
setupFiles: ['./tests/setup-unit.ts'],
environment: 'node',
// UNIT TESTS: Fast execution, no memory issues
// v6.0.0: Increased timeouts for GraphAdjacencyIndex initialization with forks
// v8.0.4: hookTimeout 30s→60s — beforeEach init() exceeds 30s under parallel load
testTimeout: 30000, // 30 seconds
hookTimeout: 60000, // 60 seconds (beforeEach with MetadataIndexManager init under load)
teardownTimeout: 60000, // 60 seconds (vitest worker RPC under parallel load)
// Include only unit tests
include: [
'tests/unit/**/*.test.ts',
'tests/**/*.unit.test.ts'
],
// Exclude integration tests
exclude: [
'tests/integration/**',
'tests/**/*.integration.test.ts',
'tests/**/*.e2e.test.ts',
'node_modules/**'
],
// Compile-time tests (*.test-d.ts) — validates the reserved-metadata-key
// guard (@ts-expect-error assertions in tests/unit/types/) with tsc on
// every unit run. See src/types/reservedFields.ts for the contract.
typecheck: {
enabled: true,
checker: 'tsc',
include: ['tests/unit/types/**/*.test-d.ts'],
tsconfig: './tests/configs/tsconfig.typecheck.json'
},
// Use 'forks' for process isolation — 'threads' causes vitest internal
// "Timeout calling onTaskUpdate" RPC errors under heavy parallel load
pool: 'forks',
poolOptions: {
forks: {
maxForks: 8,
minForks: 2,
}
},
reporters: ['verbose'],
// Coverage for unit tests — disabled by default to avoid vitest worker
// RPC timeouts during v8 coverage collection (causes false exit code 1).
// Run with --coverage flag when needed: npx vitest run --coverage
coverage: {
enabled: false,
provider: 'v8',
reporter: ['text', 'html'],
include: ['src/**/*.ts'],
exclude: [
'src/**/*.test.ts',
'src/embeddings/worker-*.ts', // Skip worker files
'dist/**'
]
}
}
})