import path from 'node:path';
import { fileURLToPath } from 'node:url';

{{#if storybook}}import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
{{/if}}import react from '@vitejs/plugin-react';
{{#if storybook}}import { playwright } from '@vitest/browser-playwright';
{{/if}}import { defineConfig } from 'vitest/config';

{{#if storybook}}const dirname = path.dirname(fileURLToPath(import.meta.url));

{{/if}}export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  test: {
{{#if storybook}}    projects: [
      {
        extends: true,
        test: {
          name: 'unit',
          environment: 'jsdom',
          setupFiles: ['./src/test/setup.ts'],
          globals: true,
          include: ['src/**/*.test.{ts,tsx}'],
        },
      },
      {
        extends: true,
        plugins: [
          storybookTest({
            configDir: path.join(dirname, '.storybook'),
          }),
        ],
        test: {
          name: 'storybook',
          browser: {
            enabled: true,
            headless: true,
            provider: playwright(),
            instances: [{ browser: 'chromium' }],
          },
        },
      },
    ],
{{else}}    environment: 'jsdom',
    setupFiles: ['./src/test/setup.ts'],
    globals: true,
    include: ['src/**/*.test.{ts,tsx}'],
{{/if}}  },
});
