Skip to content

test(srcts): Replay the sample logs in a Node test - #155

Merged
schloerke merged 3 commits into
schloerke/typescript-strictfrom
schloerke/typescript-graph-test
Oct 20, 2026
Merged

schloerke merged 3 commits into
schloerke/typescript-strictfrom
schloerke/typescript-graph-test

Conversation

@schloerke

@schloerke schloerke commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Adds the first JS test. srcts/__tests__/graphReplay.test.ts replays each of the 5 logs in inst/log-files/ through GraphAtStep. It checks four step lists (visible, idle, output calc, and user mark steps). At the first, middle, and last visible step, it checks the node, edge, and unique-edge counts plus a fingerprint: a short hash of each element's key, classes, and label, which is what cytoscape draws. It then filters on the first node and checks the filtered steps and the filtered graph. It uses Node's built-in node:test, and the only new dependency is @types/node.

npm test bundles the test with esbuild into node_modules/.cache/ and runs it with plain node, which takes about 0.2 seconds. (node --test fails on current Node, which treats the path as a glob and skips node_modules/.) npm run build now runs it too, so CI's routine job runs it as well. tsconfig.json leaves srcts/__tests__/ out, and tsconfig.test.json adds the tests with Node types, so app code still cannot use Node globals. npm run typecheck runs both. The graph modules read window when they load, so setupWindow.ts sets up a minimal stub first. log/initStep.ts now exports initStep(), so the test numbers steps the same way the app does.

The expected values come from the current code, which matches the main bundle in the browser comparison from rstudio/reactlog#154. To confirm the test catches real breakage, I removed the edge-delete line in Graph.addEntry, and all 5 replay tests failed. I also removed one invalidateStatus.toFinished() call: the counts stayed the same, and the fingerprints failed for all 5 logs. Adding a log file without adding its values also fails. memory-bank/jsBuild.md explains how to update the values.

srcts/__tests__/graphReplay.test.ts runs each log in inst/log-files/
through GraphAtStep and checks the step lists and the node and edge
counts at the first, middle, and last visible step. `npm test` bundles
it with esbuild and runs it with node --test; `npm run build` (and so
CI's routine job) runs it too.
@schloerke
schloerke added this pull request to stack #153 October 20, 2026 18:12
Newer Node (CI uses the current release) treats `node --test` arguments
as globs, and globs skip node_modules/, so it could not find the bundle.
Running the file directly still reports through node:test and exits 1
on failure.
…es out of app code

- Split tsconfig: app code no longer sees @types/node; tsconfig.test.json adds the tests
- Fingerprint each checked step from what cytoscape draws, so wrong statuses fail
- Filter on the first node and check the filtered steps and graph
- Number steps with initStep() instead of a copy
- Ignore non-.js files in inst/log-files/ and find it from the bundle's folder
@schloerke
schloerke merged commit 660e3e9 into main Oct 20, 2026
13 checks passed
@schloerke
schloerke deleted the schloerke/typescript-graph-test branch October 20, 2026 18:32
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