chart/bin/e2e
Chris Amow 501afb7792 Snap to the nearest extreme on screen, and add an e2e suite
Snapping took the bar sharing the cursor's time and then its nearer extreme,
which ignored how far away that extreme was. Pointing below a candle snapped to
that candle's low however distant, while the extreme genuinely under the cursor
was never considered. Zoomed out to some 360 bars at three pixels apart, that
made hitting the bar you meant a matter of several tries. snapPoint now scans
six bars either side and takes the extreme nearest in pixels.

Proven by probe: with the cursor sitting exactly on one bar's low but nudged two
pixels so coordinateToTime resolves to its neighbour, the snap takes the extreme
under the cursor rather than the neighbour's.

A report of the snap dot appearing "way above the bar" turned out to be the dot
landing correctly on the low while the cursor was 151 points below it: the right
price scale keeps a bottom margin of 0.1 and the volume overlay is drawn in it,
so the lower fifth of the pane sits below every candle.

bin/e2e runs tests/e2e against the dev stack inside the playwright service —
Node's own test runner, no dependency added here, since Playwright is global in
that container. Eleven cases, each one a bug that shipped: the viewport parked
ten hours in the past, hourly candles drawn as slivers, stale bar events
throwing, comments drifting across a timeframe switch, and three ways a
trendline anchor could disagree with its preview. Not one was reachable from
pytest. Tests delete any drawing they create, because the dev store is shared
with whoever is looking at the app.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 20:16:09 -05:00

40 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run the end-to-end tests against the local dev stack.
#
# bin/e2e # every test
# bin/e2e trendline # only files matching a name
#
# They run inside the `playwright` compose service, which already has
# Playwright and a browser. Nothing is installed into this repo — NODE_PATH
# points Node at the container's global modules, and tests/e2e resolves it
# through createRequire because ESM ignores NODE_PATH.
#
# These drive the real app against the real feed. They create drawings and
# delete them again afterwards; the dev stack shares one drawing store with
# whoever else is looking at it.
set -uo pipefail
FILTER=${1:-}
COMPOSE=${COMPOSE:-docker compose}
if ! $COMPOSE ps --status running --services 2>/dev/null | grep -qx playwright; then
echo "the playwright service is not running — start it with: $COMPOSE up -d" >&2
exit 1
fi
if [ -n "$FILTER" ]; then
FILES=$(ls tests/e2e/*"$FILTER"*.test.mjs 2>/dev/null)
if [ -z "$FILES" ]; then
echo "no e2e test files match '$FILTER'" >&2
exit 1
fi
else
FILES=$(ls tests/e2e/*.test.mjs)
fi
# The app is reachable as http://api:8000 from inside the compose network.
# shellcheck disable=SC2086
$COMPOSE exec -T \
-e NODE_PATH=/usr/lib/node_modules \
-e E2E_URL="${E2E_URL:-http://api:8000/}" \
playwright node --test --test-concurrency=1 $(echo $FILES | sed 's#tests/e2e/#/repo/tests/e2e/#g')