Files
flyer-crawler.projectium.com/vite.config.ts
Torben Sorensen 80d2b1ffe6
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m28s
Add user database service and unit tests
- Implement user database service with functions for user management (create, find, update, delete).
- Add comprehensive unit tests for user database service using Vitest.
- Mock database interactions to ensure isolated testing.
- Create setup files for unit tests to handle database connections and global mocks.
- Introduce error handling for unique constraints and foreign key violations.
- Enhance logging for better traceability during database operations.
2025-12-04 15:30:27 -08:00

74 lines
3.0 KiB
TypeScript

// vite.config.ts
import path from 'path';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
/**
* This is the main configuration file for Vite and the Vitest 'unit' test project.
* When running `vitest`, it is orchestrated by `vitest.workspace.ts`, which
* separates the unit and integration test environments.
*/
export default defineConfig({
// Vite-specific configuration for the dev server, build, etc.
// This is inherited by all Vitest projects.
plugins: [react()],
server: {
port: 3000,
host: '0.0.0.0',
},
resolve: {
alias: {
// Use __dirname for a more robust path resolution
'@': path.resolve(__dirname, './src'),
// This alias ensures that any import of 'services/logger' is resolved
// to the browser-safe client version during the Vite build process.
// Server-side code should explicitly import 'services/logger.server'.
'services/logger': path.resolve(__dirname, './src/services/logger.client.ts'),
},
},
// Vitest-specific configuration for the 'unit' test project.
test: {
// Name this project 'unit' to distinguish it in the workspace.
name: 'unit',
// By default, Vitest does not suppress console logs.
// The onConsoleLog hook is only needed if you want to conditionally filter specific logs.
// Keeping the default behavior is often safer to avoid missing important warnings.
// Disable file parallelism to run tests sequentially (replaces --no-threads)
fileParallelism: false,
environment: 'jsdom',
globalSetup: './src/tests/setup/global-setup.ts',
setupFiles: ['./src/tests/setup/tests-setup-unit.ts'],
// Explicitly include all test files that are NOT integration tests.
include: ['src/**/*.test.{ts,tsx}'],
// Exclude integration tests and other non-test files from the unit test runner.
exclude: [
'**/node_modules/**',
'**/dist/**',
'src/tests/integration/**', // Exclude the entire integration test directory
'**/*.e2e.test.ts'
],
coverage: {
provider: 'v8',
// We remove 'text' here. The final text report will be generated by `nyc` after merging.
reporter: ['text', 'html', 'json'],
// hanging-process reporter helps identify tests that do not exit properly - comes at a high cost tho
//reporter: ['verbose', 'html', 'json', 'hanging-process'],
reportsDirectory: './.coverage/unit',
clean: true,
reportOnFailure: true, // This ensures the report generates even if tests fail
include: ['src/**/*.{ts,tsx}'],
// Refine exclusions to be more comprehensive
exclude: [
'src/main.tsx',
'src/types.ts',
'src/tests/**', // Exclude all test setup and helper files
'src/**/*.test.{ts,tsx}', // Exclude test files themselves
'src/**/*.stories.{ts,tsx}', // Exclude Storybook stories
'src/**/*.d.ts', // Exclude type definition files
'src/components/icons/**', // Exclude icon components if they are simple wrappers
],
},
},
});