From 6d8ee7dda81be23a87e64f86a4d9dafacc95af80 Mon Sep 17 00:00:00 2001 From: Josue Zamudio Date: Sat, 21 Mar 2026 09:03:58 +0000 Subject: [PATCH] Update documentation for testing infrastructure - Add test commands to CLAUDE.md and README.md - Update file structure to include game-logic.js and __tests__/ - Document Jest test suite with 57 tests --- CLAUDE.md | 12 ++++++++++-- README.md | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 711668a..bb999d6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -17,6 +17,12 @@ cd server && npm start # or cd server && node index.js +# Run tests +cd server && npm test + +# Run tests with coverage +cd server && npm run test:coverage + # Server runs on http://localhost:3000 (or PORT env variable) ``` @@ -24,11 +30,13 @@ cd server && node index.js ### Server-Client Model -- **Server** (`server/index.js`): Express + Socket.io handles all game logic authoritatively +- **Server** (`server/`): Express + Socket.io handles all game logic authoritatively + - `index.js`: Main server with socket.io event handlers + - `game-logic.js`: Pure game logic functions (testable, no socket dependencies) + - `__tests__/`: Jest test suite with 57 tests - Manages single global lobby with `lobby.players` Map - Game tick runs at 50ms intervals via `gameTick()` - Broadcasts state updates to all connected clients via `broadcastState()` - - Tetromino definitions and board constants are duplicated on server - **Client** (`public/js/`): Vanilla JavaScript with module pattern - `network.js`: Socket.io client wrapper, manages player/game state caching diff --git a/README.md b/README.md index fd26060..6abc9ad 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,23 @@ The last player standing wins! 5. Click "READY" when all players are ready +## Testing + +Run the test suite: +```bash +cd server && npm test +``` + +Run with coverage: +```bash +cd server && npm run test:coverage +``` + +The test suite includes 57 tests covering: +- Unit tests for pure game logic functions +- Integration tests for garbage system +- Socket.io integration tests for multiplayer flow + ## Controls - **Arrow Left/Right**: Move piece @@ -58,7 +75,12 @@ The last player standing wins! ``` tetris-battle-royale/ ├── server/ -│ ├── index.js # Node.js + Socket.io server +│ ├── index.js # Node.js + Socket.io server +│ ├── game-logic.js # Pure game logic functions (testable) +│ ├── __tests__/ # Jest test suite +│ │ ├── game-logic.test.js +│ │ ├── garbage-system.test.js +│ │ └── socket-integration.test.js │ └── package.json ├── public/ │ ├── index.html # Main HTML