Files
caddy-proxy-manager/tests/vitest.config.ts
fuomag9 fc680d4171 fix: use bun:sqlite in production, better-sqlite3 as test-only devDep
Production (Docker): src/lib/db.ts now uses bun:sqlite + drizzle-orm/bun-sqlite.
No native addon compilation needed — bun:sqlite is a Bun built-in. The Dockerfile
drops all native build tools (python3, make, g++) and uses --ignore-scripts.

Tests (Vitest/Node.js): bun:sqlite is unavailable under Node.js, so:
- tests/helpers/db.ts keeps better-sqlite3 + drizzle-orm/better-sqlite3 for
  integration tests that need a real in-memory SQLite
- vitest.config.ts aliases bun:sqlite → a thin better-sqlite3 shim and
  drizzle-orm/bun-sqlite → drizzle-orm/better-sqlite3 for unit tests that
  transitively import src/lib/db.ts without executing any queries
- better-sqlite3 stays as a devDependency (test-only, not built in Docker)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 11:53:33 +01:00

40 lines
1.5 KiB
TypeScript

import { defineConfig } from 'vitest/config';
import tsconfigPaths from 'vite-tsconfig-paths';
import { resolve } from 'node:path';
const root = resolve(__dirname, '..');
export default defineConfig({
plugins: [tsconfigPaths({ root })],
resolve: {
alias: {
// bun:sqlite is a Bun built-in unavailable in Node.js/Vitest. Redirect both
// the protocol import and the drizzle bun-sqlite adapter to their better-sqlite3
// equivalents so tests that transitively import src/lib/db.ts don't crash.
// Tests that need a real database use tests/helpers/db.ts (better-sqlite3 directly).
'bun:sqlite': resolve(__dirname, 'helpers/bun-sqlite-compat.ts'),
'drizzle-orm/bun-sqlite/migrator': 'drizzle-orm/better-sqlite3/migrator',
'drizzle-orm/bun-sqlite': 'drizzle-orm/better-sqlite3',
},
},
test: {
environment: 'node',
setupFiles: [resolve(__dirname, 'setup.vitest.ts')],
env: {
DATABASE_URL: ':memory:',
SESSION_SECRET: 'test-session-secret-for-vitest-unit-tests-12345',
NODE_ENV: 'test',
},
include: [
resolve(__dirname, 'unit/**/*.test.ts'),
resolve(__dirname, 'integration/**/*.test.ts'),
],
// Suppress console output from production code during tests (e.g. expected
// warn/error calls when intentionally feeding bad input to parsers).
// Tests that need to assert on console calls can still use vi.spyOn(console, ...).
onConsoleLog() {
return false;
},
},
});