get2knowio/newcleus

[Server][Tests] Add first unit tests for config normalization via context

Offen

#3 geöffnet am 01.10.2025

 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Vue (0 Forks)auto 404
good first issuequalityservertests

Repository-Metriken

Stars
 (0 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Summary Introduce the first server-side unit tests to validate configuration loading and normalization using the new createWikiContext(), without relying on global state.

Background

  • Config and env flag normalization is currently scattered and relies on implicit truthiness checks.
  • Establishing tests here sets the pattern for future modules and proves the value of the context abstraction.

Scope

  • Add Vitest to the server package with a minimal config.
  • Write unit tests around server/core/config.mjs to verify env variable overrides and normalization of booleans/SSL flags.
  • Ensure tests run independently of the running server and do not mutate globals.

Tasks

  • Add devDependencies to server/package.json: vitest, @vitest/coverage-v8 (optional), c8 (optional)
  • Create server/vitest.config.mjs with test.environment='node'
  • Add npm script: "test": "vitest"
  • Implement a small helper to coerce env flags (e.g., toBoolean/toArray) and test them
  • Write tests covering: - HTTP/HTTPS toggle normalization (server/web.mjs references) - DB SSL options type coercion (server/core/db.mjs references) - Env override precedence (config.yml vs process.env)
  • Document how to run tests in server/README.md

Acceptance Criteria

  • pnpm --filter server test passes locally
  • Tests do not require spinning up the app or setting global.WIKI
  • Clear examples of env normalization are captured in tests

References

Contributor Guide