import type { Config } from 'jest'

import { pathsToModuleNameMapper } from 'ts-jest'

import { compilerOptions } from './tsconfig.json'

const config: Config = {
  displayName: 'backend',
  moduleFileExtensions: ['js', 'json', 'ts'],
  rootDir: '.',
  testRegex: '.*\\.test\\.ts$',
  transform: {
    '^.+\\.(t|j)s$': 'ts-jest',
  },
  testEnvironment: 'node',
  roots: [
    //'<rootDir>/libs/',
    '<rootDir>/apps/',
  ],
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    prefix: '<rootDir>/',
  }),
  prettierPath: null,
  coverageReporters: [
    [
      'lcov',
      {
        // We need this setting so the lcov.info file has the paths relative to
        // the project root. Without this, Sonar not be able to map the coverage to
        // the right files in case different packages have the same relative path.
        // This setting does not work on Windows - however, we only need it for the CI
        projectRoot: '../../../../',
      },
    ],
    'html',
  ],
}

export default config
