import { execSync } from 'child_process';
import type { Config } from 'jest';

import { config as dotEnvConfig } from 'dotenv';
dotEnvConfig();

process.env.CI_COMMIT_SHORT_SHA ??= execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
process.env.CI_COMMIT_REF_NAME ??= execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
process.env.SQUIZ_REGION = 'au';
process.env.DEPLOYMENT_ENVIRONMENT = 'dev';
process.env.TENANT_ID ??= 'my-tenant';

// Sync object
const config: Config = {
  preset: 'ts-jest',
  testTimeout: 60_000,
  testEnvironment: 'node',

  testRegex: '.*\\.integration\\.spec\\.ts$',
  testPathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/cdk.out/', 'test.ts'],
  maxWorkers: 1,

  setupFiles: ['./src/integration-tests/test-setup.ts'],
  detectOpenHandles: true,

  globals: {
    BUILD_VERSION: process.env.CI_COMMIT_SHORT_SHA,
    BUILD_BRANCH: process.env.CI_COMMIT_REF_NAME,
  },
};

export default config;
