The DBPOC test suite runs on bun test (Bun’s built-in runner — no Jest, no Vitest, no ts-node). 27 *.test.ts files, 6,538 lines, mixed unit + integration. No bunfig.toml; no global setup/teardown. package.json: "test": "bun test".
Layout
tests/api/*.test.ts(12 files) — REST integration tests, hit a live API server. See API Tests.tests/enrichment/*.test.ts(4 files) — extraction logic, mostly inline HTML fixtures. See Enrichment Tests.tests/fetchers/*.test.ts(2 files) — bulk fetchers with mocked axios. See Fetcher Tests.tests/domainDiscovery.test.ts— registry latency + hosting-domain rejection. See Domain Discovery Tests.tests/speed.test.ts— registry lookup latency budget. See Speed Tests.src/**/*.test.ts(6 files, colocated) — unit tests forcompliance,validationEngine,enrichmentEngine.v7,lib/validation,fetchers/bolagsverket/mapper,integration(the queue/schema smoke).autoresearch/regression.test.ts— name-validation regression guards for the Autoresearch Loop.
What needs to be running
Warning
Tests fall into two camps and the runner does not separate them. Running
bun teston a fresh checkout fails most API tests because they assume a server.
| Suite | Requires | Notes |
|---|---|---|
tests/api/* | API at localhost:${API_PORT ?? 3000} + Postgres at localhost:5433 (enrichnodedb) | Each suite registers a fresh user with a unique *-test@example.com address. |
tests/api/kundkort-enrich.test.ts | Same as above + a real org_nr 5565672655 resolvable through the enrichment pipeline | Enrichment hits live external services unless mocked. |
tests/enrichment/board-members-integration.test.ts | Calls enrichV7() end-to-end with bypass_cache: true | 30s timeout per test, network-dependent. |
tests/enrichment/crawlee-quality.test.ts, firecrawl.test.ts, processors.test.ts | None — inline fixtures + injected mock client | Safe in CI. |
tests/fetchers/* | Mocked axios via mock.module() | Safe in CI. |
tests/domainDiscovery.test.ts, tests/speed.test.ts | Live database with seeded registry data; findCompanyDomain calls Serper if no cache | Will hit network unless seeded. |
src/compliance.test.ts, src/integration.test.ts, src/lib/validation.test.ts, src/enrichmentEngine.v7.test.ts, src/fetchers/bolagsverket/mapper.test.ts | Pure unit, mock pg pool | Safe in CI. |
src/validationEngine.test.ts | Imports validationEngine.ts which calls mock layers | Safe in CI. |
autoresearch/regression.test.ts | Pure | Safe in CI. |
Environment variables
API tests read:
API_PORT(default 3000)PGHOST(defaultlocalhost),PGPORT(default 5433),PGUSER(defaultuser),PGPASSWORD(defaultpassword),PGDATABASE(defaultenrichnodedb)JWT_SECRET— security tests assume a default dev value if unsetKEYCLOAK_DEV_MODE— kundkort-enrich asserts 200 instead of 401 when'true'
Scraper bypasses (from Crawlee Scraper):
NODE_ENV=testorSCRAPE_LIMIT_BYPASS=trueskips the 3x/year per-domain limit.
Firecrawl tests set FIRECRAWL_API_KEY=fc-test-key to avoid the missing-key throw, then inject a mock client via _setClientForTest().
Persistence in unit tests
pg Pool is used directly (legacy — pre-Bun migration, see Stack). Each API suite opens its own pool with max: 5 and closes in afterAll. Cleanup is keyed by source = '<suite>_test' or email LIKE '%@authtest.com' patterns — collisions across parallel runs are possible.
Running subsets
bun test # all
bun test tests/api/auth.test.ts # one file
bun test tests/enrichment/ # one folder
bun test --test-name-pattern "should reject" # by describe/it textKnown gaps
See Test Coverage Gaps — large parts of src/queues/, src/workers/, src/import/, and most src/lib/ files have no test.
See also
API Tests, Enrichment Tests, Fetcher Tests, Test Coverage Gaps, Local Development.