module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['<rootDir>/src'],
  testMatch: ['**/__tests__/**/*.test.ts', '**/__tests__/**/*.spec.ts'],
  transform: {
    '^.+\\.ts$': ['ts-jest', {
      tsconfig: {
        target: 'ES2022',
        module: 'CommonJS', // Use CommonJS for Jest
        moduleResolution: 'node',
        esModuleInterop: true,
        allowSyntheticDefaultImports: true,
        strict: false, // Less strict for tests
        skipLibCheck: true,
        forceConsistentCasingInFileNames: false, // Allow index signature access
        resolveJsonModule: true,
        declaration: false, // Don't need declarations for tests
        declarationMap: false,
        sourceMap: true,
        noImplicitAny: false, // Allow implicit any in tests
      },
      useESM: false, // Use CommonJS for Jest even though package.json has "type": "module"
      isolatedModules: true, // Skip type checking - just transpile
    }],
  },
  moduleFileExtensions: ['ts', 'js', 'json'],
  moduleNameMapper: {
    '^@4runr/shared$': '<rootDir>/../../packages/shared/src',
    '^@4runr/shared/(.*)$': '<rootDir>/../../packages/shared/src/$1',
    '^@4runr/sentinel$': '<rootDir>/../../packages/sentinel/src',
    '^@4runr/sentinel/(.*)$': '<rootDir>/../../packages/sentinel/src/$1',
    '^@4runr/shield$': '<rootDir>/../../packages/shield/src',
    '^@4runr/shield/(.*)$': '<rootDir>/../../packages/shield/src/$1',
    '^(\\.{1,2}/.*)\\.js$': '$1',
    '^(\\.{1,2}/.*)\\.ts$': '$1',
  },
  testPathIgnorePatterns: [
    '/node_modules/',
    '/dist/',
  ],
  collectCoverageFrom: [
    'src/**/*.ts',
    '!src/**/*.d.ts',
    '!src/**/__tests__/**',
  ],
  setupFilesAfterEnv: [],
  testTimeout: 30000,
  // Ignore dist directory
  modulePathIgnorePatterns: ['<rootDir>/dist'],
};

