quake2ts 0.0.562 → 0.0.564
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 +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/types/assets/crossReference.d.ts +9 -27
- package/packages/engine/dist/types/assets/crossReference.d.ts.map +1 -1
- package/packages/engine/dist/types/assets/streamingPak.d.ts +28 -0
- package/packages/engine/dist/types/assets/streamingPak.d.ts.map +1 -0
- package/packages/test-utils/dist/index.cjs +435 -5
- package/packages/test-utils/dist/index.cjs.map +1 -1
- package/packages/test-utils/dist/index.d.cts +216 -10
- package/packages/test-utils/dist/index.d.ts +216 -10
- package/packages/test-utils/dist/index.js +414 -5
- package/packages/test-utils/dist/index.js.map +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as vitest from 'vitest';
|
|
2
2
|
import { Mock } from 'vitest';
|
|
3
|
-
import { Vec3, CollisionPlane, CollisionBrush, CollisionNode, CollisionLeaf, CollisionModel, PlayerState, EntityState, createRandomGenerator, NetDriver } from '@quake2ts/shared';
|
|
3
|
+
import { Vec3, CollisionPlane, CollisionBrush, CollisionNode, CollisionLeaf, CollisionModel, PlayerState, EntityState, createRandomGenerator, NetDriver, UserCommand } from '@quake2ts/shared';
|
|
4
4
|
export { intersects, ladderTrace, stairTrace } from '@quake2ts/shared';
|
|
5
5
|
import { GameStateSnapshot, Entity, ScriptHookRegistry, SpawnContext, EntitySystem, SpawnRegistry } from '@quake2ts/game';
|
|
6
|
-
import { NetworkTransport, Server, ServerStatic, Client } from '@quake2ts/server';
|
|
6
|
+
import { NetworkTransport, Server, ServerStatic, Client, ClientState } from '@quake2ts/server';
|
|
7
7
|
import { ImageData } from '@napi-rs/canvas';
|
|
8
8
|
import { LaunchOptions, BrowserContextOptions, Browser, BrowserContext, Page } from 'playwright';
|
|
9
9
|
import { Server as Server$1 } from 'http';
|
|
@@ -267,6 +267,155 @@ interface MockServer {
|
|
|
267
267
|
*/
|
|
268
268
|
declare function createMockServer(overrides?: Partial<MockServer>): MockServer;
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Interface representing connection state for testing.
|
|
272
|
+
*/
|
|
273
|
+
interface Connection {
|
|
274
|
+
state: ClientState;
|
|
275
|
+
address: string;
|
|
276
|
+
challenge: number;
|
|
277
|
+
userInfo: UserInfo;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Stages of the client connection handshake.
|
|
281
|
+
*/
|
|
282
|
+
declare enum HandshakeStage {
|
|
283
|
+
None = 0,
|
|
284
|
+
Challenge = 1,
|
|
285
|
+
Connect = 2,
|
|
286
|
+
Info = 3,
|
|
287
|
+
Active = 4
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Interface representing a handshake state.
|
|
291
|
+
*/
|
|
292
|
+
interface Handshake {
|
|
293
|
+
stage: HandshakeStage;
|
|
294
|
+
clientNum: number;
|
|
295
|
+
challenge: number;
|
|
296
|
+
qport: number;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Interface for UserInfo structure.
|
|
300
|
+
*/
|
|
301
|
+
interface UserInfo {
|
|
302
|
+
name: string;
|
|
303
|
+
skin: string;
|
|
304
|
+
model: string;
|
|
305
|
+
fov: number;
|
|
306
|
+
hand: number;
|
|
307
|
+
rate: number;
|
|
308
|
+
msg: number;
|
|
309
|
+
spectator?: number;
|
|
310
|
+
[key: string]: string | number | undefined;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Helper to serialize UserInfo to Quake 2 info string format.
|
|
314
|
+
* Format: \key\value\key2\value2
|
|
315
|
+
*/
|
|
316
|
+
declare function serializeUserInfo(info: UserInfo): string;
|
|
317
|
+
/**
|
|
318
|
+
* Creates a mock UserInfo object.
|
|
319
|
+
* @param overrides Optional overrides for the user info.
|
|
320
|
+
*/
|
|
321
|
+
declare function createMockUserInfo(overrides?: Partial<UserInfo>): UserInfo;
|
|
322
|
+
/**
|
|
323
|
+
* Creates a mock connection object (Client) with specific state.
|
|
324
|
+
* @param state The client state (default: Connected).
|
|
325
|
+
* @param overrides Optional overrides for the client.
|
|
326
|
+
*/
|
|
327
|
+
declare function createMockConnection(state?: ClientState, overrides?: Partial<Client>): Client;
|
|
328
|
+
/**
|
|
329
|
+
* Creates a mock handshake object.
|
|
330
|
+
* @param stage The stage of the handshake (default: None).
|
|
331
|
+
*/
|
|
332
|
+
declare function createMockHandshake(stage?: HandshakeStage): Handshake;
|
|
333
|
+
/**
|
|
334
|
+
* Simulates a handshake between a mock client and server.
|
|
335
|
+
* Note: This is a high-level simulation helper.
|
|
336
|
+
* @param client The mock client connection.
|
|
337
|
+
* @param server The mock server instance.
|
|
338
|
+
* @returns Promise that resolves to true if handshake succeeded.
|
|
339
|
+
*/
|
|
340
|
+
declare function simulateHandshake(client: Client, server: any): Promise<boolean>;
|
|
341
|
+
|
|
342
|
+
type MockServerContext = Server & {
|
|
343
|
+
clients: (Client | null)[];
|
|
344
|
+
entities?: Entity[];
|
|
345
|
+
};
|
|
346
|
+
interface MultiplayerScenario {
|
|
347
|
+
server: MockServerContext;
|
|
348
|
+
clients: Client[];
|
|
349
|
+
entities: Entity[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Creates a multiplayer test scenario with a mock server and a number of clients.
|
|
353
|
+
* @param numPlayers Number of players to simulate.
|
|
354
|
+
*/
|
|
355
|
+
declare function createMultiplayerTestScenario(numPlayers?: number): MultiplayerScenario;
|
|
356
|
+
/**
|
|
357
|
+
* Simulates a player joining the server.
|
|
358
|
+
* @param server The mock server instance.
|
|
359
|
+
* @param userInfo Optional user info overrides.
|
|
360
|
+
*/
|
|
361
|
+
declare function simulatePlayerJoin(server: MockServerContext, userInfo?: Partial<UserInfo>): Promise<Client>;
|
|
362
|
+
/**
|
|
363
|
+
* Simulates a player leaving the server.
|
|
364
|
+
* @param server The mock server instance.
|
|
365
|
+
* @param clientNum The client number to disconnect.
|
|
366
|
+
*/
|
|
367
|
+
declare function simulatePlayerLeave(server: MockServerContext, clientNum: number): void;
|
|
368
|
+
/**
|
|
369
|
+
* Simulates a single server frame update.
|
|
370
|
+
* @param server The mock server instance.
|
|
371
|
+
* @param deltaTime Time step in seconds (default: 0.1).
|
|
372
|
+
*/
|
|
373
|
+
declare function simulateServerTick(server: MockServerContext, deltaTime?: number): void;
|
|
374
|
+
/**
|
|
375
|
+
* Simulates player input for a specific client.
|
|
376
|
+
* @param client The server client.
|
|
377
|
+
* @param input The input command.
|
|
378
|
+
*/
|
|
379
|
+
declare function simulatePlayerInput(client: Client, input: Partial<UserCommand>): void;
|
|
380
|
+
|
|
381
|
+
interface Snapshot {
|
|
382
|
+
serverTime: number;
|
|
383
|
+
playerState: any;
|
|
384
|
+
entities: EntityState[];
|
|
385
|
+
}
|
|
386
|
+
interface DeltaSnapshot {
|
|
387
|
+
snapshot: Snapshot;
|
|
388
|
+
deltaEntities: EntityState[];
|
|
389
|
+
removedEntities: number[];
|
|
390
|
+
}
|
|
391
|
+
interface ConsistencyReport {
|
|
392
|
+
valid: boolean;
|
|
393
|
+
errors: string[];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Creates a client-specific snapshot from the server state.
|
|
397
|
+
* @param serverState The current server state.
|
|
398
|
+
* @param clientNum The client number to generate snapshot for.
|
|
399
|
+
*/
|
|
400
|
+
declare function createServerSnapshot(serverState: Server, clientNum: number): Snapshot;
|
|
401
|
+
/**
|
|
402
|
+
* Calculates the delta between two snapshots.
|
|
403
|
+
* @param oldSnapshot The baseline snapshot.
|
|
404
|
+
* @param newSnapshot The current snapshot.
|
|
405
|
+
*/
|
|
406
|
+
declare function createDeltaSnapshot(oldSnapshot: Snapshot, newSnapshot: Snapshot): DeltaSnapshot;
|
|
407
|
+
/**
|
|
408
|
+
* Verifies the consistency of a sequence of snapshots.
|
|
409
|
+
* @param snapshots Array of snapshots ordered by time.
|
|
410
|
+
*/
|
|
411
|
+
declare function verifySnapshotConsistency(snapshots: Snapshot[]): ConsistencyReport;
|
|
412
|
+
/**
|
|
413
|
+
* Simulates network delivery of a snapshot with potential packet loss.
|
|
414
|
+
* @param snapshot The snapshot to deliver.
|
|
415
|
+
* @param reliability Probability of successful delivery (0.0 to 1.0).
|
|
416
|
+
*/
|
|
417
|
+
declare function simulateSnapshotDelivery(snapshot: Snapshot, reliability?: number): Promise<Snapshot | null>;
|
|
418
|
+
|
|
270
419
|
interface BrowserSetupOptions {
|
|
271
420
|
url?: string;
|
|
272
421
|
pretendToBeVisual?: boolean;
|
|
@@ -310,11 +459,14 @@ declare function createMockImageData(width: number, height: number, fillColor?:
|
|
|
310
459
|
*/
|
|
311
460
|
declare function createMockImage(width?: number, height?: number, src?: string): HTMLImageElement;
|
|
312
461
|
|
|
462
|
+
interface NodeSetupOptions {
|
|
463
|
+
polyfillFetch?: boolean;
|
|
464
|
+
}
|
|
313
465
|
/**
|
|
314
466
|
* Sets up a Node.js environment for testing.
|
|
315
467
|
* This is primarily for backend or shared logic that doesn't rely on browser APIs.
|
|
316
468
|
*/
|
|
317
|
-
declare function setupNodeEnvironment(): void;
|
|
469
|
+
declare function setupNodeEnvironment(options?: NodeSetupOptions): void;
|
|
318
470
|
|
|
319
471
|
declare function createMockWebGL2Context(canvas: HTMLCanvasElement): WebGL2RenderingContext;
|
|
320
472
|
|
|
@@ -334,14 +486,14 @@ declare function createMockSessionStorage(initialData?: Record<string, string>):
|
|
|
334
486
|
*/
|
|
335
487
|
declare function createMockIndexedDB(): IDBFactory;
|
|
336
488
|
interface StorageScenario {
|
|
337
|
-
storage: Storage;
|
|
338
|
-
populate(data: Record<string,
|
|
339
|
-
verify(key: string, value:
|
|
489
|
+
storage: Storage | IDBFactory;
|
|
490
|
+
populate(data: Record<string, any>): Promise<void> | void;
|
|
491
|
+
verify(key: string, value: any): Promise<boolean> | boolean;
|
|
340
492
|
}
|
|
341
493
|
/**
|
|
342
494
|
* Helper to setup a storage test scenario.
|
|
343
495
|
*/
|
|
344
|
-
declare function createStorageTestScenario(storageType?: 'local' | 'session'): StorageScenario;
|
|
496
|
+
declare function createStorageTestScenario(storageType?: 'local' | 'session' | 'indexed'): StorageScenario;
|
|
345
497
|
|
|
346
498
|
declare function createMockAudioContext(): AudioContext;
|
|
347
499
|
/**
|
|
@@ -358,8 +510,7 @@ interface AudioEvent {
|
|
|
358
510
|
}
|
|
359
511
|
/**
|
|
360
512
|
* Captures audio operations for verification.
|
|
361
|
-
*
|
|
362
|
-
* This is a placeholder for future implementation.
|
|
513
|
+
* Note: Only works if the context was created via createMockAudioContext which proxies calls.
|
|
363
514
|
*/
|
|
364
515
|
declare function captureAudioEvents(context: AudioContext): AudioEvent[];
|
|
365
516
|
|
|
@@ -452,4 +603,59 @@ declare class InputInjector {
|
|
|
452
603
|
wheel(deltaY: number): void;
|
|
453
604
|
}
|
|
454
605
|
|
|
455
|
-
|
|
606
|
+
interface NetworkSimulator {
|
|
607
|
+
apply(page: any): Promise<void>;
|
|
608
|
+
clear(page: any): Promise<void>;
|
|
609
|
+
}
|
|
610
|
+
type NetworkCondition = 'good' | 'slow' | 'unstable' | 'offline';
|
|
611
|
+
interface NetworkConfig {
|
|
612
|
+
offline: boolean;
|
|
613
|
+
downloadThroughput: number;
|
|
614
|
+
uploadThroughput: number;
|
|
615
|
+
latency: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Simulates network conditions using Chrome DevTools Protocol (CDP) via Playwright.
|
|
619
|
+
*/
|
|
620
|
+
declare function simulateNetworkCondition(condition: NetworkCondition): NetworkSimulator;
|
|
621
|
+
/**
|
|
622
|
+
* Creates a custom network condition simulator.
|
|
623
|
+
*
|
|
624
|
+
* @param latency Latency in milliseconds
|
|
625
|
+
* @param jitter Approximate jitter (variation in latency) - Note: CDP doesn't support jitter natively.
|
|
626
|
+
* @param packetLoss Packet loss percentage (0-100) - Ignored for basic CDP emulation.
|
|
627
|
+
*/
|
|
628
|
+
declare function createCustomNetworkCondition(latency: number, jitter?: number, packetLoss?: number, baseConfig?: NetworkConfig): NetworkSimulator;
|
|
629
|
+
/**
|
|
630
|
+
* Throttles bandwidth for the given page.
|
|
631
|
+
*/
|
|
632
|
+
declare function throttleBandwidth(page: any, bytesPerSecond: number): Promise<void>;
|
|
633
|
+
|
|
634
|
+
interface VisualDiff {
|
|
635
|
+
pixelDiff: number;
|
|
636
|
+
diffPath?: string;
|
|
637
|
+
matched: boolean;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Captures a screenshot of the current game state.
|
|
641
|
+
*/
|
|
642
|
+
declare function captureGameScreenshot(page: Page, name: string, options?: {
|
|
643
|
+
dir?: string;
|
|
644
|
+
fullPage?: boolean;
|
|
645
|
+
}): Promise<Buffer>;
|
|
646
|
+
/**
|
|
647
|
+
* Compares two image buffers pixel-by-pixel.
|
|
648
|
+
* Note: A robust implementation would use a library like 'pixelmatch' or 'looks-same'.
|
|
649
|
+
* For now, we provide a basic placeholder or rely on simple buffer comparison.
|
|
650
|
+
*/
|
|
651
|
+
declare function compareScreenshots(baseline: Buffer, current: Buffer, threshold?: number): Promise<VisualDiff>;
|
|
652
|
+
interface VisualScenario {
|
|
653
|
+
capture(name: string): Promise<Buffer>;
|
|
654
|
+
compare(name: string, baselineDir: string): Promise<VisualDiff>;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Creates a helper for visual regression testing scenarios.
|
|
658
|
+
*/
|
|
659
|
+
declare function createVisualTestScenario(page: Page, sceneName: string): VisualScenario;
|
|
660
|
+
|
|
661
|
+
export { type AudioEvent, type BinaryStreamMock, type BinaryWriterMock, type BrowserSetupOptions, type Connection, type ConsistencyReport, type ControlledTimer, type DeltaSnapshot, type DrawCall, type GameState, type GameStateCapture, type Handshake, HandshakeStage, InputInjector, type MockEngine, type MockGame, MockPointerLock, type MockRAF, type MockServer, type MockServerContext, MockTransport, type MockUDPSocket, type MultiplayerScenario, type NetworkAddress, type NetworkCondition, type NetworkConfig, type NetworkSimulator, type NodeSetupOptions, type PlaywrightOptions, type PlaywrightTestClient, type Snapshot, type StorageScenario, type TestContext, type UserInfo, type VisualDiff, type VisualScenario, captureAudioEvents, captureCanvasDrawCalls, captureGameScreenshot, captureGameState, compareScreenshots, createBinaryStreamMock, createBinaryWriterMock, createControlledTimer, createCustomNetworkCondition, createDeltaSnapshot, createEntity, createEntityStateFactory, createGameStateSnapshotFactory, createMockAudioContext, createMockCanvas, createMockCanvasContext2D, createMockConnection, createMockEngine, createMockGame, createMockGameState, createMockHandshake, createMockImage, createMockImageData, createMockIndexedDB, createMockLocalStorage, createMockNetworkAddress, createMockPerformance, createMockRAF, createMockServer, createMockServerClient, createMockServerState, createMockServerStatic, createMockSessionStorage, createMockTransport, createMockUDPSocket, createMockUserInfo, createMockWebGL2Context, createMultiplayerTestScenario, createNetChanMock, createPlayerStateFactory, createPlaywrightTestClient, createServerSnapshot, createSpawnContext, createStorageTestScenario, createTestContext, createVisualTestScenario, makeAxisBrush, makeBrushFromMinsMaxs, makeBspModel, makeLeaf, makeLeafModel, makeNode, makePlane, serializeUserInfo, setupBrowserEnvironment, setupMockAudioContext, setupNodeEnvironment, simulateFrames, simulateFramesWithMock, simulateHandshake, simulateNetworkCondition, simulatePlayerInput, simulatePlayerJoin, simulatePlayerLeave, simulateServerTick, simulateSnapshotDelivery, teardownBrowserEnvironment, teardownMockAudioContext, throttleBandwidth, verifySnapshotConsistency, waitForGameReady };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as vitest from 'vitest';
|
|
2
2
|
import { Mock } from 'vitest';
|
|
3
|
-
import { Vec3, CollisionPlane, CollisionBrush, CollisionNode, CollisionLeaf, CollisionModel, PlayerState, EntityState, createRandomGenerator, NetDriver } from '@quake2ts/shared';
|
|
3
|
+
import { Vec3, CollisionPlane, CollisionBrush, CollisionNode, CollisionLeaf, CollisionModel, PlayerState, EntityState, createRandomGenerator, NetDriver, UserCommand } from '@quake2ts/shared';
|
|
4
4
|
export { intersects, ladderTrace, stairTrace } from '@quake2ts/shared';
|
|
5
5
|
import { GameStateSnapshot, Entity, ScriptHookRegistry, SpawnContext, EntitySystem, SpawnRegistry } from '@quake2ts/game';
|
|
6
|
-
import { NetworkTransport, Server, ServerStatic, Client } from '@quake2ts/server';
|
|
6
|
+
import { NetworkTransport, Server, ServerStatic, Client, ClientState } from '@quake2ts/server';
|
|
7
7
|
import { ImageData } from '@napi-rs/canvas';
|
|
8
8
|
import { LaunchOptions, BrowserContextOptions, Browser, BrowserContext, Page } from 'playwright';
|
|
9
9
|
import { Server as Server$1 } from 'http';
|
|
@@ -267,6 +267,155 @@ interface MockServer {
|
|
|
267
267
|
*/
|
|
268
268
|
declare function createMockServer(overrides?: Partial<MockServer>): MockServer;
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
* Interface representing connection state for testing.
|
|
272
|
+
*/
|
|
273
|
+
interface Connection {
|
|
274
|
+
state: ClientState;
|
|
275
|
+
address: string;
|
|
276
|
+
challenge: number;
|
|
277
|
+
userInfo: UserInfo;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Stages of the client connection handshake.
|
|
281
|
+
*/
|
|
282
|
+
declare enum HandshakeStage {
|
|
283
|
+
None = 0,
|
|
284
|
+
Challenge = 1,
|
|
285
|
+
Connect = 2,
|
|
286
|
+
Info = 3,
|
|
287
|
+
Active = 4
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Interface representing a handshake state.
|
|
291
|
+
*/
|
|
292
|
+
interface Handshake {
|
|
293
|
+
stage: HandshakeStage;
|
|
294
|
+
clientNum: number;
|
|
295
|
+
challenge: number;
|
|
296
|
+
qport: number;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Interface for UserInfo structure.
|
|
300
|
+
*/
|
|
301
|
+
interface UserInfo {
|
|
302
|
+
name: string;
|
|
303
|
+
skin: string;
|
|
304
|
+
model: string;
|
|
305
|
+
fov: number;
|
|
306
|
+
hand: number;
|
|
307
|
+
rate: number;
|
|
308
|
+
msg: number;
|
|
309
|
+
spectator?: number;
|
|
310
|
+
[key: string]: string | number | undefined;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Helper to serialize UserInfo to Quake 2 info string format.
|
|
314
|
+
* Format: \key\value\key2\value2
|
|
315
|
+
*/
|
|
316
|
+
declare function serializeUserInfo(info: UserInfo): string;
|
|
317
|
+
/**
|
|
318
|
+
* Creates a mock UserInfo object.
|
|
319
|
+
* @param overrides Optional overrides for the user info.
|
|
320
|
+
*/
|
|
321
|
+
declare function createMockUserInfo(overrides?: Partial<UserInfo>): UserInfo;
|
|
322
|
+
/**
|
|
323
|
+
* Creates a mock connection object (Client) with specific state.
|
|
324
|
+
* @param state The client state (default: Connected).
|
|
325
|
+
* @param overrides Optional overrides for the client.
|
|
326
|
+
*/
|
|
327
|
+
declare function createMockConnection(state?: ClientState, overrides?: Partial<Client>): Client;
|
|
328
|
+
/**
|
|
329
|
+
* Creates a mock handshake object.
|
|
330
|
+
* @param stage The stage of the handshake (default: None).
|
|
331
|
+
*/
|
|
332
|
+
declare function createMockHandshake(stage?: HandshakeStage): Handshake;
|
|
333
|
+
/**
|
|
334
|
+
* Simulates a handshake between a mock client and server.
|
|
335
|
+
* Note: This is a high-level simulation helper.
|
|
336
|
+
* @param client The mock client connection.
|
|
337
|
+
* @param server The mock server instance.
|
|
338
|
+
* @returns Promise that resolves to true if handshake succeeded.
|
|
339
|
+
*/
|
|
340
|
+
declare function simulateHandshake(client: Client, server: any): Promise<boolean>;
|
|
341
|
+
|
|
342
|
+
type MockServerContext = Server & {
|
|
343
|
+
clients: (Client | null)[];
|
|
344
|
+
entities?: Entity[];
|
|
345
|
+
};
|
|
346
|
+
interface MultiplayerScenario {
|
|
347
|
+
server: MockServerContext;
|
|
348
|
+
clients: Client[];
|
|
349
|
+
entities: Entity[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Creates a multiplayer test scenario with a mock server and a number of clients.
|
|
353
|
+
* @param numPlayers Number of players to simulate.
|
|
354
|
+
*/
|
|
355
|
+
declare function createMultiplayerTestScenario(numPlayers?: number): MultiplayerScenario;
|
|
356
|
+
/**
|
|
357
|
+
* Simulates a player joining the server.
|
|
358
|
+
* @param server The mock server instance.
|
|
359
|
+
* @param userInfo Optional user info overrides.
|
|
360
|
+
*/
|
|
361
|
+
declare function simulatePlayerJoin(server: MockServerContext, userInfo?: Partial<UserInfo>): Promise<Client>;
|
|
362
|
+
/**
|
|
363
|
+
* Simulates a player leaving the server.
|
|
364
|
+
* @param server The mock server instance.
|
|
365
|
+
* @param clientNum The client number to disconnect.
|
|
366
|
+
*/
|
|
367
|
+
declare function simulatePlayerLeave(server: MockServerContext, clientNum: number): void;
|
|
368
|
+
/**
|
|
369
|
+
* Simulates a single server frame update.
|
|
370
|
+
* @param server The mock server instance.
|
|
371
|
+
* @param deltaTime Time step in seconds (default: 0.1).
|
|
372
|
+
*/
|
|
373
|
+
declare function simulateServerTick(server: MockServerContext, deltaTime?: number): void;
|
|
374
|
+
/**
|
|
375
|
+
* Simulates player input for a specific client.
|
|
376
|
+
* @param client The server client.
|
|
377
|
+
* @param input The input command.
|
|
378
|
+
*/
|
|
379
|
+
declare function simulatePlayerInput(client: Client, input: Partial<UserCommand>): void;
|
|
380
|
+
|
|
381
|
+
interface Snapshot {
|
|
382
|
+
serverTime: number;
|
|
383
|
+
playerState: any;
|
|
384
|
+
entities: EntityState[];
|
|
385
|
+
}
|
|
386
|
+
interface DeltaSnapshot {
|
|
387
|
+
snapshot: Snapshot;
|
|
388
|
+
deltaEntities: EntityState[];
|
|
389
|
+
removedEntities: number[];
|
|
390
|
+
}
|
|
391
|
+
interface ConsistencyReport {
|
|
392
|
+
valid: boolean;
|
|
393
|
+
errors: string[];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Creates a client-specific snapshot from the server state.
|
|
397
|
+
* @param serverState The current server state.
|
|
398
|
+
* @param clientNum The client number to generate snapshot for.
|
|
399
|
+
*/
|
|
400
|
+
declare function createServerSnapshot(serverState: Server, clientNum: number): Snapshot;
|
|
401
|
+
/**
|
|
402
|
+
* Calculates the delta between two snapshots.
|
|
403
|
+
* @param oldSnapshot The baseline snapshot.
|
|
404
|
+
* @param newSnapshot The current snapshot.
|
|
405
|
+
*/
|
|
406
|
+
declare function createDeltaSnapshot(oldSnapshot: Snapshot, newSnapshot: Snapshot): DeltaSnapshot;
|
|
407
|
+
/**
|
|
408
|
+
* Verifies the consistency of a sequence of snapshots.
|
|
409
|
+
* @param snapshots Array of snapshots ordered by time.
|
|
410
|
+
*/
|
|
411
|
+
declare function verifySnapshotConsistency(snapshots: Snapshot[]): ConsistencyReport;
|
|
412
|
+
/**
|
|
413
|
+
* Simulates network delivery of a snapshot with potential packet loss.
|
|
414
|
+
* @param snapshot The snapshot to deliver.
|
|
415
|
+
* @param reliability Probability of successful delivery (0.0 to 1.0).
|
|
416
|
+
*/
|
|
417
|
+
declare function simulateSnapshotDelivery(snapshot: Snapshot, reliability?: number): Promise<Snapshot | null>;
|
|
418
|
+
|
|
270
419
|
interface BrowserSetupOptions {
|
|
271
420
|
url?: string;
|
|
272
421
|
pretendToBeVisual?: boolean;
|
|
@@ -310,11 +459,14 @@ declare function createMockImageData(width: number, height: number, fillColor?:
|
|
|
310
459
|
*/
|
|
311
460
|
declare function createMockImage(width?: number, height?: number, src?: string): HTMLImageElement;
|
|
312
461
|
|
|
462
|
+
interface NodeSetupOptions {
|
|
463
|
+
polyfillFetch?: boolean;
|
|
464
|
+
}
|
|
313
465
|
/**
|
|
314
466
|
* Sets up a Node.js environment for testing.
|
|
315
467
|
* This is primarily for backend or shared logic that doesn't rely on browser APIs.
|
|
316
468
|
*/
|
|
317
|
-
declare function setupNodeEnvironment(): void;
|
|
469
|
+
declare function setupNodeEnvironment(options?: NodeSetupOptions): void;
|
|
318
470
|
|
|
319
471
|
declare function createMockWebGL2Context(canvas: HTMLCanvasElement): WebGL2RenderingContext;
|
|
320
472
|
|
|
@@ -334,14 +486,14 @@ declare function createMockSessionStorage(initialData?: Record<string, string>):
|
|
|
334
486
|
*/
|
|
335
487
|
declare function createMockIndexedDB(): IDBFactory;
|
|
336
488
|
interface StorageScenario {
|
|
337
|
-
storage: Storage;
|
|
338
|
-
populate(data: Record<string,
|
|
339
|
-
verify(key: string, value:
|
|
489
|
+
storage: Storage | IDBFactory;
|
|
490
|
+
populate(data: Record<string, any>): Promise<void> | void;
|
|
491
|
+
verify(key: string, value: any): Promise<boolean> | boolean;
|
|
340
492
|
}
|
|
341
493
|
/**
|
|
342
494
|
* Helper to setup a storage test scenario.
|
|
343
495
|
*/
|
|
344
|
-
declare function createStorageTestScenario(storageType?: 'local' | 'session'): StorageScenario;
|
|
496
|
+
declare function createStorageTestScenario(storageType?: 'local' | 'session' | 'indexed'): StorageScenario;
|
|
345
497
|
|
|
346
498
|
declare function createMockAudioContext(): AudioContext;
|
|
347
499
|
/**
|
|
@@ -358,8 +510,7 @@ interface AudioEvent {
|
|
|
358
510
|
}
|
|
359
511
|
/**
|
|
360
512
|
* Captures audio operations for verification.
|
|
361
|
-
*
|
|
362
|
-
* This is a placeholder for future implementation.
|
|
513
|
+
* Note: Only works if the context was created via createMockAudioContext which proxies calls.
|
|
363
514
|
*/
|
|
364
515
|
declare function captureAudioEvents(context: AudioContext): AudioEvent[];
|
|
365
516
|
|
|
@@ -452,4 +603,59 @@ declare class InputInjector {
|
|
|
452
603
|
wheel(deltaY: number): void;
|
|
453
604
|
}
|
|
454
605
|
|
|
455
|
-
|
|
606
|
+
interface NetworkSimulator {
|
|
607
|
+
apply(page: any): Promise<void>;
|
|
608
|
+
clear(page: any): Promise<void>;
|
|
609
|
+
}
|
|
610
|
+
type NetworkCondition = 'good' | 'slow' | 'unstable' | 'offline';
|
|
611
|
+
interface NetworkConfig {
|
|
612
|
+
offline: boolean;
|
|
613
|
+
downloadThroughput: number;
|
|
614
|
+
uploadThroughput: number;
|
|
615
|
+
latency: number;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Simulates network conditions using Chrome DevTools Protocol (CDP) via Playwright.
|
|
619
|
+
*/
|
|
620
|
+
declare function simulateNetworkCondition(condition: NetworkCondition): NetworkSimulator;
|
|
621
|
+
/**
|
|
622
|
+
* Creates a custom network condition simulator.
|
|
623
|
+
*
|
|
624
|
+
* @param latency Latency in milliseconds
|
|
625
|
+
* @param jitter Approximate jitter (variation in latency) - Note: CDP doesn't support jitter natively.
|
|
626
|
+
* @param packetLoss Packet loss percentage (0-100) - Ignored for basic CDP emulation.
|
|
627
|
+
*/
|
|
628
|
+
declare function createCustomNetworkCondition(latency: number, jitter?: number, packetLoss?: number, baseConfig?: NetworkConfig): NetworkSimulator;
|
|
629
|
+
/**
|
|
630
|
+
* Throttles bandwidth for the given page.
|
|
631
|
+
*/
|
|
632
|
+
declare function throttleBandwidth(page: any, bytesPerSecond: number): Promise<void>;
|
|
633
|
+
|
|
634
|
+
interface VisualDiff {
|
|
635
|
+
pixelDiff: number;
|
|
636
|
+
diffPath?: string;
|
|
637
|
+
matched: boolean;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Captures a screenshot of the current game state.
|
|
641
|
+
*/
|
|
642
|
+
declare function captureGameScreenshot(page: Page, name: string, options?: {
|
|
643
|
+
dir?: string;
|
|
644
|
+
fullPage?: boolean;
|
|
645
|
+
}): Promise<Buffer>;
|
|
646
|
+
/**
|
|
647
|
+
* Compares two image buffers pixel-by-pixel.
|
|
648
|
+
* Note: A robust implementation would use a library like 'pixelmatch' or 'looks-same'.
|
|
649
|
+
* For now, we provide a basic placeholder or rely on simple buffer comparison.
|
|
650
|
+
*/
|
|
651
|
+
declare function compareScreenshots(baseline: Buffer, current: Buffer, threshold?: number): Promise<VisualDiff>;
|
|
652
|
+
interface VisualScenario {
|
|
653
|
+
capture(name: string): Promise<Buffer>;
|
|
654
|
+
compare(name: string, baselineDir: string): Promise<VisualDiff>;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Creates a helper for visual regression testing scenarios.
|
|
658
|
+
*/
|
|
659
|
+
declare function createVisualTestScenario(page: Page, sceneName: string): VisualScenario;
|
|
660
|
+
|
|
661
|
+
export { type AudioEvent, type BinaryStreamMock, type BinaryWriterMock, type BrowserSetupOptions, type Connection, type ConsistencyReport, type ControlledTimer, type DeltaSnapshot, type DrawCall, type GameState, type GameStateCapture, type Handshake, HandshakeStage, InputInjector, type MockEngine, type MockGame, MockPointerLock, type MockRAF, type MockServer, type MockServerContext, MockTransport, type MockUDPSocket, type MultiplayerScenario, type NetworkAddress, type NetworkCondition, type NetworkConfig, type NetworkSimulator, type NodeSetupOptions, type PlaywrightOptions, type PlaywrightTestClient, type Snapshot, type StorageScenario, type TestContext, type UserInfo, type VisualDiff, type VisualScenario, captureAudioEvents, captureCanvasDrawCalls, captureGameScreenshot, captureGameState, compareScreenshots, createBinaryStreamMock, createBinaryWriterMock, createControlledTimer, createCustomNetworkCondition, createDeltaSnapshot, createEntity, createEntityStateFactory, createGameStateSnapshotFactory, createMockAudioContext, createMockCanvas, createMockCanvasContext2D, createMockConnection, createMockEngine, createMockGame, createMockGameState, createMockHandshake, createMockImage, createMockImageData, createMockIndexedDB, createMockLocalStorage, createMockNetworkAddress, createMockPerformance, createMockRAF, createMockServer, createMockServerClient, createMockServerState, createMockServerStatic, createMockSessionStorage, createMockTransport, createMockUDPSocket, createMockUserInfo, createMockWebGL2Context, createMultiplayerTestScenario, createNetChanMock, createPlayerStateFactory, createPlaywrightTestClient, createServerSnapshot, createSpawnContext, createStorageTestScenario, createTestContext, createVisualTestScenario, makeAxisBrush, makeBrushFromMinsMaxs, makeBspModel, makeLeaf, makeLeafModel, makeNode, makePlane, serializeUserInfo, setupBrowserEnvironment, setupMockAudioContext, setupNodeEnvironment, simulateFrames, simulateFramesWithMock, simulateHandshake, simulateNetworkCondition, simulatePlayerInput, simulatePlayerJoin, simulatePlayerLeave, simulateServerTick, simulateSnapshotDelivery, teardownBrowserEnvironment, teardownMockAudioContext, throttleBandwidth, verifySnapshotConsistency, waitForGameReady };
|