quake2ts 0.0.564 → 0.0.566
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/render/webgpu/context.d.ts +27 -0
- package/packages/engine/dist/types/render/webgpu/context.d.ts.map +1 -0
- package/packages/test-utils/dist/index.cjs +249 -178
- package/packages/test-utils/dist/index.cjs.map +1 -1
- package/packages/test-utils/dist/index.d.cts +46 -41
- package/packages/test-utils/dist/index.d.ts +46 -41
- package/packages/test-utils/dist/index.js +245 -178
- package/packages/test-utils/dist/index.js.map +1 -1
|
@@ -459,6 +459,51 @@ declare function createMockImageData(width: number, height: number, fillColor?:
|
|
|
459
459
|
*/
|
|
460
460
|
declare function createMockImage(width?: number, height?: number, src?: string): HTMLImageElement;
|
|
461
461
|
|
|
462
|
+
declare function createMockGPUAdapter(): Partial<GPUAdapter>;
|
|
463
|
+
declare function createMockGPUDevice(): Partial<GPUDevice>;
|
|
464
|
+
declare function createMockGPUCanvasContext(): Partial<GPUCanvasContext>;
|
|
465
|
+
declare function setupWebGPUMocks(): void;
|
|
466
|
+
|
|
467
|
+
interface MockRAF {
|
|
468
|
+
tick(timestamp?: number): void;
|
|
469
|
+
advance(deltaMs?: number): void;
|
|
470
|
+
getCallbacks(): FrameRequestCallback[];
|
|
471
|
+
reset(): void;
|
|
472
|
+
enable(): void;
|
|
473
|
+
disable(): void;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Creates a mock implementation of requestAnimationFrame that allows manual control.
|
|
477
|
+
* It replaces the global requestAnimationFrame and cancelAnimationFrame.
|
|
478
|
+
*/
|
|
479
|
+
declare function createMockRAF(): MockRAF;
|
|
480
|
+
/**
|
|
481
|
+
* Creates a mock Performance object with controllable time.
|
|
482
|
+
*/
|
|
483
|
+
declare function createMockPerformance(startTime?: number): Performance;
|
|
484
|
+
interface ControlledTimer {
|
|
485
|
+
tick(): void;
|
|
486
|
+
advanceBy(ms: number): void;
|
|
487
|
+
clear(): void;
|
|
488
|
+
restore(): void;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Creates a controlled timer that replaces global setTimeout/setInterval.
|
|
492
|
+
* Allows deterministic time advancement.
|
|
493
|
+
*/
|
|
494
|
+
declare function createControlledTimer(): ControlledTimer;
|
|
495
|
+
/**
|
|
496
|
+
* Helper to simulate multiple frames of a game loop.
|
|
497
|
+
* @param count Number of frames to simulate
|
|
498
|
+
* @param frameTimeMs Time per frame in milliseconds
|
|
499
|
+
* @param callback Optional callback to run inside the loop (e.g. triggering inputs)
|
|
500
|
+
*/
|
|
501
|
+
declare function simulateFrames(count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
502
|
+
/**
|
|
503
|
+
* Simulates frames using a provided MockRAF controller.
|
|
504
|
+
*/
|
|
505
|
+
declare function simulateFramesWithMock(mock: MockRAF, count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
506
|
+
|
|
462
507
|
interface NodeSetupOptions {
|
|
463
508
|
polyfillFetch?: boolean;
|
|
464
509
|
}
|
|
@@ -514,46 +559,6 @@ interface AudioEvent {
|
|
|
514
559
|
*/
|
|
515
560
|
declare function captureAudioEvents(context: AudioContext): AudioEvent[];
|
|
516
561
|
|
|
517
|
-
interface MockRAF {
|
|
518
|
-
tick(timestamp?: number): void;
|
|
519
|
-
advance(deltaMs?: number): void;
|
|
520
|
-
getCallbacks(): FrameRequestCallback[];
|
|
521
|
-
reset(): void;
|
|
522
|
-
enable(): void;
|
|
523
|
-
disable(): void;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Creates a mock implementation of requestAnimationFrame that allows manual control.
|
|
527
|
-
* It replaces the global requestAnimationFrame and cancelAnimationFrame.
|
|
528
|
-
*/
|
|
529
|
-
declare function createMockRAF(): MockRAF;
|
|
530
|
-
/**
|
|
531
|
-
* Creates a mock Performance object with controllable time.
|
|
532
|
-
*/
|
|
533
|
-
declare function createMockPerformance(startTime?: number): Performance;
|
|
534
|
-
interface ControlledTimer {
|
|
535
|
-
tick(): void;
|
|
536
|
-
advanceBy(ms: number): void;
|
|
537
|
-
clear(): void;
|
|
538
|
-
restore(): void;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Creates a controlled timer that replaces global setTimeout/setInterval.
|
|
542
|
-
* Allows deterministic time advancement.
|
|
543
|
-
*/
|
|
544
|
-
declare function createControlledTimer(): ControlledTimer;
|
|
545
|
-
/**
|
|
546
|
-
* Helper to simulate multiple frames of a game loop.
|
|
547
|
-
* @param count Number of frames to simulate
|
|
548
|
-
* @param frameTimeMs Time per frame in milliseconds
|
|
549
|
-
* @param callback Optional callback to run inside the loop (e.g. triggering inputs)
|
|
550
|
-
*/
|
|
551
|
-
declare function simulateFrames(count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
552
|
-
/**
|
|
553
|
-
* Simulates frames using a provided MockRAF controller.
|
|
554
|
-
*/
|
|
555
|
-
declare function simulateFramesWithMock(mock: MockRAF, count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
556
|
-
|
|
557
562
|
/**
|
|
558
563
|
* Interface for Test Client options
|
|
559
564
|
*/
|
|
@@ -658,4 +663,4 @@ interface VisualScenario {
|
|
|
658
663
|
*/
|
|
659
664
|
declare function createVisualTestScenario(page: Page, sceneName: string): VisualScenario;
|
|
660
665
|
|
|
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 };
|
|
666
|
+
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, createMockGPUAdapter, createMockGPUCanvasContext, createMockGPUDevice, 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, setupWebGPUMocks, simulateFrames, simulateFramesWithMock, simulateHandshake, simulateNetworkCondition, simulatePlayerInput, simulatePlayerJoin, simulatePlayerLeave, simulateServerTick, simulateSnapshotDelivery, teardownBrowserEnvironment, teardownMockAudioContext, throttleBandwidth, verifySnapshotConsistency, waitForGameReady };
|
|
@@ -459,6 +459,51 @@ declare function createMockImageData(width: number, height: number, fillColor?:
|
|
|
459
459
|
*/
|
|
460
460
|
declare function createMockImage(width?: number, height?: number, src?: string): HTMLImageElement;
|
|
461
461
|
|
|
462
|
+
declare function createMockGPUAdapter(): Partial<GPUAdapter>;
|
|
463
|
+
declare function createMockGPUDevice(): Partial<GPUDevice>;
|
|
464
|
+
declare function createMockGPUCanvasContext(): Partial<GPUCanvasContext>;
|
|
465
|
+
declare function setupWebGPUMocks(): void;
|
|
466
|
+
|
|
467
|
+
interface MockRAF {
|
|
468
|
+
tick(timestamp?: number): void;
|
|
469
|
+
advance(deltaMs?: number): void;
|
|
470
|
+
getCallbacks(): FrameRequestCallback[];
|
|
471
|
+
reset(): void;
|
|
472
|
+
enable(): void;
|
|
473
|
+
disable(): void;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Creates a mock implementation of requestAnimationFrame that allows manual control.
|
|
477
|
+
* It replaces the global requestAnimationFrame and cancelAnimationFrame.
|
|
478
|
+
*/
|
|
479
|
+
declare function createMockRAF(): MockRAF;
|
|
480
|
+
/**
|
|
481
|
+
* Creates a mock Performance object with controllable time.
|
|
482
|
+
*/
|
|
483
|
+
declare function createMockPerformance(startTime?: number): Performance;
|
|
484
|
+
interface ControlledTimer {
|
|
485
|
+
tick(): void;
|
|
486
|
+
advanceBy(ms: number): void;
|
|
487
|
+
clear(): void;
|
|
488
|
+
restore(): void;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Creates a controlled timer that replaces global setTimeout/setInterval.
|
|
492
|
+
* Allows deterministic time advancement.
|
|
493
|
+
*/
|
|
494
|
+
declare function createControlledTimer(): ControlledTimer;
|
|
495
|
+
/**
|
|
496
|
+
* Helper to simulate multiple frames of a game loop.
|
|
497
|
+
* @param count Number of frames to simulate
|
|
498
|
+
* @param frameTimeMs Time per frame in milliseconds
|
|
499
|
+
* @param callback Optional callback to run inside the loop (e.g. triggering inputs)
|
|
500
|
+
*/
|
|
501
|
+
declare function simulateFrames(count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
502
|
+
/**
|
|
503
|
+
* Simulates frames using a provided MockRAF controller.
|
|
504
|
+
*/
|
|
505
|
+
declare function simulateFramesWithMock(mock: MockRAF, count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
506
|
+
|
|
462
507
|
interface NodeSetupOptions {
|
|
463
508
|
polyfillFetch?: boolean;
|
|
464
509
|
}
|
|
@@ -514,46 +559,6 @@ interface AudioEvent {
|
|
|
514
559
|
*/
|
|
515
560
|
declare function captureAudioEvents(context: AudioContext): AudioEvent[];
|
|
516
561
|
|
|
517
|
-
interface MockRAF {
|
|
518
|
-
tick(timestamp?: number): void;
|
|
519
|
-
advance(deltaMs?: number): void;
|
|
520
|
-
getCallbacks(): FrameRequestCallback[];
|
|
521
|
-
reset(): void;
|
|
522
|
-
enable(): void;
|
|
523
|
-
disable(): void;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Creates a mock implementation of requestAnimationFrame that allows manual control.
|
|
527
|
-
* It replaces the global requestAnimationFrame and cancelAnimationFrame.
|
|
528
|
-
*/
|
|
529
|
-
declare function createMockRAF(): MockRAF;
|
|
530
|
-
/**
|
|
531
|
-
* Creates a mock Performance object with controllable time.
|
|
532
|
-
*/
|
|
533
|
-
declare function createMockPerformance(startTime?: number): Performance;
|
|
534
|
-
interface ControlledTimer {
|
|
535
|
-
tick(): void;
|
|
536
|
-
advanceBy(ms: number): void;
|
|
537
|
-
clear(): void;
|
|
538
|
-
restore(): void;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Creates a controlled timer that replaces global setTimeout/setInterval.
|
|
542
|
-
* Allows deterministic time advancement.
|
|
543
|
-
*/
|
|
544
|
-
declare function createControlledTimer(): ControlledTimer;
|
|
545
|
-
/**
|
|
546
|
-
* Helper to simulate multiple frames of a game loop.
|
|
547
|
-
* @param count Number of frames to simulate
|
|
548
|
-
* @param frameTimeMs Time per frame in milliseconds
|
|
549
|
-
* @param callback Optional callback to run inside the loop (e.g. triggering inputs)
|
|
550
|
-
*/
|
|
551
|
-
declare function simulateFrames(count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
552
|
-
/**
|
|
553
|
-
* Simulates frames using a provided MockRAF controller.
|
|
554
|
-
*/
|
|
555
|
-
declare function simulateFramesWithMock(mock: MockRAF, count: number, frameTimeMs?: number, callback?: (frameIndex: number) => void): void;
|
|
556
|
-
|
|
557
562
|
/**
|
|
558
563
|
* Interface for Test Client options
|
|
559
564
|
*/
|
|
@@ -658,4 +663,4 @@ interface VisualScenario {
|
|
|
658
663
|
*/
|
|
659
664
|
declare function createVisualTestScenario(page: Page, sceneName: string): VisualScenario;
|
|
660
665
|
|
|
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 };
|
|
666
|
+
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, createMockGPUAdapter, createMockGPUCanvasContext, createMockGPUDevice, 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, setupWebGPUMocks, simulateFrames, simulateFramesWithMock, simulateHandshake, simulateNetworkCondition, simulatePlayerInput, simulatePlayerJoin, simulatePlayerLeave, simulateServerTick, simulateSnapshotDelivery, teardownBrowserEnvironment, teardownMockAudioContext, throttleBandwidth, verifySnapshotConsistency, waitForGameReady };
|
|
@@ -1287,193 +1287,67 @@ function createMockImage(width, height, src) {
|
|
|
1287
1287
|
return img;
|
|
1288
1288
|
}
|
|
1289
1289
|
|
|
1290
|
-
// src/
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
// src/setup/storage.ts
|
|
1297
|
-
import "fake-indexeddb/auto";
|
|
1298
|
-
function createMockLocalStorage(initialData = {}) {
|
|
1299
|
-
const storage = new Map(Object.entries(initialData));
|
|
1290
|
+
// src/engine/mocks/webgpu.ts
|
|
1291
|
+
import { vi as vi5 } from "vitest";
|
|
1292
|
+
function createMockGPUAdapter() {
|
|
1300
1293
|
return {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
clear: () => storage.clear(),
|
|
1305
|
-
key: (index) => Array.from(storage.keys())[index] || null,
|
|
1306
|
-
get length() {
|
|
1307
|
-
return storage.size;
|
|
1308
|
-
}
|
|
1294
|
+
requestDevice: vi5.fn().mockResolvedValue(createMockGPUDevice()),
|
|
1295
|
+
features: /* @__PURE__ */ new Set(),
|
|
1296
|
+
limits: {}
|
|
1309
1297
|
};
|
|
1310
1298
|
}
|
|
1311
|
-
function
|
|
1312
|
-
return
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1299
|
+
function createMockGPUDevice() {
|
|
1300
|
+
return {
|
|
1301
|
+
features: /* @__PURE__ */ new Set(),
|
|
1302
|
+
limits: {},
|
|
1303
|
+
queue: {
|
|
1304
|
+
submit: vi5.fn(),
|
|
1305
|
+
writeBuffer: vi5.fn(),
|
|
1306
|
+
writeTexture: vi5.fn(),
|
|
1307
|
+
copyExternalImageToTexture: vi5.fn()
|
|
1308
|
+
},
|
|
1309
|
+
createCommandEncoder: vi5.fn().mockReturnValue({
|
|
1310
|
+
beginRenderPass: vi5.fn().mockReturnValue({
|
|
1311
|
+
setPipeline: vi5.fn(),
|
|
1312
|
+
draw: vi5.fn(),
|
|
1313
|
+
end: vi5.fn()
|
|
1314
|
+
}),
|
|
1315
|
+
finish: vi5.fn()
|
|
1316
|
+
}),
|
|
1317
|
+
createRenderPipeline: vi5.fn(),
|
|
1318
|
+
createShaderModule: vi5.fn(),
|
|
1319
|
+
createBindGroup: vi5.fn(),
|
|
1320
|
+
createBindGroupLayout: vi5.fn(),
|
|
1321
|
+
createBuffer: vi5.fn(),
|
|
1322
|
+
createTexture: vi5.fn(),
|
|
1323
|
+
createSampler: vi5.fn()
|
|
1324
|
+
};
|
|
1319
1325
|
}
|
|
1320
|
-
function
|
|
1321
|
-
if (storageType === "indexed") {
|
|
1322
|
-
const dbName = `test-db-${Math.random().toString(36).substring(7)}`;
|
|
1323
|
-
const storeName = "test-store";
|
|
1324
|
-
const storage2 = createMockIndexedDB();
|
|
1325
|
-
return {
|
|
1326
|
-
storage: storage2,
|
|
1327
|
-
populate: async (data) => {
|
|
1328
|
-
return new Promise((resolve, reject) => {
|
|
1329
|
-
const req = storage2.open(dbName, 1);
|
|
1330
|
-
req.onupgradeneeded = (e) => {
|
|
1331
|
-
const db = e.target.result;
|
|
1332
|
-
db.createObjectStore(storeName);
|
|
1333
|
-
};
|
|
1334
|
-
req.onsuccess = (e) => {
|
|
1335
|
-
const db = e.target.result;
|
|
1336
|
-
const tx = db.transaction(storeName, "readwrite");
|
|
1337
|
-
const store = tx.objectStore(storeName);
|
|
1338
|
-
Object.entries(data).forEach(([k, v]) => store.put(v, k));
|
|
1339
|
-
tx.oncomplete = () => {
|
|
1340
|
-
db.close();
|
|
1341
|
-
resolve();
|
|
1342
|
-
};
|
|
1343
|
-
tx.onerror = () => reject(tx.error);
|
|
1344
|
-
};
|
|
1345
|
-
req.onerror = () => reject(req.error);
|
|
1346
|
-
});
|
|
1347
|
-
},
|
|
1348
|
-
verify: async (key, value) => {
|
|
1349
|
-
return new Promise((resolve, reject) => {
|
|
1350
|
-
const req = storage2.open(dbName, 1);
|
|
1351
|
-
req.onsuccess = (e) => {
|
|
1352
|
-
const db = e.target.result;
|
|
1353
|
-
if (!db.objectStoreNames.contains(storeName)) {
|
|
1354
|
-
db.close();
|
|
1355
|
-
resolve(false);
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
const tx = db.transaction(storeName, "readonly");
|
|
1359
|
-
const store = tx.objectStore(storeName);
|
|
1360
|
-
const getReq = store.get(key);
|
|
1361
|
-
getReq.onsuccess = () => {
|
|
1362
|
-
const result = getReq.result === value;
|
|
1363
|
-
db.close();
|
|
1364
|
-
resolve(result);
|
|
1365
|
-
};
|
|
1366
|
-
getReq.onerror = () => {
|
|
1367
|
-
db.close();
|
|
1368
|
-
resolve(false);
|
|
1369
|
-
};
|
|
1370
|
-
};
|
|
1371
|
-
req.onerror = () => reject(req.error);
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
const storage = storageType === "local" ? createMockLocalStorage() : createMockSessionStorage();
|
|
1326
|
+
function createMockGPUCanvasContext() {
|
|
1377
1327
|
return {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
},
|
|
1382
|
-
verify(key, value) {
|
|
1383
|
-
return storage.getItem(key) === value;
|
|
1384
|
-
}
|
|
1328
|
+
configure: vi5.fn(),
|
|
1329
|
+
unconfigure: vi5.fn(),
|
|
1330
|
+
getCurrentTexture: vi5.fn()
|
|
1385
1331
|
};
|
|
1386
1332
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
connect: () => {
|
|
1393
|
-
},
|
|
1394
|
-
gain: { value: 1, setValueAtTime: () => {
|
|
1395
|
-
} }
|
|
1396
|
-
}),
|
|
1397
|
-
createOscillator: () => ({
|
|
1398
|
-
connect: () => {
|
|
1399
|
-
},
|
|
1400
|
-
start: () => {
|
|
1401
|
-
},
|
|
1402
|
-
stop: () => {
|
|
1403
|
-
},
|
|
1404
|
-
frequency: { value: 440 }
|
|
1405
|
-
}),
|
|
1406
|
-
createBufferSource: () => ({
|
|
1407
|
-
connect: () => {
|
|
1408
|
-
},
|
|
1409
|
-
start: () => {
|
|
1410
|
-
},
|
|
1411
|
-
stop: () => {
|
|
1412
|
-
},
|
|
1413
|
-
buffer: null,
|
|
1414
|
-
playbackRate: { value: 1 },
|
|
1415
|
-
loop: false
|
|
1416
|
-
}),
|
|
1417
|
-
destination: {},
|
|
1418
|
-
currentTime: 0,
|
|
1419
|
-
state: "running",
|
|
1420
|
-
resume: async () => {
|
|
1421
|
-
},
|
|
1422
|
-
suspend: async () => {
|
|
1423
|
-
},
|
|
1424
|
-
close: async () => {
|
|
1425
|
-
},
|
|
1426
|
-
decodeAudioData: async (buffer) => ({
|
|
1427
|
-
duration: 1,
|
|
1428
|
-
length: 44100,
|
|
1429
|
-
sampleRate: 44100,
|
|
1430
|
-
numberOfChannels: 2,
|
|
1431
|
-
getChannelData: () => new Float32Array(44100)
|
|
1432
|
-
}),
|
|
1433
|
-
createBuffer: (channels, length, sampleRate) => ({
|
|
1434
|
-
duration: length / sampleRate,
|
|
1435
|
-
length,
|
|
1436
|
-
sampleRate,
|
|
1437
|
-
numberOfChannels: channels,
|
|
1438
|
-
getChannelData: () => new Float32Array(length)
|
|
1439
|
-
}),
|
|
1440
|
-
// Helper to track events if needed
|
|
1441
|
-
_events: []
|
|
1333
|
+
function setupWebGPUMocks() {
|
|
1334
|
+
const mockAdapter = createMockGPUAdapter();
|
|
1335
|
+
const mockGpu = {
|
|
1336
|
+
requestAdapter: vi5.fn().mockResolvedValue(mockAdapter),
|
|
1337
|
+
getPreferredCanvasFormat: vi5.fn().mockReturnValue("bgra8unorm")
|
|
1442
1338
|
};
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
if (typeof value === "function") {
|
|
1448
|
-
return (...args) => {
|
|
1449
|
-
target._events.push({ type: String(prop), args });
|
|
1450
|
-
return Reflect.apply(value, target, args);
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
return value;
|
|
1454
|
-
}
|
|
1339
|
+
Object.defineProperty(global.navigator, "gpu", {
|
|
1340
|
+
value: mockGpu,
|
|
1341
|
+
writable: true,
|
|
1342
|
+
configurable: true
|
|
1455
1343
|
});
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
};
|
|
1464
|
-
global.window.AudioContext = global.AudioContext;
|
|
1465
|
-
global.window.webkitAudioContext = global.AudioContext;
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
function teardownMockAudioContext() {
|
|
1469
|
-
if (global.AudioContext && global.AudioContext.toString().includes("class")) {
|
|
1470
|
-
delete global.AudioContext;
|
|
1471
|
-
delete global.window.AudioContext;
|
|
1472
|
-
delete global.window.webkitAudioContext;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
function captureAudioEvents(context) {
|
|
1476
|
-
return context._events || [];
|
|
1344
|
+
global.GPUTextureUsage = {
|
|
1345
|
+
COPY_SRC: 1,
|
|
1346
|
+
COPY_DST: 2,
|
|
1347
|
+
TEXTURE_BINDING: 4,
|
|
1348
|
+
STORAGE_BINDING: 8,
|
|
1349
|
+
RENDER_ATTACHMENT: 16
|
|
1350
|
+
};
|
|
1477
1351
|
}
|
|
1478
1352
|
|
|
1479
1353
|
// src/setup/timing.ts
|
|
@@ -1660,6 +1534,195 @@ function simulateFramesWithMock(mock, count, frameTimeMs = 16.6, callback) {
|
|
|
1660
1534
|
}
|
|
1661
1535
|
}
|
|
1662
1536
|
|
|
1537
|
+
// src/setup/node.ts
|
|
1538
|
+
function setupNodeEnvironment(options = {}) {
|
|
1539
|
+
if (options.polyfillFetch && typeof global.fetch === "undefined") {
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
// src/setup/storage.ts
|
|
1544
|
+
import "fake-indexeddb/auto";
|
|
1545
|
+
function createMockLocalStorage(initialData = {}) {
|
|
1546
|
+
const storage = new Map(Object.entries(initialData));
|
|
1547
|
+
return {
|
|
1548
|
+
getItem: (key) => storage.get(key) || null,
|
|
1549
|
+
setItem: (key, value) => storage.set(key, value),
|
|
1550
|
+
removeItem: (key) => storage.delete(key),
|
|
1551
|
+
clear: () => storage.clear(),
|
|
1552
|
+
key: (index) => Array.from(storage.keys())[index] || null,
|
|
1553
|
+
get length() {
|
|
1554
|
+
return storage.size;
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function createMockSessionStorage(initialData = {}) {
|
|
1559
|
+
return createMockLocalStorage(initialData);
|
|
1560
|
+
}
|
|
1561
|
+
function createMockIndexedDB() {
|
|
1562
|
+
if (typeof indexedDB === "undefined") {
|
|
1563
|
+
throw new Error("IndexedDB mock not found. Ensure fake-indexeddb is loaded.");
|
|
1564
|
+
}
|
|
1565
|
+
return indexedDB;
|
|
1566
|
+
}
|
|
1567
|
+
function createStorageTestScenario(storageType = "local") {
|
|
1568
|
+
if (storageType === "indexed") {
|
|
1569
|
+
const dbName = `test-db-${Math.random().toString(36).substring(7)}`;
|
|
1570
|
+
const storeName = "test-store";
|
|
1571
|
+
const storage2 = createMockIndexedDB();
|
|
1572
|
+
return {
|
|
1573
|
+
storage: storage2,
|
|
1574
|
+
populate: async (data) => {
|
|
1575
|
+
return new Promise((resolve, reject) => {
|
|
1576
|
+
const req = storage2.open(dbName, 1);
|
|
1577
|
+
req.onupgradeneeded = (e) => {
|
|
1578
|
+
const db = e.target.result;
|
|
1579
|
+
db.createObjectStore(storeName);
|
|
1580
|
+
};
|
|
1581
|
+
req.onsuccess = (e) => {
|
|
1582
|
+
const db = e.target.result;
|
|
1583
|
+
const tx = db.transaction(storeName, "readwrite");
|
|
1584
|
+
const store = tx.objectStore(storeName);
|
|
1585
|
+
Object.entries(data).forEach(([k, v]) => store.put(v, k));
|
|
1586
|
+
tx.oncomplete = () => {
|
|
1587
|
+
db.close();
|
|
1588
|
+
resolve();
|
|
1589
|
+
};
|
|
1590
|
+
tx.onerror = () => reject(tx.error);
|
|
1591
|
+
};
|
|
1592
|
+
req.onerror = () => reject(req.error);
|
|
1593
|
+
});
|
|
1594
|
+
},
|
|
1595
|
+
verify: async (key, value) => {
|
|
1596
|
+
return new Promise((resolve, reject) => {
|
|
1597
|
+
const req = storage2.open(dbName, 1);
|
|
1598
|
+
req.onsuccess = (e) => {
|
|
1599
|
+
const db = e.target.result;
|
|
1600
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
1601
|
+
db.close();
|
|
1602
|
+
resolve(false);
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
const tx = db.transaction(storeName, "readonly");
|
|
1606
|
+
const store = tx.objectStore(storeName);
|
|
1607
|
+
const getReq = store.get(key);
|
|
1608
|
+
getReq.onsuccess = () => {
|
|
1609
|
+
const result = getReq.result === value;
|
|
1610
|
+
db.close();
|
|
1611
|
+
resolve(result);
|
|
1612
|
+
};
|
|
1613
|
+
getReq.onerror = () => {
|
|
1614
|
+
db.close();
|
|
1615
|
+
resolve(false);
|
|
1616
|
+
};
|
|
1617
|
+
};
|
|
1618
|
+
req.onerror = () => reject(req.error);
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
const storage = storageType === "local" ? createMockLocalStorage() : createMockSessionStorage();
|
|
1624
|
+
return {
|
|
1625
|
+
storage,
|
|
1626
|
+
populate(data) {
|
|
1627
|
+
Object.entries(data).forEach(([k, v]) => storage.setItem(k, v));
|
|
1628
|
+
},
|
|
1629
|
+
verify(key, value) {
|
|
1630
|
+
return storage.getItem(key) === value;
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// src/setup/audio.ts
|
|
1636
|
+
function createMockAudioContext() {
|
|
1637
|
+
const context = {
|
|
1638
|
+
createGain: () => ({
|
|
1639
|
+
connect: () => {
|
|
1640
|
+
},
|
|
1641
|
+
gain: { value: 1, setValueAtTime: () => {
|
|
1642
|
+
} }
|
|
1643
|
+
}),
|
|
1644
|
+
createOscillator: () => ({
|
|
1645
|
+
connect: () => {
|
|
1646
|
+
},
|
|
1647
|
+
start: () => {
|
|
1648
|
+
},
|
|
1649
|
+
stop: () => {
|
|
1650
|
+
},
|
|
1651
|
+
frequency: { value: 440 }
|
|
1652
|
+
}),
|
|
1653
|
+
createBufferSource: () => ({
|
|
1654
|
+
connect: () => {
|
|
1655
|
+
},
|
|
1656
|
+
start: () => {
|
|
1657
|
+
},
|
|
1658
|
+
stop: () => {
|
|
1659
|
+
},
|
|
1660
|
+
buffer: null,
|
|
1661
|
+
playbackRate: { value: 1 },
|
|
1662
|
+
loop: false
|
|
1663
|
+
}),
|
|
1664
|
+
destination: {},
|
|
1665
|
+
currentTime: 0,
|
|
1666
|
+
state: "running",
|
|
1667
|
+
resume: async () => {
|
|
1668
|
+
},
|
|
1669
|
+
suspend: async () => {
|
|
1670
|
+
},
|
|
1671
|
+
close: async () => {
|
|
1672
|
+
},
|
|
1673
|
+
decodeAudioData: async (buffer) => ({
|
|
1674
|
+
duration: 1,
|
|
1675
|
+
length: 44100,
|
|
1676
|
+
sampleRate: 44100,
|
|
1677
|
+
numberOfChannels: 2,
|
|
1678
|
+
getChannelData: () => new Float32Array(44100)
|
|
1679
|
+
}),
|
|
1680
|
+
createBuffer: (channels, length, sampleRate) => ({
|
|
1681
|
+
duration: length / sampleRate,
|
|
1682
|
+
length,
|
|
1683
|
+
sampleRate,
|
|
1684
|
+
numberOfChannels: channels,
|
|
1685
|
+
getChannelData: () => new Float32Array(length)
|
|
1686
|
+
}),
|
|
1687
|
+
// Helper to track events if needed
|
|
1688
|
+
_events: []
|
|
1689
|
+
};
|
|
1690
|
+
return new Proxy(context, {
|
|
1691
|
+
get(target, prop, receiver) {
|
|
1692
|
+
if (prop === "_events") return target._events;
|
|
1693
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1694
|
+
if (typeof value === "function") {
|
|
1695
|
+
return (...args) => {
|
|
1696
|
+
target._events.push({ type: String(prop), args });
|
|
1697
|
+
return Reflect.apply(value, target, args);
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
return value;
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
function setupMockAudioContext() {
|
|
1705
|
+
if (typeof global.AudioContext === "undefined" && typeof global.window !== "undefined") {
|
|
1706
|
+
global.AudioContext = class {
|
|
1707
|
+
constructor() {
|
|
1708
|
+
return createMockAudioContext();
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
global.window.AudioContext = global.AudioContext;
|
|
1712
|
+
global.window.webkitAudioContext = global.AudioContext;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
function teardownMockAudioContext() {
|
|
1716
|
+
if (global.AudioContext && global.AudioContext.toString().includes("class")) {
|
|
1717
|
+
delete global.AudioContext;
|
|
1718
|
+
delete global.window.AudioContext;
|
|
1719
|
+
delete global.window.webkitAudioContext;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
function captureAudioEvents(context) {
|
|
1723
|
+
return context._events || [];
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1663
1726
|
// src/e2e/playwright.ts
|
|
1664
1727
|
import { chromium } from "playwright";
|
|
1665
1728
|
import { createServer } from "http";
|
|
@@ -1898,6 +1961,9 @@ export {
|
|
|
1898
1961
|
createMockCanvasContext2D,
|
|
1899
1962
|
createMockConnection,
|
|
1900
1963
|
createMockEngine,
|
|
1964
|
+
createMockGPUAdapter,
|
|
1965
|
+
createMockGPUCanvasContext,
|
|
1966
|
+
createMockGPUDevice,
|
|
1901
1967
|
createMockGame,
|
|
1902
1968
|
createMockGameState,
|
|
1903
1969
|
createMockHandshake,
|
|
@@ -1939,6 +2005,7 @@ export {
|
|
|
1939
2005
|
setupBrowserEnvironment,
|
|
1940
2006
|
setupMockAudioContext,
|
|
1941
2007
|
setupNodeEnvironment,
|
|
2008
|
+
setupWebGPUMocks,
|
|
1942
2009
|
simulateFrames,
|
|
1943
2010
|
simulateFramesWithMock,
|
|
1944
2011
|
simulateHandshake,
|