mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
a2f2c2856e
- Create mock at __mocks__/@ruvector/nervous-system-wasm.ts - Add moduleNameMapper entry in jest.config.js - Update .gitignore to allow @ruvector mock directory - Fixes "Unexpected token 'export'" error in CI tests The mock provides stub implementations of all WASM classes (Hypervector, HdcMemory, BTSPLayer, GlobalWorkspace, etc.) for Jest tests while the real WASM module is used in production. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
154 lines
5.0 KiB
JavaScript
154 lines
5.0 KiB
JavaScript
// CRITICAL: Set NODE_ENV before any modules load
|
||
// This ensures AdapterConfig correctly detects test environment
|
||
process.env.NODE_ENV = 'test';
|
||
|
||
module.exports = {
|
||
preset: 'ts-jest',
|
||
testEnvironment: 'node',
|
||
|
||
// CRITICAL: Global setup/teardown to prevent process.cwd() errors
|
||
globalSetup: '<rootDir>/jest.global-setup.ts',
|
||
globalTeardown: '<rootDir>/jest.global-teardown.ts',
|
||
|
||
roots: ['<rootDir>/src', '<rootDir>/tests'],
|
||
testMatch: [
|
||
'**/__tests__/**/*.+(ts|tsx|js)',
|
||
'**/*.(test|spec).+(ts|tsx|js)'
|
||
],
|
||
transform: {
|
||
'^.+\\.(ts|tsx)$': ['ts-jest', {
|
||
tsconfig: {
|
||
skipLibCheck: true,
|
||
skipDefaultLibCheck: true
|
||
},
|
||
isolatedModules: true
|
||
}]
|
||
},
|
||
|
||
// CRITICAL: Coverage configuration - enabled via --coverage flag
|
||
collectCoverage: false, // Set to true via CLI --coverage flag
|
||
collectCoverageFrom: [
|
||
'src/**/*.{ts,tsx}',
|
||
'!src/**/*.d.ts',
|
||
'!src/**/*.test.ts',
|
||
'!src/**/__mocks__/**',
|
||
'!src/**/types/**',
|
||
'!src/**/index.ts'
|
||
],
|
||
coverageDirectory: 'coverage',
|
||
coverageReporters: [
|
||
'text',
|
||
'lcov',
|
||
'html',
|
||
'json-summary'
|
||
],
|
||
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts', '<rootDir>/tests/setup.ts'],
|
||
testEnvironmentOptions: {
|
||
// Use dynamic cwd - process.cwd() at config load time is stable
|
||
cwd: process.cwd()
|
||
},
|
||
moduleNameMapper: {
|
||
'^@/(.*)$': '<rootDir>/src/$1',
|
||
'^@core/(.*)$': '<rootDir>/src/core/$1',
|
||
'^@agents/(.*)$': '<rootDir>/src/agents/$1',
|
||
'^@cli/(.*)$': '<rootDir>/src/cli/$1',
|
||
'^@utils/(.*)$': '<rootDir>/src/utils/$1',
|
||
'^@types$': '<rootDir>/src/types/index.ts',
|
||
'^@types/(.*)$': '<rootDir>/src/types/$1',
|
||
'^@mcp/(.*)$': '<rootDir>/src/mcp/$1',
|
||
'^@learning/(.*)$': '<rootDir>/src/learning/$1',
|
||
'^@reasoning/(.*)$': '<rootDir>/src/reasoning/$1',
|
||
'^@streaming/(.*)$': '<rootDir>/src/streaming/$1',
|
||
'^@routing/(.*)$': '<rootDir>/src/core/routing/$1',
|
||
'^@memory/(.*)$': '<rootDir>/src/memory/$1',
|
||
// Mock ESM modules to avoid "Unexpected token 'export'" errors
|
||
'^agentdb$': '<rootDir>/__mocks__/agentdb.ts',
|
||
'^@ruvector/nervous-system-wasm$': '<rootDir>/__mocks__/@ruvector/nervous-system-wasm.ts',
|
||
// Map .js imports to .ts source files for Jest
|
||
'^(\\.{1,2}/.*)\\.js$': '$1'
|
||
},
|
||
// Memory optimization settings - Enhanced for DevPod
|
||
maxWorkers: 1, // Reduced from 2 to 1 for maximum safety
|
||
workerIdleMemoryLimit: '384MB', // More aggressive: 512MB → 384MB
|
||
testTimeout: 30000, // Increased: 15s → 20s for better cleanup time
|
||
cache: true, // Enable caching to reduce compilation overhead
|
||
cacheDirectory: '/tmp/jest-cache', // Explicit cache location
|
||
maxConcurrency: 2, // Limit concurrent test suites
|
||
bail: false, // Continue on test failures to complete cleanup
|
||
clearMocks: true, // Auto-clear mocks between tests
|
||
resetMocks: true, // Reset mock state between tests
|
||
restoreMocks: true, // Restore original implementations
|
||
|
||
// Advanced leak detection - Balanced approach
|
||
detectLeaks: false, // Disabled - too aggressive for integration tests
|
||
detectOpenHandles: true, // Find unclosed resources
|
||
forceExit: false, // Allow graceful exit
|
||
|
||
// Transform ESM modules (faker-js, uuid, agentdb, ruvector WASM)
|
||
transformIgnorePatterns: [
|
||
'node_modules/(?!(@faker-js|@ruvector/nervous-system-wasm|inquirer|cli-cursor|cli-spinners|ora|chalk|strip-ansi|ansi-regex|is-fullwidth-code-point|string-width|wrap-ansi|cliui|uuid|agentdb)/)'
|
||
],
|
||
|
||
// Module handling - reduce loading overhead
|
||
modulePathIgnorePatterns: [
|
||
'<rootDir>/dist/',
|
||
'<rootDir>/coverage/',
|
||
'<rootDir>/node_modules/.cache/'
|
||
],
|
||
|
||
// Test path ignoring to reduce discovery overhead
|
||
testPathIgnorePatterns: [
|
||
'/node_modules/',
|
||
'/dist/',
|
||
'/coverage/',
|
||
'\\.skip\\.(test|spec)\\.(ts|js)$',
|
||
// CRITICAL: Benchmark and code-intelligence tests corrupt tree-sitter native module state
|
||
// They must run in separate Jest projects (jest.config.benchmarks.js, jest.config.code-intelligence.js)
|
||
'/benchmarks/',
|
||
'benchmarks\\.test\\.(ts|js)$',
|
||
'/code-intelligence/'
|
||
],
|
||
|
||
// Custom reporters for memory tracking
|
||
reporters: [
|
||
'default',
|
||
['<rootDir>/tests/utils/memory-reporter.js', {
|
||
enabled: process.env.TRACK_MEMORY === 'true'
|
||
}],
|
||
// JUnit reporter for CI integration (generates junit.xml)
|
||
['jest-junit', {
|
||
outputDirectory: '.',
|
||
outputName: 'junit.xml',
|
||
classNameTemplate: '{classname}',
|
||
titleTemplate: '{title}',
|
||
ancestorSeparator: ' › ',
|
||
usePathForSuiteName: true
|
||
}]
|
||
],
|
||
|
||
// Force garbage collection between test files
|
||
testSequencer: '<rootDir>/tests/sequencers/MemorySafeSequencer.js',
|
||
|
||
// Coverage thresholds - Migration targets
|
||
coverageThreshold: {
|
||
global: {
|
||
branches: 75,
|
||
functions: 80,
|
||
lines: 80,
|
||
statements: 80
|
||
},
|
||
// Critical path coverage (higher threshold)
|
||
'./src/core/': {
|
||
branches: 85,
|
||
functions: 85,
|
||
lines: 85,
|
||
statements: 85
|
||
},
|
||
'./src/agents/': {
|
||
branches: 80,
|
||
functions: 80,
|
||
lines: 80,
|
||
statements: 80
|
||
}
|
||
}
|
||
}; |