const nextJest = require('next/jest')

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: './',
})

// Add any custom config to be passed to Jest
const customJestConfig = {
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  testEnvironment: 'jest-environment-jsdom',
  moduleNameMapper: {
    '^@pages/(.*)$': '<rootDir>/pages/$1',
    '^@/(.*)$': '<rootDir>/src/$1',
    '^@app/(.*)$': '<rootDir>/src/app/$1',
    '^@assets/(.*)$': '<rootDir>/src/assets/$1',
    '^@components/(.*)$': '<rootDir>/src/components/$1',
    '^@config/(.*)$': '<rootDir>/src/config/$1',
    '^@contexts/(.*)$': '<rootDir>/src/contexts/$1',
    '^@interfaces/(.*)$': '<rootDir>/src/interfaces/$1',
    '^@libs/(.*)$': '<rootDir>/src/libs/$1',
    '^@providers/(.*)$': '<rootDir>/src/providers/$1',
    '^@utils/(.*)$': '<rootDir>/src/utils/$1',
    // Handle specific aliases if generic one causes issues, but trying generic first matching tsconfig
    // '^@(.*)$': '<rootDir>/src/$1',
  },
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
