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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user