test: add node:test unit tests for three pure utility modules#548
Open
xpoes123 wants to merge 1 commit into
Open
test: add node:test unit tests for three pure utility modules#548xpoes123 wants to merge 1 commit into
xpoes123 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:testmodule — no new runtime dependencies — and wires it tonpm testvia"test": "node --test"inpackage.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.jswere deliberately excluded because that file callsmongoClient.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 coveringserver/merge-two-sorted-arrays.js: non-overlapping merge, duplicate-keycombineFunction, empty-array edges, and single-element arrays.test/strings.test.js— 10 cases coveringclient/scripts/utilities/strings.js:escapeHTML(HTML entities,undefined, empty string),kebabCase,removeParentheses, andtitleCase.test/get-bonus-part-label.test.js— 6 cases coveringclient/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:testandnode:assert/strictare Node stdlib. The suite runs green withnpm test. All three covered modules are pure functions with no DB-connecting import side-effects, establishing a safe pattern for future contributors to extend.