Skip to content

Add automated test suite (node:test + jsdom)#241

Merged
robinmoisson merged 15 commits into
mainfrom
feature-add-tests
Jun 8, 2026
Merged

Add automated test suite (node:test + jsdom)#241
robinmoisson merged 15 commits into
mainfrom
feature-add-tests

Conversation

@robinmoisson

@robinmoisson robinmoisson commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add 50 automated tests using the built-in node:test runner — zero new runtime deps; jsdom is added as a devDependency for browser-runtime tests under a simulated DOM.
  • Pin all backward-compatibility boundaries: the 3-round PBKDF2 chain iteration counts, the encode/decode wire format, decode()'s retry chain for old hashes, localStorage key names, URL-fragment autodecrypt format.
  • Add a GitHub Actions workflow running tests on Node 20 and 22.

No changes to lib/ or cli/ source — this PR only adds tests, CI, and .gitignore entries.

What's tested

  • lib/cryptoEngine.js — primitives + each hash round pinned against golden fixtures (14 tests)
  • lib/codec.js — happy-path encode/decode, wire format, tamper rejection (6 tests)
  • lib/codec.js retry chain — all 3 branches of the backward-compat path that lets old remember-me localStorage tokens still decrypt (4 tests)
  • lib/formater.js — token substitution (7 tests)
  • cli/helpers.js pure functions — the hand-rolled CommonJS→IIFE bundler, salt validation (7 tests)
  • Full CLI flow via subprocess — encrypt → decrypt round-trip, invalid salt rejection (3 tests)
  • lib/staticryptJs.js browser runtime under jsdom — decrypt path, remember-me, URL autodecrypt, logout (9 tests)

Golden fixtures live in test/fixtures/encrypted-blobs/basic.json. Regenerate with node test/fixtures/generate.js (not run in CI).

Test plan

  • npm test passes locally (50 tests, ~2.5s)
  • GitHub Actions CI passes on both Node 20 and 22
  • bash scripts/build.sh still produces a working encrypted/test.html
  • Skim test/codec-compat.test.js — these are the most important (any failure here means a real regression in the backward-compat retry chain)

…xtures/legacy-html

- Remove `test/` from .gitignore so the directory can hold real test files
- Move legacy manual fixtures into test/fixtures/legacy-html/
- Add `test` script using `node --test --test-reporter=spec`
- Add jsdom ^24.0.0 as devDependency
Was carried into the repo from the pre-existing untracked test1/ directory
during Task 1's fixture move. Not a meaningful fixture.
Without an explicit glob, node --test recursively picks up everything
under test/, including test/fixtures/generate.js and test/setup/jsdomEnv.js.
The former actually re-ran on every `npm test`, overwriting the golden
fixture with a new random IV. The latter was harmless noise but still
"ran" as a 0-test file.
@robinmoisson robinmoisson merged commit 22b0c00 into main Jun 8, 2026
2 checks passed
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