@gamerstake/game-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +22 -0
- package/.testing-guide-summary.md +261 -0
- package/DEVELOPER_GUIDE.md +996 -0
- package/MANUAL_TESTING.md +369 -0
- package/QUICK_START.md +368 -0
- package/README.md +379 -0
- package/TESTING_OVERVIEW.md +378 -0
- package/dist/index.d.ts +1266 -0
- package/dist/index.js +1632 -0
- package/dist/index.js.map +1 -0
- package/examples/simple-game/README.md +176 -0
- package/examples/simple-game/client.ts +201 -0
- package/examples/simple-game/package.json +14 -0
- package/examples/simple-game/server.ts +233 -0
- package/jest.config.ts +39 -0
- package/package.json +54 -0
- package/src/core/GameLoop.ts +214 -0
- package/src/core/GameRules.ts +103 -0
- package/src/core/GameServer.ts +200 -0
- package/src/core/Room.ts +368 -0
- package/src/entities/Entity.ts +118 -0
- package/src/entities/Registry.ts +161 -0
- package/src/index.ts +51 -0
- package/src/input/Command.ts +41 -0
- package/src/input/InputQueue.ts +130 -0
- package/src/network/Network.ts +112 -0
- package/src/network/Snapshot.ts +59 -0
- package/src/physics/AABB.ts +104 -0
- package/src/physics/Movement.ts +124 -0
- package/src/spatial/Grid.ts +202 -0
- package/src/types/index.ts +117 -0
- package/src/types/protocol.ts +161 -0
- package/src/utils/Logger.ts +112 -0
- package/src/utils/RingBuffer.ts +116 -0
- package/tests/AABB.test.ts +38 -0
- package/tests/Entity.test.ts +35 -0
- package/tests/GameLoop.test.ts +58 -0
- package/tests/GameServer.test.ts +64 -0
- package/tests/Grid.test.ts +28 -0
- package/tests/InputQueue.test.ts +42 -0
- package/tests/Movement.test.ts +37 -0
- package/tests/Network.test.ts +39 -0
- package/tests/Registry.test.ts +36 -0
- package/tests/RingBuffer.test.ts +38 -0
- package/tests/Room.test.ts +80 -0
- package/tests/Snapshot.test.ts +19 -0
- package/tsconfig.json +28 -0
- package/tsup.config.ts +14 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# Testing Overview - @gamerstake/game-core
|
|
2
|
+
|
|
3
|
+
**Complete guide to testing and learning the game-core package**
|
|
4
|
+
|
|
5
|
+
## Documentation Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
game-core/
|
|
9
|
+
README.md ..................... Main documentation & API reference
|
|
10
|
+
QUICK_START.md ................ Get running in 5 minutes
|
|
11
|
+
DEVELOPER_GUIDE.md ............ Complete tutorial with examples
|
|
12
|
+
MANUAL_TESTING.md ............. How to manually test the engine
|
|
13
|
+
PUBLISHING.md ................. How to publish & distribute
|
|
14
|
+
TESTING_OVERVIEW.md ........... This file!
|
|
15
|
+
|
|
16
|
+
examples/
|
|
17
|
+
simple-game/
|
|
18
|
+
server.ts ................ Test server with game rules
|
|
19
|
+
client.ts ................ Automated test client
|
|
20
|
+
README.md ................ Manual testing instructions
|
|
21
|
+
|
|
22
|
+
tests/
|
|
23
|
+
Entity.test.ts ............... Unit tests
|
|
24
|
+
GameLoop.test.ts
|
|
25
|
+
Room.test.ts
|
|
26
|
+
... (12 test files total)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Choose Your Path
|
|
30
|
+
|
|
31
|
+
### I want to... → You should...
|
|
32
|
+
|
|
33
|
+
| Goal | Resource | Time |
|
|
34
|
+
|------|----------|------|
|
|
35
|
+
| **Understand what this package does** | Read [README.md](./README.md) | 5 min |
|
|
36
|
+
| **Get a game running quickly** | Follow [QUICK_START.md](./QUICK_START.md) | 5 min |
|
|
37
|
+
| **Learn to build games** | Read [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md) | 30 min |
|
|
38
|
+
| **Manually test the engine** | Follow [MANUAL_TESTING.md](./MANUAL_TESTING.md) | 10 min |
|
|
39
|
+
| **Run automated tests** | Run `pnpm test` | 2 min |
|
|
40
|
+
| **See working code** | Check [examples/simple-game/](./examples/simple-game/) | 10 min |
|
|
41
|
+
| **Publish the package** | Read [PUBLISHING.md](./PUBLISHING.md) | 10 min |
|
|
42
|
+
| **Understand the architecture** | Read RFC docs | 20 min |
|
|
43
|
+
|
|
44
|
+
## Testing Methods
|
|
45
|
+
|
|
46
|
+
### 1. Automated Testing (Unit Tests)
|
|
47
|
+
|
|
48
|
+
**What:** Jest-based unit tests for all components
|
|
49
|
+
**When:** During development, before commits, in CI/CD
|
|
50
|
+
**How:**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Run all tests
|
|
54
|
+
pnpm test
|
|
55
|
+
|
|
56
|
+
# Run with coverage (requires 80% coverage)
|
|
57
|
+
pnpm test:coverage
|
|
58
|
+
|
|
59
|
+
# Watch mode (auto-rerun on changes)
|
|
60
|
+
pnpm test:watch
|
|
61
|
+
|
|
62
|
+
# Type checking
|
|
63
|
+
pnpm typecheck
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Coverage:**
|
|
67
|
+
- 12 test files covering all major components
|
|
68
|
+
- Entity system, game loop, networking, spatial grid
|
|
69
|
+
- 80% coverage requirement enforced
|
|
70
|
+
|
|
71
|
+
**Example test:**
|
|
72
|
+
```typescript
|
|
73
|
+
it('updates position based on velocity and delta time', () => {
|
|
74
|
+
const entity = new Entity('e1', 0, 0);
|
|
75
|
+
entity.setVelocity(100, -50);
|
|
76
|
+
entity.updatePosition(1000); // 1 second
|
|
77
|
+
|
|
78
|
+
expect(entity.x).toBe(100);
|
|
79
|
+
expect(entity.y).toBe(-50);
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**See:** `tests/*.test.ts` for examples
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### 2. Manual Testing (Live Server)
|
|
88
|
+
|
|
89
|
+
**What:** Run a real multiplayer game server with test clients
|
|
90
|
+
**When:** Before releases, when testing multiplayer features, debugging
|
|
91
|
+
**How:**
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Step 1: Build
|
|
95
|
+
pnpm build
|
|
96
|
+
|
|
97
|
+
# Step 2: Start server
|
|
98
|
+
node examples/simple-game/server.js
|
|
99
|
+
|
|
100
|
+
# Step 3: Start clients (in new terminals)
|
|
101
|
+
node examples/simple-game/client.js
|
|
102
|
+
node examples/simple-game/client.js # More clients!
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**What it tests:**
|
|
106
|
+
- Real-time networking
|
|
107
|
+
- State synchronization
|
|
108
|
+
- Multiple concurrent players
|
|
109
|
+
- Performance under load
|
|
110
|
+
- Connection stability
|
|
111
|
+
|
|
112
|
+
**See:** [MANUAL_TESTING.md](./MANUAL_TESTING.md) for detailed guide
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### 3. Integration Testing (Your Game)
|
|
117
|
+
|
|
118
|
+
**What:** Test your game built on game-core
|
|
119
|
+
**When:** Building your actual game
|
|
120
|
+
**How:**
|
|
121
|
+
|
|
122
|
+
Create your own test suite:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// __tests__/MyGame.test.ts
|
|
126
|
+
import { GameServer } from '@gamerstake/game-core';
|
|
127
|
+
import { MyGameRules } from '../src/MyGameRules';
|
|
128
|
+
|
|
129
|
+
describe('MyGame', () => {
|
|
130
|
+
it('should award points when collecting items', () => {
|
|
131
|
+
const gameServer = new GameServer();
|
|
132
|
+
const room = gameServer.createRoom('test', new MyGameRules());
|
|
133
|
+
|
|
134
|
+
// Test your game logic
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**See:** [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md) for patterns
|
|
140
|
+
|
|
141
|
+
## Test Coverage
|
|
142
|
+
|
|
143
|
+
### What's Tested
|
|
144
|
+
|
|
145
|
+
| Component | File | Coverage | Tests |
|
|
146
|
+
|-----------|------|----------|-------|
|
|
147
|
+
| **Entities** | Entity.ts | High | Entity.test.ts |
|
|
148
|
+
| **Registry** | Registry.ts | High | Registry.test.ts |
|
|
149
|
+
| **Game Loop** | GameLoop.ts | High | GameLoop.test.ts |
|
|
150
|
+
| **Room** | Room.ts | High | Room.test.ts |
|
|
151
|
+
| **Game Server** | GameServer.ts | High | GameServer.test.ts |
|
|
152
|
+
| **Networking** | Network.ts | High | Network.test.ts |
|
|
153
|
+
| **Snapshots** | Snapshot.ts | High | Snapshot.test.ts |
|
|
154
|
+
| **Spatial Grid** | Grid.ts | High | Grid.test.ts |
|
|
155
|
+
| **Physics** | Movement.ts | High | Movement.test.ts |
|
|
156
|
+
| **Collision** | AABB.ts | High | AABB.test.ts |
|
|
157
|
+
| **Input Queue** | InputQueue.ts | High | InputQueue.test.ts |
|
|
158
|
+
| **RingBuffer** | RingBuffer.ts | High | RingBuffer.test.ts |
|
|
159
|
+
|
|
160
|
+
### Coverage Requirements
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// jest.config.ts
|
|
164
|
+
coverageThreshold: {
|
|
165
|
+
global: {
|
|
166
|
+
branches: 80,
|
|
167
|
+
functions: 80,
|
|
168
|
+
lines: 80,
|
|
169
|
+
statements: 80,
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Quick Commands Reference
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# AUTOMATED TESTS
|
|
178
|
+
pnpm test # Run all tests once
|
|
179
|
+
pnpm test:watch # Watch mode
|
|
180
|
+
pnpm test:coverage # With coverage report
|
|
181
|
+
pnpm typecheck # Type checking only
|
|
182
|
+
|
|
183
|
+
# BUILD
|
|
184
|
+
pnpm build # Build for production
|
|
185
|
+
pnpm dev # Build + watch
|
|
186
|
+
|
|
187
|
+
# MANUAL TESTING
|
|
188
|
+
node examples/simple-game/server.js # Start test server
|
|
189
|
+
node examples/simple-game/client.js # Start test client
|
|
190
|
+
|
|
191
|
+
# LINTING
|
|
192
|
+
pnpm lint # Check code style
|
|
193
|
+
|
|
194
|
+
# CLEAN
|
|
195
|
+
pnpm clean # Remove dist/
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Learning Path
|
|
199
|
+
|
|
200
|
+
### For Complete Beginners
|
|
201
|
+
|
|
202
|
+
1. **Read** [README.md](./README.md) - Understand what game-core is
|
|
203
|
+
2. **Follow** [QUICK_START.md](./QUICK_START.md) - Get something running
|
|
204
|
+
3. **Try** Manual testing - See it work live
|
|
205
|
+
4. **Read** [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md) - Learn patterns
|
|
206
|
+
5. **Build** Your first game!
|
|
207
|
+
|
|
208
|
+
### For Experienced Developers
|
|
209
|
+
|
|
210
|
+
1. **Skim** [README.md](./README.md) - API overview
|
|
211
|
+
2. **Read** [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md) - Advanced patterns
|
|
212
|
+
3. **Review** `tests/` - See usage examples
|
|
213
|
+
4. **Build** Your game!
|
|
214
|
+
|
|
215
|
+
### For Contributors
|
|
216
|
+
|
|
217
|
+
1. **Read** Architecture RFC docs
|
|
218
|
+
2. **Study** Source code (well-documented)
|
|
219
|
+
3. **Run** `pnpm test:coverage`
|
|
220
|
+
4. **Write** Tests for new features
|
|
221
|
+
5. **Submit** PRs with tests
|
|
222
|
+
|
|
223
|
+
## Troubleshooting Testing
|
|
224
|
+
|
|
225
|
+
### Tests Won't Run
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Install dependencies
|
|
229
|
+
pnpm install
|
|
230
|
+
|
|
231
|
+
# Check Node version (needs 20+)
|
|
232
|
+
node --version
|
|
233
|
+
|
|
234
|
+
# Try clean install
|
|
235
|
+
rm -rf node_modules package-lock.json
|
|
236
|
+
pnpm install
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Tests Failing
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Run specific test file
|
|
243
|
+
pnpm test Entity.test.ts
|
|
244
|
+
|
|
245
|
+
# Run with verbose output
|
|
246
|
+
pnpm test --verbose
|
|
247
|
+
|
|
248
|
+
# Update snapshots (if using)
|
|
249
|
+
pnpm test -u
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Manual Testing Issues
|
|
253
|
+
|
|
254
|
+
See [MANUAL_TESTING.md](./MANUAL_TESTING.md) troubleshooting section.
|
|
255
|
+
|
|
256
|
+
### Coverage Not Meeting Threshold
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
# Check which files need more tests
|
|
260
|
+
pnpm test:coverage
|
|
261
|
+
|
|
262
|
+
# View HTML report
|
|
263
|
+
open coverage/index.html
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Performance Testing
|
|
267
|
+
|
|
268
|
+
### Monitoring Metrics
|
|
269
|
+
|
|
270
|
+
The manual test server logs performance metrics:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
Room: 3 players, 8 entities, Avg tick: 12.34ms
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Targets:**
|
|
277
|
+
- **Good:** < 40ms avg tick time
|
|
278
|
+
- **Warning:** 40-50ms (optimization recommended)
|
|
279
|
+
- **Critical:** > 50ms (dropping frames)
|
|
280
|
+
|
|
281
|
+
### Load Testing
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
# Start server
|
|
285
|
+
node examples/simple-game/server.js
|
|
286
|
+
|
|
287
|
+
# In separate terminals, start many clients
|
|
288
|
+
for i in {1..20}; do
|
|
289
|
+
node examples/simple-game/client.js &
|
|
290
|
+
done
|
|
291
|
+
|
|
292
|
+
# Watch server metrics
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Profiling
|
|
296
|
+
|
|
297
|
+
Add profiling to your game rules:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
onTick(room: Room, delta: number) {
|
|
301
|
+
console.time('tick');
|
|
302
|
+
|
|
303
|
+
// Your game logic
|
|
304
|
+
|
|
305
|
+
console.timeEnd('tick');
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Test-Driven Development
|
|
310
|
+
|
|
311
|
+
### Writing Tests for Your Game
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
// 1. Write the test
|
|
315
|
+
it('should damage enemy when attacked', () => {
|
|
316
|
+
const room = createTestRoom();
|
|
317
|
+
const player = room.getRegistry().get('player-1');
|
|
318
|
+
const enemy = room.getRegistry().get('enemy-1');
|
|
319
|
+
|
|
320
|
+
player.attack(enemy);
|
|
321
|
+
|
|
322
|
+
expect(enemy.health).toBe(75); // Started at 100, took 25 damage
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// 2. Implement the feature
|
|
326
|
+
class Player extends Entity {
|
|
327
|
+
attack(target: Entity) {
|
|
328
|
+
target.health -= this.attackPower;
|
|
329
|
+
target.markDirty();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// 3. Run test
|
|
334
|
+
pnpm test
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## Additional Resources
|
|
338
|
+
|
|
339
|
+
### Documentation
|
|
340
|
+
|
|
341
|
+
- **[README.md](./README.md)** - Main API reference
|
|
342
|
+
- **[QUICK_START.md](./QUICK_START.md)** - 5-minute tutorial
|
|
343
|
+
- **[DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md)** - Complete guide
|
|
344
|
+
- **[MANUAL_TESTING.md](./MANUAL_TESTING.md)** - Testing instructions
|
|
345
|
+
- **[PUBLISHING.md](./PUBLISHING.md)** - Publishing and distribution
|
|
346
|
+
|
|
347
|
+
### Examples
|
|
348
|
+
|
|
349
|
+
- **[examples/simple-game/](./examples/simple-game/)** - Working server & client
|
|
350
|
+
|
|
351
|
+
### Tests
|
|
352
|
+
|
|
353
|
+
- **[tests/](./tests/)** - Unit test examples
|
|
354
|
+
|
|
355
|
+
### Source Code
|
|
356
|
+
|
|
357
|
+
- **[src/](./src/)** - Well-documented source (read for advanced usage)
|
|
358
|
+
|
|
359
|
+
## Getting Help
|
|
360
|
+
|
|
361
|
+
1. **Check docs** - Start with [QUICK_START.md](./QUICK_START.md)
|
|
362
|
+
2. **Read examples** - See working code in `examples/`
|
|
363
|
+
3. **Review tests** - See patterns in `tests/`
|
|
364
|
+
4. **Check source** - Code is well-documented
|
|
365
|
+
5. **Contact team** - GamerStake engineering team
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## Summary
|
|
370
|
+
|
|
371
|
+
**Automated testing** with Jest - `pnpm test`
|
|
372
|
+
**Manual testing** with live server - See [MANUAL_TESTING.md](./MANUAL_TESTING.md)
|
|
373
|
+
**Developer guide** - See [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md)
|
|
374
|
+
**Quick start** - See [QUICK_START.md](./QUICK_START.md)
|
|
375
|
+
**Examples** - See `examples/simple-game/`
|
|
376
|
+
**High coverage** - 80% threshold enforced
|
|
377
|
+
|
|
378
|
+
**You're ready to test and build with game-core! **
|