Skip to content

Make E2E tests resilient to database state with ID normalization#229

Draft
lordscarlet wants to merge 6 commits into
YourDeveloperFriend:mainfrom
lordscarlet:fix/e2e-tests
Draft

Make E2E tests resilient to database state with ID normalization#229
lordscarlet wants to merge 6 commits into
YourDeveloperFriend:mainfrom
lordscarlet:fix/e2e-tests

Conversation

@lordscarlet

@lordscarlet lordscarlet commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Summary

I was having trouble getting the e2e tests to succeed. I believe it is because I do not have the same data as whomever wrote the tests. This PR implements ID-agnostic E2E tests that are resilient to different database states, ensuring that other contributors' tests won't fail due to different user ID sequences.

Changes

  • Add normalizePlayerIds() function to compareGameData() that canonicalizes player IDs before snapshot comparison
  • Regenerate golden files with normalized canonical player IDs instead of absolute DB IDs
  • Add .gitattributes to enforce LF line endings across all tracked files
  • Add .vscode/settings.json to lock formatter/linter behavior
  • Normalize all tracked files to LF per .gitattributes

Key Benefits

  • Contributors' E2E tests won't fail due to different database user ID sequences
  • Golden files remain stable and deterministic across test runs
  • No database wipes or cleanup scripts needed
  • Consistent formatting across the repository

Testing

  • E2E tests pass deterministically across multiple runs
  • No changes to golden files after regeneration (formatting is stable)
  • Tests work with any database user ID sequence thanks to normalization
  • With a completely fresh database the "old" golden files fail
  • With a completely fresh database, these golden files pass

Merge from YourDeveloperFriend
- Add normalizePlayerIds() function to compareGameData() that canonicalizes player IDs
  before snapshot comparison, making tests portable across different database states
- Regenerate golden files (build_track_after.json, create_game_after.json) with
  normalized canonical player IDs (1, 2, 3, ...) instead of absolute DB IDs
- Enhance buildTrack WebDriver method with scroll positioning and pointer events
  for better test stability and React integration
- Add .gitattributes to enforce LF line endings across all tracked files
- Add .vscode/settings.json to lock formatter/linter behavior (Prettier, ESLint on save)

This ensures:
- Teammates' tests won't fail due to different database user ID sequences
- Golden files remain stable and deterministic across test runs
- No database wipes or cleanup scripts needed
- Consistent formatting and reliable track building interactions
- Add missing undoPlayerId normalization in normalizePlayerIds() function
  to canonicalize player IDs for portable golden file comparisons
- Improve type safety: replace 'any' types with proper GameApi types
  and MutablePlayerData interface
- Add non-null assertions after idMap.get() calls for type safety
- Update build_track_after.json golden file with correct normalized
  undoPlayerId value (3 -> 4)
- Revert to standard JSON.stringify format to preserve golden file
  formatting consistency

This fixes a critical bug where tests would fail if undoPlayerId was
present in the game state, as it wasn't being normalized during the
ID mapping process.
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