import { vitestConfig } from '@tooling/vitest-config';

const BODY_COMPONENT_RENDER_TESTS = [
  'src/themes/**/*IndexBody.test.ts',
  'src/themes/**/*SearchBody.test.ts',
  'src/themes/**/*NotFoundBody.test.ts',
  'src/themes/**/*PostBody.test.ts',
] as const;

const RENDER_TESTS = [
  'src/themes/render.container.test.tsx',
  'src/themes/render.test.ts',
  'src/themes/magazine.render.test.ts',
  'src/themes/registry.test.ts',
  'src/pages/install/_preview.test.ts',
  ...BODY_COMPONENT_RENDER_TESTS,
] as const;

export default vitestConfig.realPg({
  oxc: {
    jsx: { runtime: 'automatic' },
  },
  test: {
    name: 'unit',
    setupFiles: ['./src/test/cf-workers-mock.ts', './vitest.setup.ts'],
    hookTimeout: 300_000,
    testTimeout: 180_000,
    maxWorkers: 1,
    // Vitest 4 shares mocked module state differently when isolation is disabled.
    // Keep one worker for the real-PG boot budget, but isolate each test file.
    isolate: true,
    onConsoleLog(log) {
      // AstroContainer validates ASTRO_CONFIG_DEFAULTS, whose markdown defaults trip Astro's own gfm/smartypants deprecation warning.
      if (log.includes('`markdown.gfm`') && log.includes('deprecated')) return false;
    },
    include: ['src/**/*.test.ts', 'src/**/*.test.tsx', 'mcp/**/*.test.ts'],
    exclude: ['e2e/**', 'node_modules/**', 'dist/**', ...RENDER_TESTS],
  },
});
