import { defineConfig } from "vitest/config";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { resolve } from "path";

export default defineConfig({
  plugins: [svelte({ hot: !process.env.VITEST })],
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: ["./src/test/setup-globals.ts", "./src/test/setup.ts"],
    // `scripts/` is included so build tooling (the traceability coverage
    // engine) is covered by the normal suite rather than only by CI.
    include: ["src/**/*.{test,spec}.{js,ts}", "scripts/**/*.{test,spec}.{js,ts}"],
    coverage: {
      provider: "v8",
      reporter: ["text", "json", "html"],
      exclude: [
        "node_modules/",
        "src/test/",
        "**/*.test.ts",
        "**/*.spec.ts",
        "src-tauri/",
      ],
    },
  },
  resolve: {
    conditions: ["browser"],
    alias: {
      $lib: resolve(__dirname, "./src/lib"),
      "$lib/": resolve(__dirname, "./src/lib/"),
      "$app/environment": resolve(__dirname, "./src/test/mocks/app-environment.ts"),
      "$app/navigation": resolve(__dirname, "./src/test/mocks/app-navigation.ts"),
      "$app/stores": resolve(__dirname, "./src/test/mocks/app-stores.ts"),
    },
  },
});
