import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import path from "path";

const shared = {
  globals: true,
  setupFiles: ["src/__tests__/helpers/setup.ts"],
  env: {
    AMAP_API_KEY: "test-amap-key",
    DEEPSEEK_API_KEY: "test-deepseek-key",
  },
} as const;

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  test: {
    projects: [
      {
        plugins: [react()],
        resolve: { alias: { "@": path.resolve(__dirname, "src") } },
        test: {
          ...shared,
          name: "ui",
          environment: "jsdom",
          include: ["src/**/*.test.{ts,tsx}"],
          exclude: ["src/app/api/**", "src/lib/**/*.test.ts"],
        },
      },
      {
        resolve: { alias: { "@": path.resolve(__dirname, "src") } },
        test: {
          ...shared,
          name: "api",
          environment: "node",
          include: ["src/app/api/**/*.test.ts", "src/lib/**/*.test.ts"],
        },
      },
    ],
  },
});
