get2knowio/newcleus

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

開放

#3 建立於 2025年10月1日

 (1 則留言) (0 個反應) (0 位負責人)Vue (0 個分叉)auto 404
good first issuequalityservertests

倉庫指標

星標
 (0 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南