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 for compliance, 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 test on a fresh checkout fails most API tests because they assume a server.

SuiteRequiresNotes
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.tsSame as above + a real org_nr 5565672655 resolvable through the enrichment pipelineEnrichment hits live external services unless mocked.
tests/enrichment/board-members-integration.test.tsCalls enrichV7() end-to-end with bypass_cache: true30s timeout per test, network-dependent.
tests/enrichment/crawlee-quality.test.ts, firecrawl.test.ts, processors.test.tsNone — inline fixtures + injected mock clientSafe in CI.
tests/fetchers/*Mocked axios via mock.module()Safe in CI.
tests/domainDiscovery.test.ts, tests/speed.test.tsLive database with seeded registry data; findCompanyDomain calls Serper if no cacheWill 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.tsPure unit, mock pg poolSafe in CI.
src/validationEngine.test.tsImports validationEngine.ts which calls mock layersSafe in CI.
autoresearch/regression.test.tsPureSafe in CI.

Environment variables

API tests read:

  • API_PORT (default 3000)
  • PGHOST (default localhost), PGPORT (default 5433), PGUSER (default user), PGPASSWORD (default password), PGDATABASE (default enrichnodedb)
  • JWT_SECRET — security tests assume a default dev value if unset
  • KEYCLOAK_DEV_MODE — kundkort-enrich asserts 200 instead of 401 when 'true'

Scraper bypasses (from Crawlee Scraper):

  • NODE_ENV=test or SCRAPE_LIMIT_BYPASS=true skips 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 text

Known 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.

See also