- Add vitest as dev dep (pnpm add -D vitest), create vitest.config.ts with globals:true and setupFiles - Migrate digest-template, normalize-relay-url, reschedule-on-frequency-change, and event-arrival-race from raw JS + hand-rolled asserts to vitest describe/it/expect, as .test.ts (port all assertions without weakening) - Create test/setup.ts with env vars needed by env.ts/mailer.ts - DELETE test/web-ui.test.js: dead test for removed web UI (PR #1) - package.json: add test:unit script (vitest run), keep test = bash E2E - script/checks: add pnpm test:unit after build - README: document pnpm test:unit / pnpm test
23 lines
No EOL
975 B
TypeScript
23 lines
No EOL
975 B
TypeScript
// Vitest setup: set required env vars before test modules are loaded.
|
|
// env.ts checks these at module load time; they must be present when
|
|
// actions.ts / mailer.ts / etc. are imported.
|
|
import { mkdirSync } from 'fs'
|
|
|
|
const dataDir = 'test-data-unit'
|
|
mkdirSync(dataDir, { recursive: true })
|
|
|
|
process.env.MAILSHIP_URL = 'http://localhost:3000'
|
|
process.env.MAILSHIP_NAME = 'Test Mailship'
|
|
process.env.MAILSHIP_SECRET = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
process.env.SMTP_HOST = 'localhost'
|
|
process.env.SMTP_PORT = '587'
|
|
process.env.SMTP_USER = 'test@test.com'
|
|
process.env.SMTP_PASSWORD = 'test'
|
|
process.env.SMTP_FROM = 'test@test.com'
|
|
process.env.DEFAULT_RELAYS = 'wss://relay.damus.io'
|
|
process.env.INDEXER_RELAYS = 'wss://purplepag.es'
|
|
process.env.SEARCH_RELAYS = 'wss://relay.nostr.band'
|
|
process.env.PORT = '3000'
|
|
process.env.CORS_ORIGIN = 'http://localhost:5173'
|
|
process.env.BASE_URL = 'http://localhost:3000'
|
|
process.env.DATA_DIR = dataDir |