get2knowio/newcleus

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

Aperta

#3 aperta il 1 ott 2025

 (1 commento) (0 reazioni) (0 assegnatari)Vue (0 fork)auto 404
good first issuequalityservertests

Metriche repository

Star
 (0 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor