import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';

import { jsdomProject, nodeProject } from '@spoon/vitest-config';

const dirname = path.dirname(fileURLToPath(import.meta.url));
const srcAlias = path.join(dirname, 'src');
const withNextAlias = <T extends object>(project: T) => ({
  ...project,
  resolve: {
    alias: {
      '@': srcAlias,
    },
  },
});

export default defineConfig({
  resolve: {
    alias: {
      '@': srcAlias,
    },
  },
  test: {
    projects: [
      withNextAlias(nodeProject('unit', ['tests/unit/**/*.test.{ts,tsx}'])),
      withNextAlias(
        nodeProject('integration', ['tests/integration/**/*.test.{ts,tsx}']),
      ),
      withNextAlias(
        jsdomProject('component', ['tests/component/**/*.test.{ts,tsx}']),
      ),
    ],
  },
});
