chore(test): 🔧 Update Vitest/Jest configs across 15+ modules; standardize coverage rules, globals, plugins, and .env.example variables

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Lilith 2026-02-06 01:33:12 -08:00
parent c5e292db73
commit 8cd25f7b91
16 changed files with 222 additions and 160 deletions

View file

@ -0,0 +1,3 @@
import { jsdomPreset } from '@lilith/test-utils/vitest-presets'
export default jsdomPreset()

View file

@ -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)

View file

@ -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') },
],
},
})

View file

@ -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, './'),
},
},
})

View file

@ -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/'),
},
},
})

View file

@ -1,30 +0,0 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/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: {
'^@/(.*)$': '<rootDir>/src/$1',
},
testTimeout: 10000,
maxWorkers: '50%',
}

View file

@ -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'),
},
},
})

View file

@ -0,0 +1,3 @@
import { nestPreset } from '@lilith/test-utils/vitest-presets'
export default nestPreset()

View file

@ -0,0 +1,3 @@
import { nestPreset } from '@lilith/test-utils/vitest-presets'
export default nestPreset()

View file

@ -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/'),
},
},
})

View file

@ -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'),
},
},
});
})

View file

@ -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'),
},
},
})

View file

@ -0,0 +1,3 @@
import { nestPreset } from '@lilith/test-utils/vitest-presets'
export default nestPreset()

View file

@ -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'),
},
},
});
})

View file

@ -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'),
},
},
});
})

View file

@ -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