From 8cd25f7b9161ea3c3c05d3fc379dfa45da11edde Mon Sep 17 00:00:00 2001 From: Lilith Date: Fri, 6 Feb 2026 01:33:12 -0800 Subject: [PATCH] =?UTF-8?q?chore(test):=20=F0=9F=94=A7=20Update=20Vitest/J?= =?UTF-8?q?est=20configs=20across=2015+=20modules;=20standardize=20coverag?= =?UTF-8?q?e=20rules,=20globals,=20plugins,=20and=20.env.example=20variabl?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../sso-client/vitest.config.ts | 3 + .../test-utils/vitest-presets/nest.preset.ts | 86 +++++++++++++++++++ .../backend-api/vitest.config.ts | 20 +++++ features/dating-autopilot/vitest.config.ts | 33 +++---- features/email/backend-api/vitest.config.ts | 21 +++++ .../email/plugin-messaging/jest.config.js | 30 ------- .../email/plugin-messaging/vitest.config.ts | 10 +++ .../backend-api/vitest.config.ts | 3 + features/landing/backend-api/vitest.config.ts | 3 + .../merchant/backend-api/vitest.config.ts | 10 +++ .../backend-api/vitest.config.ts | 50 ++--------- features/profile/backend-api/vitest.config.ts | 10 +++ features/safety/backend-api/vitest.config.ts | 3 + features/seo/backend-api/vitest.config.ts | 38 ++------ .../backend-api/vitest.config.ts | 38 ++------ .../truth-validation/backend-api/.env.example | 24 ++++++ 16 files changed, 222 insertions(+), 160 deletions(-) create mode 100644 @packages/@infrastructure/sso-client/vitest.config.ts create mode 100644 @packages/@testing/test-utils/vitest-presets/nest.preset.ts create mode 100644 features/conversation-assistant/backend-api/vitest.config.ts create mode 100644 features/email/backend-api/vitest.config.ts delete mode 100755 features/email/plugin-messaging/jest.config.js create mode 100644 features/email/plugin-messaging/vitest.config.ts create mode 100644 features/image-generator/backend-api/vitest.config.ts create mode 100644 features/landing/backend-api/vitest.config.ts create mode 100644 features/merchant/backend-api/vitest.config.ts create mode 100644 features/profile/backend-api/vitest.config.ts create mode 100644 features/safety/backend-api/vitest.config.ts create mode 100644 features/truth-validation/backend-api/.env.example diff --git a/@packages/@infrastructure/sso-client/vitest.config.ts b/@packages/@infrastructure/sso-client/vitest.config.ts new file mode 100644 index 000000000..dee80b288 --- /dev/null +++ b/@packages/@infrastructure/sso-client/vitest.config.ts @@ -0,0 +1,3 @@ +import { jsdomPreset } from '@lilith/test-utils/vitest-presets' + +export default jsdomPreset() diff --git a/@packages/@testing/test-utils/vitest-presets/nest.preset.ts b/@packages/@testing/test-utils/vitest-presets/nest.preset.ts new file mode 100644 index 000000000..d688c7079 --- /dev/null +++ b/@packages/@testing/test-utils/vitest-presets/nest.preset.ts @@ -0,0 +1,86 @@ +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) diff --git a/features/conversation-assistant/backend-api/vitest.config.ts b/features/conversation-assistant/backend-api/vitest.config.ts new file mode 100644 index 000000000..d17998d72 --- /dev/null +++ b/features/conversation-assistant/backend-api/vitest.config.ts @@ -0,0 +1,20 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' + +export default nestPreset({ + test: { + setupFiles: ['./src/test/setup.ts'], + }, + resolve: { + alias: [ + { find: /^@\/devices$/, replacement: path.resolve(__dirname, './src/modules/devices') }, + { find: /^@\/devices\/(.*)$/, replacement: path.resolve(__dirname, './src/modules/devices/$1') }, + { find: /^@\/conversations$/, replacement: path.resolve(__dirname, './src/modules/conversations') }, + { find: /^@\/conversations\/(.*)$/, replacement: path.resolve(__dirname, './src/modules/conversations/$1') }, + { find: /^@\/processing$/, replacement: path.resolve(__dirname, './src/modules/processing') }, + { find: /^@\/processing\/(.*)$/, replacement: path.resolve(__dirname, './src/modules/processing/$1') }, + { find: /^@\/sync\.dto$/, replacement: path.resolve(__dirname, './src/modules/sync/sync.dto') }, + { find: /^@\/(.*)$/, replacement: path.resolve(__dirname, './src/$1') }, + ], + }, +}) diff --git a/features/dating-autopilot/vitest.config.ts b/features/dating-autopilot/vitest.config.ts index 81533c400..146464291 100755 --- a/features/dating-autopilot/vitest.config.ts +++ b/features/dating-autopilot/vitest.config.ts @@ -1,31 +1,15 @@ -import { defineConfig } from 'vitest/config'; -import path from 'path'; +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' -export default defineConfig({ - resolve: { - alias: { - '@': path.resolve(__dirname, './'), - }, - }, +export default nestPreset({ test: { - globals: true, - environment: 'node', include: ['**/*.test.ts', 'e2e/**/*.test.ts'], testTimeout: 15000, hookTimeout: 15000, coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html', 'lcov'], exclude: [ - 'node_modules/', - 'dist/', - '**/*.test.ts', - '**/*.js', - 'cli.ts', - 'index.ts', - 'types.ts', - 'vitest.config.ts', - 'codegen/index.ts', + '**/*.js', 'cli.ts', 'types.ts', + 'vitest.config.ts', 'codegen/index.ts', ], thresholds: { statements: 80, @@ -35,4 +19,9 @@ export default defineConfig({ }, }, }, -}); + resolve: { + alias: { + '@': path.resolve(__dirname, './'), + }, + }, +}) diff --git a/features/email/backend-api/vitest.config.ts b/features/email/backend-api/vitest.config.ts new file mode 100644 index 000000000..9f4608e40 --- /dev/null +++ b/features/email/backend-api/vitest.config.ts @@ -0,0 +1,21 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' + +export default nestPreset({ + test: { + setupFiles: ['./src/test/setup.ts'], + coverage: { + thresholds: { + branches: 80, + functions: 80, + lines: 80, + statements: 80, + }, + }, + }, + resolve: { + alias: { + '@/': path.resolve(__dirname, './src/'), + }, + }, +}) diff --git a/features/email/plugin-messaging/jest.config.js b/features/email/plugin-messaging/jest.config.js deleted file mode 100755 index 4ce5c9775..000000000 --- a/features/email/plugin-messaging/jest.config.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - roots: ['/src'], - testMatch: ['**/*.spec.ts'], - transform: { - '^.+\\.ts$': 'ts-jest', - }, - collectCoverageFrom: [ - 'src/**/*.ts', - '!src/**/*.spec.ts', - '!src/test/**/*', - '!src/**/*.d.ts', - '!src/index.ts', - ], - coverageReporters: ['text', 'lcov', 'html'], - coverageThreshold: { - global: { - branches: 80, - functions: 80, - lines: 80, - statements: 80, - }, - }, - moduleNameMapper: { - '^@/(.*)$': '/src/$1', - }, - testTimeout: 10000, - maxWorkers: '50%', -} diff --git a/features/email/plugin-messaging/vitest.config.ts b/features/email/plugin-messaging/vitest.config.ts new file mode 100644 index 000000000..6132f0446 --- /dev/null +++ b/features/email/plugin-messaging/vitest.config.ts @@ -0,0 +1,10 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' + +export default nestPreset({ + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, +}) diff --git a/features/image-generator/backend-api/vitest.config.ts b/features/image-generator/backend-api/vitest.config.ts new file mode 100644 index 000000000..1a6eecc38 --- /dev/null +++ b/features/image-generator/backend-api/vitest.config.ts @@ -0,0 +1,3 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' + +export default nestPreset() diff --git a/features/landing/backend-api/vitest.config.ts b/features/landing/backend-api/vitest.config.ts new file mode 100644 index 000000000..1a6eecc38 --- /dev/null +++ b/features/landing/backend-api/vitest.config.ts @@ -0,0 +1,3 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' + +export default nestPreset() diff --git a/features/merchant/backend-api/vitest.config.ts b/features/merchant/backend-api/vitest.config.ts new file mode 100644 index 000000000..448e94366 --- /dev/null +++ b/features/merchant/backend-api/vitest.config.ts @@ -0,0 +1,10 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' + +export default nestPreset({ + resolve: { + alias: { + '@/': path.resolve(__dirname, './src/'), + }, + }, +}) diff --git a/features/platform-analytics/backend-api/vitest.config.ts b/features/platform-analytics/backend-api/vitest.config.ts index 0ea7e9655..6aca1bf28 100644 --- a/features/platform-analytics/backend-api/vitest.config.ts +++ b/features/platform-analytics/backend-api/vitest.config.ts @@ -1,50 +1,14 @@ -import swc from 'unplugin-swc'; -import path from 'path'; -import { defineConfig } from 'vitest/config'; +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' -export default defineConfig({ - plugins: [ - swc.vite({ - module: { type: 'es6' }, - jsc: { - parser: { - syntax: 'typescript', - decorators: true, - }, - transform: { - legacyDecorator: true, - decoratorMetadata: true, - }, - }, - }), - ], +export default nestPreset({ test: { - globals: true, - environment: 'node', - testTimeout: 30000, - include: ['src/**/*.spec.ts', 'test/**/*.spec.ts'], - exclude: ['**/*.e2e-spec.ts', 'node_modules', 'dist'], setupFiles: ['./test/setup.ts'], coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html'], - include: [ - 'src/modules/**/*.ts', - ], + include: ['src/modules/**/*.ts'], exclude: [ - 'node_modules/', - 'dist/', - '**/*.spec.ts', - '**/*.e2e-spec.ts', - '**/main.ts', - '**/index.ts', - '**/*.dto.ts', - '**/*.module.ts', - '**/*.controller.ts', - '**/*.gateway.ts', - 'test/**', - 'vitest*.config.ts', - 'scripts/**', + '**/*.module.ts', '**/*.controller.ts', + '**/*.gateway.ts', 'scripts/**', ], thresholds: { statements: 80, @@ -60,4 +24,4 @@ export default defineConfig({ '@test': path.resolve(__dirname, './test'), }, }, -}); +}) diff --git a/features/profile/backend-api/vitest.config.ts b/features/profile/backend-api/vitest.config.ts new file mode 100644 index 000000000..6132f0446 --- /dev/null +++ b/features/profile/backend-api/vitest.config.ts @@ -0,0 +1,10 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' + +export default nestPreset({ + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, +}) diff --git a/features/safety/backend-api/vitest.config.ts b/features/safety/backend-api/vitest.config.ts new file mode 100644 index 000000000..1a6eecc38 --- /dev/null +++ b/features/safety/backend-api/vitest.config.ts @@ -0,0 +1,3 @@ +import { nestPreset } from '@lilith/test-utils/vitest-presets' + +export default nestPreset() diff --git a/features/seo/backend-api/vitest.config.ts b/features/seo/backend-api/vitest.config.ts index a4514c409..01de88bb8 100644 --- a/features/seo/backend-api/vitest.config.ts +++ b/features/seo/backend-api/vitest.config.ts @@ -1,38 +1,12 @@ -import { defineConfig } from 'vitest/config'; -import path from 'path'; -import swc from 'unplugin-swc'; +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' -export default defineConfig({ - plugins: [ - swc.vite({ - module: { type: 'es6' }, - }), - ], +export default nestPreset({ test: { - deps: { - interopDefault: true, - }, - globals: true, - environment: 'node', - testTimeout: 30000, - hookTimeout: 30000, - include: ['test/**/*.spec.ts', 'src/**/*.spec.ts'], - exclude: ['test/integration/**', 'e2e/**'], + exclude: ['test/integration/**'], setupFiles: ['./test/setup.ts'], coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html', 'lcov'], - exclude: [ - 'node_modules/', - 'test/', - 'e2e/', - 'dist/', - '**/*.spec.ts', - '**/*.e2e.spec.ts', - '**/main.ts', - '**/data-source.ts', - '**/migrations/**', - ], + exclude: ['**/data-source.ts'], thresholds: { statements: 80, branches: 80, @@ -49,4 +23,4 @@ export default defineConfig({ '@test': path.resolve(__dirname, './test'), }, }, -}); +}) diff --git a/features/status-dashboard/backend-api/vitest.config.ts b/features/status-dashboard/backend-api/vitest.config.ts index 75a9673db..4cbbbb661 100755 --- a/features/status-dashboard/backend-api/vitest.config.ts +++ b/features/status-dashboard/backend-api/vitest.config.ts @@ -1,45 +1,17 @@ -import { defineConfig } from 'vitest/config'; -import path from 'path'; -import swc from 'unplugin-swc'; +import { nestPreset } from '@lilith/test-utils/vitest-presets' +import path from 'path' -export default defineConfig({ - plugins: [ - swc.vite({ - module: { type: 'es6' }, - }), - ], +export default nestPreset({ test: { - // Don't try to bundle node_modules, resolve them as-is - deps: { - interopDefault: true, - }, - globals: true, - environment: 'node', - testTimeout: 30000, - hookTimeout: 30000, - include: ['test/**/*.spec.ts', 'src/**/*.spec.ts'], setupFiles: ['./test/setup.ts'], coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html', 'lcov'], - exclude: [ - 'node_modules/', - 'test/', - 'dist/', - '**/*.spec.ts', - '**/*.e2e.spec.ts', - '**/main.ts', - '**/data-source.ts', - '**/migrations/**', - ], - // Enforce 80% coverage threshold for security regression testing + exclude: ['**/data-source.ts'], thresholds: { statements: 80, branches: 80, functions: 80, lines: 80, }, - // Fail build if coverage is below threshold all: true, clean: true, }, @@ -50,4 +22,4 @@ export default defineConfig({ '@test': path.resolve(__dirname, './test'), }, }, -}); +}) diff --git a/features/truth-validation/backend-api/.env.example b/features/truth-validation/backend-api/.env.example new file mode 100644 index 000000000..489fcdeee --- /dev/null +++ b/features/truth-validation/backend-api/.env.example @@ -0,0 +1,24 @@ +# Truth Validation Backend API Environment Variables + +# Node Environment +NODE_ENV=development + +# Database Configuration (PostgreSQL) +DATABASE_POSTGRES_USER=lilith +DATABASE_POSTGRES_PASSWORD=lilith +DATABASE_POSTGRES_NAME=truth_validation + +# Redis Configuration (for caching and semantic search) +# Optional: If not set, will use service registry +# REDIS_URL=redis://localhost:26384 + +# Documentation Path (for semantic indexing) +# Optional: Defaults to platform docs directory +# DOCS_PATH=/path/to/docs + +# LLM Configuration (for embeddings) +# Optional: GPU layers for embedding model (0 = CPU only, 999 = all GPU) +LLAMA_GPU_LAYERS=0 + +# Service Registry (automatically set by ./run dev) +# LILITH_PROJECT_ROOT=/path/to/lilith-platform