module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'jsdom',

  // 使用 mini-testing-utils 提供的共享 setup
  setupFilesAfterEnv: ['@d8d/mini-testing-utils/testing/setup'],

  moduleNameMapper: {
    // 测试文件中的别名映射（仅用于测试文件）
    '^@/(.*)$': '<rootDir>/src/$1',
    '^~/(.*)$': '<rootDir>/tests/$1',

    // Taro API 重定向到共享 mock
    '^@tarojs/taro$': '@d8d/mini-testing-utils/testing/taro-api-mock.ts',

    // 样式和文件映射
    '\\.(css|less|scss|sass)$': '@d8d/mini-testing-utils/testing/style-mock.js',
    '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '@d8d/mini-testing-utils/testing/file-mock.js'
  },

  testMatch: [
    '<rootDir>/tests/**/*.spec.{ts,tsx}',
    '<rootDir>/tests/**/*.test.{ts,tsx}'
  ],

  collectCoverageFrom: [
    'src/**/*.{ts,tsx}',
    '!src/**/*.d.ts',
    '!src/**/index.{ts,tsx}',
    '!src/**/*.stories.{ts,tsx}'
  ],

  coverageDirectory: 'coverage',
  coverageReporters: ['text', 'lcov', 'html'],

  testPathIgnorePatterns: [
    '/node_modules/',
    '/dist/',
    '/coverage/'
  ],

  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
    '^.+\\.(js|jsx)$': 'babel-jest'
  },

  transformIgnorePatterns: [
    '/node_modules/(?!(swiper|@tarojs)/)'
  ],

  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json']
}
