import { defineConfig } from "vitest/config";
import path from "path";

const sharedConfig = {
  globals: true,
  environment: "node" as const,
  clearMocks: true,
  restoreMocks: true,
  pool: "forks" as const,
  fileParallelism: false,
  testTimeout: 30000,
  hookTimeout: 30000,
};

const sharedResolve = {
  alias: {
    "@": path.resolve(__dirname),
    "@sidetrail/db": path.resolve(__dirname, "db/src"),
  },
};

export default defineConfig({
  test: {
    ...sharedConfig,
    projects: [
      {
        test: {
          ...sharedConfig,
          name: "queries",
          include: ["data/__tests__/*.test.ts"],
          exclude: ["data/__tests__/*.actions.test.ts"],
          setupFiles: ["./data/__tests__/setup.ts"],
        },
        resolve: sharedResolve,
      },
      {
        test: {
          ...sharedConfig,
          name: "actions",
          include: ["data/__tests__/*.actions.test.ts"],
          setupFiles: ["./data/__tests__/setup.actions.ts"],
        },
        resolve: sharedResolve,
      },
    ],
  },
  resolve: sharedResolve,
});
