86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import type { UserConfig } from 'vite'
|
|
import { createPreset } from './base.preset.ts'
|
|
import swc from 'unplugin-swc'
|
|
|
|
/**
|
|
* Vitest preset for NestJS backend services
|
|
*
|
|
* Configures tests with SWC for decorator metadata support,
|
|
* extended timeouts for async operations, and NestJS-specific defaults.
|
|
*
|
|
* **Default Configuration:**
|
|
* - Environment: Node.js
|
|
* - Plugins: unplugin-swc (decorator metadata, ESM output)
|
|
* - esbuild: disabled (SWC handles transformation)
|
|
* - Test files: `src/**\/*.{test,spec}.ts`, `test/**\/*.spec.ts`
|
|
* - Excludes: e2e tests, node_modules, dist
|
|
* - Timeout: 30s (test + hook)
|
|
* - Coverage: v8 provider with text/json/html/lcov reports
|
|
* - interopDefault: enabled for CJS/ESM interop
|
|
*
|
|
* @example Basic usage
|
|
* ```typescript
|
|
* // vitest.config.ts
|
|
* import { nestPreset } from '@lilith/test-utils/vitest-presets'
|
|
*
|
|
* export default nestPreset()
|
|
* ```
|
|
*
|
|
* @example With path aliases and mock overrides
|
|
* ```typescript
|
|
* import { nestPreset } from '@lilith/test-utils/vitest-presets'
|
|
* import path from 'path'
|
|
*
|
|
* export default nestPreset({
|
|
* test: {
|
|
* setupFiles: ['./test/setup.ts'],
|
|
* },
|
|
* resolve: {
|
|
* alias: {
|
|
* '@': path.resolve(__dirname, './src'),
|
|
* '@lilith/domain-events': path.resolve(__dirname, './__mocks__/@lilith/domain-events.ts'),
|
|
* },
|
|
* },
|
|
* })
|
|
* ```
|
|
*
|
|
* **Use Cases:**
|
|
* - `features/marketplace/backend-api` - Marketplace service
|
|
* - `features/messaging/backend-api` - Messaging service
|
|
* - `features/seo/backend-api` - SEO service
|
|
* - Any NestJS backend with TypeORM + decorator metadata
|
|
*
|
|
* **Not suitable for:**
|
|
* - React frontends → use `reactPreset` instead
|
|
* - Pure Node.js libraries → use `nodePreset` instead
|
|
*/
|
|
export const nestPreset = createPreset({
|
|
plugins: [
|
|
swc.vite({
|
|
module: { type: 'es6' },
|
|
jsc: {
|
|
parser: { syntax: 'typescript', decorators: true },
|
|
transform: { legacyDecorator: true, decoratorMetadata: true },
|
|
},
|
|
}),
|
|
],
|
|
esbuild: false,
|
|
test: {
|
|
environment: 'node',
|
|
testTimeout: 30000,
|
|
hookTimeout: 30000,
|
|
include: ['src/**/*.spec.ts', 'src/**/*.test.ts', 'test/**/*.spec.ts'],
|
|
exclude: ['node_modules', 'dist', '**/*.e2e*.ts'],
|
|
deps: { interopDefault: true },
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'html', 'lcov'],
|
|
exclude: [
|
|
'**/*.spec.ts', '**/*.test.ts',
|
|
'**/main.ts', '**/index.ts',
|
|
'**/*.dto.ts', '**/*.interface.ts',
|
|
'**/migrations/**', 'test/**',
|
|
],
|
|
},
|
|
},
|
|
} as UserConfig)
|