Skip to content

test: add node:test unit tests for three pure utility modules#548

Open
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:test/add-unit-test-setup
Open

test: add node:test unit tests for three pure utility modules#548
xpoes123 wants to merge 1 commit into
qbreader:mainfrom
xpoes123:test/add-unit-test-setup

Conversation

@xpoes123

@xpoes123 xpoes123 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

The repository had no automated tests, making it difficult to validate utility logic safely across changes. This PR introduces a minimal test harness using Node's built-in node:test module — no new runtime dependencies — and wires it to npm test via "test": "node --test" in package.json.

Background

Several pure utility modules had no coverage. Adding tests for them is straightforward because they carry no import-time side-effects. Modules that transitively import database/databases.js were deliberately excluded because that file calls mongoClient.connect() at load time and would fail without a live database.

Changes

  • package.json — adds "test": "node --test" script.
  • test/merge-two-sorted-arrays.test.js — 6 cases covering server/merge-two-sorted-arrays.js: non-overlapping merge, duplicate-key combineFunction, empty-array edges, and single-element arrays.
  • test/strings.test.js — 10 cases covering client/scripts/utilities/strings.js: escapeHTML (HTML entities, undefined, empty string), kebabCase, removeParentheses, and titleCase.
  • test/get-bonus-part-label.test.js — 6 cases covering client/scripts/utilities/get-bonus-part-label.js: default fallbacks, explicit values, difficulty modifiers, out-of-range index, and custom defaults.

Risk & testing

Zero new dependencies; node:test and node:assert/strict are Node stdlib. The suite runs green with npm test. All three covered modules are pure functions with no DB-connecting import side-effects, establishing a safe pattern for future contributors to extend.

Introduces a zero-dependency test setup using Node's built-in test runner
(`node --test`) with a `test` npm script. Covers three import-safe pure
modules: `server/merge-two-sorted-arrays.js`, `client/scripts/utilities/strings.js`,
and `client/scripts/utilities/get-bonus-part-label.js` (23 assertions total),
deliberately avoiding any module whose transitive imports connect to MongoDB.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@xpoes123 xpoes123 changed the title test: add a minimal node:test unit-test setup test: add node:test unit tests for three pure utility modules Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant