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;

const sharedTestOptions = {
  setupFiles: ['./src/test/cf-workers-mock.ts', './vitest.setup.ts'],
  hookTimeout: 300_000,
  testTimeout: 180_000,
  poolOptions: { forks: { singleFork: true } },
};

// Runner split: `.test.ts` = Vitest (unit/trust-boundary, ops-free), `.spec.ts` under e2e/ =
// Playwright (browser e2e, ops-gated). Without the explicit exclude, `vitest run`'s default glob
// also grabs `e2e/*.spec.ts` and crashes loading their `@playwright/test` import.
//
// Render harness (AstroContainer + Base.astro) runs in the `render` project — see
// vitest.render.config.ts — so a plain `vitest run` (gate path) executes both suites.
export default vitestConfig.realPg({
  esbuild: {
    jsx: 'automatic',
  },
  test: {
    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;
    },
    projects: [
      {
        extends: true,
        test: {
          name: 'unit',
          ...sharedTestOptions,
          include: ['src/**/*.test.ts', 'src/**/*.test.tsx', 'mcp/**/*.test.ts'],
          exclude: ['e2e/**', 'node_modules/**', 'dist/**', ...RENDER_TESTS],
        },
      },
      './vitest.render.config.ts',
    ],
  },
});
