Skip to content

feat: add unit test suite#786

Open
podrivo wants to merge 25 commits into
gamedig:masterfrom
podrivo:feat-add-tests
Open

feat: add unit test suite#786
podrivo wants to merge 25 commits into
gamedig:masterfrom
podrivo:feat-add-tests

Conversation

@podrivo

@podrivo podrivo commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Refs #591

Problem

The project has no automated test suite. The shared byte parser (lib/reader.js) and other core utilities are relied on by nearly all ~80 protocols, yet there's no safety net to catch regressions, no npm test script, and no CI job to run tests. See #591.

Fix

Introduce a lightweight, zero-dependency unit test suite covering core parsing and utility logic, an npm test script, and a CI job to run it. No production code is changed — this PR only adds tests and wiring.

Approach:

  • Runner: Node's built-in node:test + node:assert/strict. No new dependencies, no build step, works with the existing ESM setup.
  • Scope: fast, offline unit tests only — no live servers or network.
  • Layout mirrors the source tree so tests are easy to find and scale:
tests/
  lib/
    reader.test.js
    hexutil.test.js
    results.test.js
    game-resolver.test.js
    promises.test.js
  protocols/
    core-utils.test.js   # protocols/core.js helpers
    quake3.test.js
  • node --test auto-discovers **/*.test.js recursively, so the script and CI need no per-file wiring.

What's covered:

  • lib/reader.js — the shared byte parser used by nearly every protocol: fixed-length & delimited strings, custom encodings (incl. the latin1→win1252 alias), pascalString, signed/unsigned ints (LE/BE, incl. 64-bit Long), floats, varints, part, and offset navigation (skip/setOffset/rest/done).
  • lib/HexUtil.js — debugDump length reporting, hex rendering, control-byte masking.
  • lib/Results.js — Player/Players/Results construction and defaults.
  • lib/game-resolver.js — lookup(): protocol-* types, known ids, unknown ids, and checkOldIDs deprecated-id resolution.
  • lib/Promises.js — createTimeout fires after the timeout and is silenced by cancel() (the primitive behind every socket/attempt timeout — see bug: Timeouts not triggering for TCP queries #611).
  • protocols/core.js — pure helpers trueTest, translate, assertValidPort.
  • protocols/quake3.js — stripColors (single-char ^1 and extended ^XRRGGBB color codes, plus the disabled passthrough).

CI: adds a test job to .github/workflows/node.yml running npm test on Node 18.x / 20.x / 22.x. (The built-in runner's auto-discovery is reliable on 18+; Node 16 stays covered by the existing build job.)

Examples

npm test            # node --test

Compatibility

  • No production code is changed — this PR only adds tests and CI wiring, so it's fully backwards-compatible.
  • Zero new dependencies and no build step (uses the built-in node:test runner with the existing ESM setup).
  • This establishes the harness + a safety net for the shared parsing primitive (which all ~80 protocols rely on) + one example protocol test. It is the first batch, not full coverage.

Follow-ups (out of scope for this PR):

Testing

  • npm test7 test files, 16 suites, 55 tests, all passing.
  • npm run lint:check currently reports pre-existing failures on master in untouched files (the .eslintrc.json ecmaVersion: 2021 predates ES2022 syntax already in the code). This PR introduces zero new lint errors; fixing the pre-existing ones is a separate change.

@podrivo podrivo mentioned this pull request Jun 20, 2026
podrivo added 21 commits June 21, 2026 18:11
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