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

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

const srcRoot = fileURLToPath(new URL('./src', import.meta.url));
const setupFile = fileURLToPath(new URL('./tests/setup.ts', import.meta.url));
const alias = {
  '~': srcRoot,
  '~/': `${srcRoot}/`,
};

const componentProject = jsdomProject('component', [
  'tests/component/**/*.test.{ts,tsx}',
]);

export default defineConfig({
  resolve: {
    alias,
  },
  test: {
    projects: [
      nodeProject('unit', ['tests/unit/**/*.test.{ts,tsx}']),
      nodeProject('integration', ['tests/integration/**/*.test.{ts,tsx}']),
      {
        ...componentProject,
        resolve: { alias },
        test: {
          ...componentProject.test,
          setupFiles: [setupFile],
        },
      },
    ],
  },
});
