@quake2ts/test-utils 0.0.740 → 0.0.741

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quake2ts/test-utils",
3
- "version": "0.0.740",
3
+ "version": "0.0.741",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -39,10 +39,10 @@
39
39
  "pngjs": "^7.0.0",
40
40
  "vitest": "^1.6.0",
41
41
  "webgpu": "^0.3.8",
42
- "@quake2ts/engine": "^0.0.740",
43
- "@quake2ts/game": "0.0.740",
44
- "@quake2ts/server": "0.0.740",
45
- "@quake2ts/shared": "0.0.740"
42
+ "@quake2ts/engine": "^0.0.741",
43
+ "@quake2ts/server": "0.0.741",
44
+ "@quake2ts/shared": "0.0.741",
45
+ "@quake2ts/game": "0.0.741"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "@quake2ts/engine": {
@@ -92,10 +92,10 @@
92
92
  "typescript": "^5.4.5",
93
93
  "vitest": "^1.6.0",
94
94
  "webgpu": "^0.3.8",
95
- "@quake2ts/engine": "^0.0.740",
96
- "@quake2ts/game": "0.0.740",
97
- "@quake2ts/server": "0.0.740",
98
- "@quake2ts/shared": "0.0.740"
95
+ "@quake2ts/engine": "^0.0.741",
96
+ "@quake2ts/game": "0.0.741",
97
+ "@quake2ts/shared": "0.0.741",
98
+ "@quake2ts/server": "0.0.741"
99
99
  },
100
100
  "scripts": {
101
101
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -180,16 +180,16 @@ export function createTestContext(options?: { seed?: number, initialEntities?: E
180
180
  frameNumber: 1,
181
181
  sightEntity: null,
182
182
  soundEntity: null,
183
+ activePlayers: [],
184
+ monsterAlertedByPlayers: vi.fn().mockReturnValue(null),
185
+ soundClient: vi.fn().mockReturnValue(null),
183
186
  },
184
- warn: vi.fn(), // Added warn to entities as it is sometimes used there too, though typically on SpawnContext
185
- // Adding missing properties to satisfy EntitySystem interface partially or fully
186
- // We cast to unknown first anyway, but filling these in makes it safer for consumers
187
+ warn: vi.fn(),
187
188
  skill: 1,
188
189
  deathmatch: false,
189
190
  coop: false,
190
191
  activeCount: entityList.length,
191
192
  world: entityList.find(e => e.classname === 'worldspawn') || new Entity(0),
192
- // ... other EntitySystem properties would go here
193
193
  } as unknown as EntitySystem;
194
194
 
195
195
  return {
@@ -200,7 +200,6 @@ export function createTestContext(options?: { seed?: number, initialEntities?: E
200
200
  health_multiplier: 1,
201
201
  warn: vi.fn(),
202
202
  free: vi.fn(),
203
- // Mock precache functions if they are part of SpawnContext in future or TestContext extensions
204
203
  precacheModel: vi.fn(),
205
204
  precacheSound: vi.fn(),
206
205
  precacheImage: vi.fn(),
@@ -209,7 +208,6 @@ export function createTestContext(options?: { seed?: number, initialEntities?: E
209
208
 
210
209
  export function createSpawnTestContext(mapName?: string): TestContext {
211
210
  const ctx = createTestContext();
212
- // Simulate map load if needed
213
211
  if (mapName) {
214
212
  ctx.game.spawnWorld();
215
213
  }
@@ -222,7 +220,6 @@ export function createCombatTestContext(): TestContext {
222
220
 
223
221
  export function createPhysicsTestContext(bspModel?: BspModel): TestContext {
224
222
  const context = createTestContext();
225
-
226
223
  if (bspModel) {
227
224
  // If a BSP model is provided, we can set up the trace mock to be more realistic.
228
225
  // For now, we'll just store the model on the context if we extended TestContext,
@@ -231,7 +228,6 @@ export function createPhysicsTestContext(bspModel?: BspModel): TestContext {
231
228
  // In a real scenario, we might want to hook up a real BSP physics engine mock here
232
229
  // or a mock that uses the BSP data.
233
230
  }
234
-
235
231
  return context;
236
232
  }
237
233
 
@@ -239,6 +235,21 @@ export function createEntity(): Entity {
239
235
  return new Entity(1);
240
236
  }
241
237
 
238
+ /**
239
+ * Spawns an entity into the system and applies the properties from the provided data object.
240
+ * This is useful for testing when you want to spawn an entity with specific properties
241
+ * generated by a factory.
242
+ *
243
+ * @param system - The EntitySystem to spawn into.
244
+ * @param data - The partial entity data to apply (e.g. from createPlayerEntityFactory).
245
+ * @returns The spawned and populated Entity.
246
+ */
247
+ export function spawnEntity(system: EntitySystem, data: Partial<Entity>): Entity {
248
+ const ent = system.spawn();
249
+ Object.assign(ent, data);
250
+ return ent;
251
+ }
252
+
242
253
  /**
243
254
  * Creates mock imports and engine for use with createGame() from @quake2ts/game.
244
255
  * This is a convenience helper that provides all the commonly mocked functions
@@ -272,7 +283,6 @@ export function createGameImportsAndEngine(overrides?: {
272
283
  soundIndex: Mock;
273
284
  }>;
274
285
  }) {
275
- // Default trace result - matches the pattern from original monster tests
276
286
  const defaultTraceResult = {
277
287
  fraction: 1.0,
278
288
  endpos: { x: 0, y: 0, z: 0 },
@@ -63,3 +63,5 @@ export const randomVector3 = (min: number = -100, max: number = 100): Vec3 => ({
63
63
  y: Math.random() * (max - min) + min,
64
64
  z: Math.random() * (max - min) + min,
65
65
  });
66
+
67
+ export { ZERO_VEC3 } from '@quake2ts/shared';