refactor(test): separate unit and integration tests

Rename 19 integration test files from *.test.ts to *.integration.test.ts.
Configure vitest projects to run them independently with separate coverage
thresholds. CI now reports unit and integration coverage as separate flags
to Codecov.

Unit tests: pure function calls, mocked dependencies, no DB
Integration tests: createTestApp() with in-memory DB + HTTP requests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
saltbo
2026-04-13 21:01:37 -04:00
co-authored by Claude Opus 4.6
parent 4c7dddf3eb
commit df32f35ba9
21 changed files with 67 additions and 30 deletions
+9 -1
View File
@@ -24,11 +24,19 @@ jobs:
run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm test -- --coverage
- run: npx vitest run --project unit --coverage
- uses: codecov/codecov-action@v5
if: always()
with:
files: coverage/coverage-final.json
flags: unit
fail_ci_if_error: false
- run: npx vitest run --project integration --coverage
- uses: codecov/codecov-action@v5
if: always()
with:
files: coverage/coverage-final.json
flags: integration
fail_ci_if_error: false
- run: mkdir -p dist
- run: npm run test:cf
+58 -29
View File
@@ -1,38 +1,67 @@
import path from 'node:path'
import { defineConfig } from 'vitest/config'
const aliases = {
'@': path.resolve(__dirname, './src'),
'@shared': path.resolve(__dirname, './shared'),
'@server': path.resolve(__dirname, './server'),
}
const coverageConfig = {
provider: 'v8' as const,
include: ['server/**/*.ts', 'shared/**/*.ts', 'src/lib/**/*.ts', 'src/i18n/**/*.ts'],
exclude: [
'server/entry-*.ts',
'server/**/*.test.ts',
'server/**/*.integration.test.ts',
'server/**/*.cf-test.ts',
'server/test/**',
'server/platform/**',
'server/db/**',
'shared/**/*.test.ts',
'src/**/*.test.ts',
'src/i18n/index.ts',
],
reporter: ['text', 'json'] as const,
}
export default defineConfig({
test: {
globals: true,
include: ['server/**/*.test.ts', 'shared/**/*.test.ts', 'src/**/*.test.ts'],
coverage: {
provider: 'v8',
include: ['server/**/*.ts', 'shared/**/*.ts', 'src/lib/**/*.ts', 'src/i18n/**/*.ts'],
exclude: [
'server/entry-*.ts',
'server/**/*.test.ts',
'server/**/*.cf-test.ts',
'server/test/**',
'server/platform/**',
'server/db/**',
'shared/**/*.test.ts',
'src/**/*.test.ts',
'src/i18n/index.ts',
],
reporter: ['text', 'json'],
thresholds: {
statements: 90,
branches: 80,
functions: 90,
lines: 90,
projects: [
{
resolve: { alias: aliases },
test: {
name: 'unit',
include: ['server/**/*.test.ts', 'shared/**/*.test.ts', 'src/**/*.test.ts'],
exclude: ['**/*.integration.test.ts', '**/*.cf-test.ts'],
coverage: {
...coverageConfig,
thresholds: {
statements: 50,
branches: 40,
functions: 50,
lines: 50,
},
},
},
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@shared': path.resolve(__dirname, './shared'),
'@server': path.resolve(__dirname, './server'),
},
{
resolve: { alias: aliases },
test: {
name: 'integration',
include: ['server/**/*.integration.test.ts'],
coverage: {
...coverageConfig,
thresholds: {
statements: 90,
branches: 80,
functions: 90,
lines: 90,
},
},
},
},
],
},
})