{{#if storybook}}import path from 'node:path';
import { fileURLToPath } from 'node:url';

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

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

{{/if}}export default defineConfig({
  plugins: [viteReact()],
  test: {
{{#if storybook}}    projects: [
      {
        extends: true,
        test: {
          name: 'unit',
          environment: 'jsdom',
          globals: true,
          include: ['**/*.test.{ts,tsx}'],
          exclude: ['node_modules', 'dist', '.storybook'],
          coverage: {
            provider: 'v8',
            reporter: ['text', 'lcov'],
            thresholds: { branches: 80, functions: 80, lines: 80, statements: 80 },
          },
        },
      },
      {
        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',
    globals: true,
    include: ['**/*.test.{ts,tsx}'],
    exclude: ['node_modules', 'dist'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'lcov'],
      thresholds: { branches: 80, functions: 80, lines: 80, statements: 80 },
    },
{{/if}}  },
});
