@quake2ts/test-utils 0.0.875 → 0.0.877
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/dist/index.cjs +3 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -83
- package/dist/index.d.ts +2 -83
- package/dist/index.js +2 -158
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +6 -6
- package/src/e2e/network.ts +0 -47
- package/src/e2e/playwright.ts +0 -90
- package/src/e2e/visual.ts +0 -105
package/dist/index.cjs
CHANGED
|
@@ -65,12 +65,9 @@ __export(index_exports, {
|
|
|
65
65
|
captureAudioEvents: () => captureAudioEvents,
|
|
66
66
|
captureCanvasDrawCalls: () => captureCanvasDrawCalls,
|
|
67
67
|
captureFramebufferAsPNG: () => captureFramebufferAsPNG,
|
|
68
|
-
captureGameScreenshot: () => captureGameScreenshot,
|
|
69
|
-
captureGameState: () => captureGameState,
|
|
70
68
|
captureTexture: () => captureTexture,
|
|
71
69
|
captureWebGLFramebuffer: () => captureWebGLFramebuffer,
|
|
72
70
|
compareSaveGames: () => compareSaveGames,
|
|
73
|
-
compareScreenshots: () => compareScreenshots,
|
|
74
71
|
compareSnapshots: () => compareSnapshots,
|
|
75
72
|
createBandwidthTestScenario: () => createBandwidthTestScenario,
|
|
76
73
|
createBinaryStreamMock: () => createBinaryStreamMock,
|
|
@@ -82,7 +79,6 @@ __export(index_exports, {
|
|
|
82
79
|
createConfigStringArrayMock: () => createConfigStringArrayMock,
|
|
83
80
|
createConfigStringMock: () => createConfigStringMock,
|
|
84
81
|
createControlledTimer: () => createControlledTimer,
|
|
85
|
-
createCustomNetworkCondition: () => createCustomNetworkCondition,
|
|
86
82
|
createCvarMock: () => createCvarMock,
|
|
87
83
|
createDeltaSnapshot: () => createDeltaSnapshot,
|
|
88
84
|
createEntity: () => createEntity,
|
|
@@ -221,7 +217,6 @@ __export(index_exports, {
|
|
|
221
217
|
createPhysicsTestScenario: () => createPhysicsTestScenario,
|
|
222
218
|
createPlayerEntityFactory: () => createPlayerEntityFactory,
|
|
223
219
|
createPlayerStateFactory: () => createPlayerStateFactory,
|
|
224
|
-
createPlaywrightTestClient: () => createPlaywrightTestClient,
|
|
225
220
|
createPowerArmorState: () => createPowerArmorState,
|
|
226
221
|
createPredictionTestScenario: () => createPredictionTestScenario,
|
|
227
222
|
createProjectileEntityFactory: () => createProjectileEntityFactory,
|
|
@@ -243,7 +238,6 @@ __export(index_exports, {
|
|
|
243
238
|
createTriggerEntityFactory: () => createTriggerEntityFactory,
|
|
244
239
|
createVector3: () => createVector3,
|
|
245
240
|
createViewTestScenario: () => createViewTestScenario,
|
|
246
|
-
createVisualTestScenario: () => createVisualTestScenario,
|
|
247
241
|
createWebGLPlaywrightSetup: () => createWebGLPlaywrightSetup,
|
|
248
242
|
createWebGLRenderTestSetup: () => createWebGLRenderTestSetup,
|
|
249
243
|
createWebGPULifecycle: () => createWebGPULifecycle,
|
|
@@ -296,7 +290,6 @@ __export(index_exports, {
|
|
|
296
290
|
simulateHandshake: () => simulateHandshake,
|
|
297
291
|
simulateJump: () => simulateJump,
|
|
298
292
|
simulateMovement: () => simulateMovement,
|
|
299
|
-
simulateNetworkCondition: () => simulateNetworkCondition,
|
|
300
293
|
simulateNetworkDelay: () => simulateNetworkDelay,
|
|
301
294
|
simulatePacketLoss: () => simulatePacketLoss,
|
|
302
295
|
simulatePlayerInput: () => simulatePlayerInput,
|
|
@@ -309,7 +302,6 @@ __export(index_exports, {
|
|
|
309
302
|
spawnEntity: () => spawnEntity,
|
|
310
303
|
spawnTestEntity: () => spawnTestEntity,
|
|
311
304
|
stairTrace: () => import_shared3.stairTrace,
|
|
312
|
-
takeScreenshot: () => takeScreenshot,
|
|
313
305
|
teardownBrowserEnvironment: () => teardownBrowserEnvironment,
|
|
314
306
|
teardownMockAudioContext: () => teardownMockAudioContext,
|
|
315
307
|
teardownNodeEnvironment: () => teardownNodeEnvironment,
|
|
@@ -319,10 +311,8 @@ __export(index_exports, {
|
|
|
319
311
|
testWebGLAnimation: () => testWebGLAnimation,
|
|
320
312
|
testWebGLRenderer: () => testWebGLRenderer,
|
|
321
313
|
textData: () => textData,
|
|
322
|
-
throttleBandwidth: () => throttleBandwidth,
|
|
323
314
|
verifySmoothing: () => verifySmoothing,
|
|
324
|
-
verifySnapshotConsistency: () => verifySnapshotConsistency
|
|
325
|
-
waitForGameReady: () => waitForGameReady
|
|
315
|
+
verifySnapshotConsistency: () => verifySnapshotConsistency
|
|
326
316
|
});
|
|
327
317
|
module.exports = __toCommonJS(index_exports);
|
|
328
318
|
|
|
@@ -4135,7 +4125,7 @@ function createMockAssetManager(overrides) {
|
|
|
4135
4125
|
getMemoryUsage: import_vitest13.vi.fn().mockReturnValue({ textures: 0, audio: 0 }),
|
|
4136
4126
|
clearCache: import_vitest13.vi.fn(),
|
|
4137
4127
|
preloadAssets: import_vitest13.vi.fn().mockResolvedValue(void 0),
|
|
4138
|
-
queueLoad: import_vitest13.vi.fn().mockImplementation((
|
|
4128
|
+
queueLoad: import_vitest13.vi.fn().mockImplementation((path6) => Promise.resolve({})),
|
|
4139
4129
|
...overrides
|
|
4140
4130
|
};
|
|
4141
4131
|
}
|
|
@@ -6601,152 +6591,6 @@ var test = import_vitest23.test.extend({
|
|
|
6601
6591
|
}
|
|
6602
6592
|
}
|
|
6603
6593
|
});
|
|
6604
|
-
|
|
6605
|
-
// src/e2e/playwright.ts
|
|
6606
|
-
async function createPlaywrightTestClient(options = {}) {
|
|
6607
|
-
let playwright;
|
|
6608
|
-
try {
|
|
6609
|
-
playwright = await import("playwright");
|
|
6610
|
-
} catch (e) {
|
|
6611
|
-
throw new Error("Playwright is not installed. Please install it to use this utility.");
|
|
6612
|
-
}
|
|
6613
|
-
const browser = await playwright.chromium.launch({
|
|
6614
|
-
headless: options.headless ?? true
|
|
6615
|
-
});
|
|
6616
|
-
const context = await browser.newContext({
|
|
6617
|
-
viewport: options.viewport || { width: 1280, height: 720 }
|
|
6618
|
-
});
|
|
6619
|
-
const page = await context.newPage();
|
|
6620
|
-
return {
|
|
6621
|
-
page,
|
|
6622
|
-
browser,
|
|
6623
|
-
async navigate(url) {
|
|
6624
|
-
await page.goto(url);
|
|
6625
|
-
},
|
|
6626
|
-
async waitForGame() {
|
|
6627
|
-
await waitForGameReady(page);
|
|
6628
|
-
},
|
|
6629
|
-
async injectInput(type, data) {
|
|
6630
|
-
await page.evaluate(({ type: type2, data: data2 }) => {
|
|
6631
|
-
console.log("Injecting input", type2, data2);
|
|
6632
|
-
}, { type, data });
|
|
6633
|
-
},
|
|
6634
|
-
async screenshot(name) {
|
|
6635
|
-
return await page.screenshot({ path: `${name}.png` });
|
|
6636
|
-
},
|
|
6637
|
-
async close() {
|
|
6638
|
-
await browser.close();
|
|
6639
|
-
}
|
|
6640
|
-
};
|
|
6641
|
-
}
|
|
6642
|
-
async function waitForGameReady(page, timeout = 1e4) {
|
|
6643
|
-
await page.waitForFunction(() => {
|
|
6644
|
-
return window.game && window.game.isRunning;
|
|
6645
|
-
}, { timeout });
|
|
6646
|
-
}
|
|
6647
|
-
async function captureGameState(page) {
|
|
6648
|
-
return await page.evaluate(() => {
|
|
6649
|
-
const game = window.game;
|
|
6650
|
-
return {
|
|
6651
|
-
time: game ? game.time : 0,
|
|
6652
|
-
entities: game && game.entities ? game.entities.length : 0
|
|
6653
|
-
};
|
|
6654
|
-
});
|
|
6655
|
-
}
|
|
6656
|
-
|
|
6657
|
-
// src/e2e/network.ts
|
|
6658
|
-
function simulateNetworkCondition(condition) {
|
|
6659
|
-
switch (condition) {
|
|
6660
|
-
case "good":
|
|
6661
|
-
return { latency: 20, jitter: 5, packetLoss: 0, bandwidth: 10 * 1024 * 1024 };
|
|
6662
|
-
case "slow":
|
|
6663
|
-
return { latency: 150, jitter: 20, packetLoss: 0.01, bandwidth: 1 * 1024 * 1024 };
|
|
6664
|
-
case "unstable":
|
|
6665
|
-
return { latency: 100, jitter: 100, packetLoss: 0.05, bandwidth: 512 * 1024 };
|
|
6666
|
-
case "offline":
|
|
6667
|
-
return { latency: 0, jitter: 0, packetLoss: 1, bandwidth: 0 };
|
|
6668
|
-
case "custom":
|
|
6669
|
-
default:
|
|
6670
|
-
return { latency: 0, jitter: 0, packetLoss: 0, bandwidth: Infinity };
|
|
6671
|
-
}
|
|
6672
|
-
}
|
|
6673
|
-
function createCustomNetworkCondition(latency, jitter, packetLoss) {
|
|
6674
|
-
return {
|
|
6675
|
-
latency,
|
|
6676
|
-
jitter,
|
|
6677
|
-
packetLoss,
|
|
6678
|
-
bandwidth: Infinity
|
|
6679
|
-
// Default to unlimited unless specified
|
|
6680
|
-
};
|
|
6681
|
-
}
|
|
6682
|
-
function throttleBandwidth(bytesPerSecond) {
|
|
6683
|
-
}
|
|
6684
|
-
|
|
6685
|
-
// src/e2e/visual.ts
|
|
6686
|
-
var import_pngjs2 = require("pngjs");
|
|
6687
|
-
var import_pixelmatch2 = __toESM(require("pixelmatch"), 1);
|
|
6688
|
-
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
6689
|
-
var import_path5 = __toESM(require("path"), 1);
|
|
6690
|
-
async function captureGameScreenshot(page, name) {
|
|
6691
|
-
const canvasElement = page.locator("canvas");
|
|
6692
|
-
if (await canvasElement.count() > 0) {
|
|
6693
|
-
return await canvasElement.screenshot({ path: `${name}.png` });
|
|
6694
|
-
}
|
|
6695
|
-
return await page.screenshot({ path: `${name}.png` });
|
|
6696
|
-
}
|
|
6697
|
-
async function takeScreenshot(canvas, filepath) {
|
|
6698
|
-
let buffer;
|
|
6699
|
-
if ("toBuffer" in canvas && typeof canvas.toBuffer === "function") {
|
|
6700
|
-
buffer = canvas.toBuffer("image/png");
|
|
6701
|
-
} else if ("toDataURL" in canvas) {
|
|
6702
|
-
const dataUrl = canvas.toDataURL("image/png");
|
|
6703
|
-
const base64 = dataUrl.replace(/^data:image\/png;base64,/, "");
|
|
6704
|
-
buffer = Buffer.from(base64, "base64");
|
|
6705
|
-
} else {
|
|
6706
|
-
throw new Error("Unsupported canvas type for screenshot");
|
|
6707
|
-
}
|
|
6708
|
-
await import_promises3.default.mkdir(import_path5.default.dirname(filepath), { recursive: true });
|
|
6709
|
-
await import_promises3.default.writeFile(filepath, buffer);
|
|
6710
|
-
}
|
|
6711
|
-
function compareScreenshots(baseline, current, threshold = 0.01) {
|
|
6712
|
-
try {
|
|
6713
|
-
const img1 = import_pngjs2.PNG.sync.read(baseline);
|
|
6714
|
-
const img2 = import_pngjs2.PNG.sync.read(current);
|
|
6715
|
-
if (img1.width !== img2.width || img1.height !== img2.height) {
|
|
6716
|
-
throw new Error(`Image dimensions do not match: ${img1.width}x${img1.height} vs ${img2.width}x${img2.height}`);
|
|
6717
|
-
}
|
|
6718
|
-
const { width, height } = img1;
|
|
6719
|
-
const diff = new import_pngjs2.PNG({ width, height });
|
|
6720
|
-
const diffPixels = (0, import_pixelmatch2.default)(
|
|
6721
|
-
img1.data,
|
|
6722
|
-
img2.data,
|
|
6723
|
-
diff.data,
|
|
6724
|
-
width,
|
|
6725
|
-
height,
|
|
6726
|
-
{ threshold }
|
|
6727
|
-
);
|
|
6728
|
-
const diffPercentage = diffPixels / (width * height);
|
|
6729
|
-
const isMatch = diffPixels === 0;
|
|
6730
|
-
return {
|
|
6731
|
-
diffPixels,
|
|
6732
|
-
diffPercentage,
|
|
6733
|
-
isMatch,
|
|
6734
|
-
diffImage: import_pngjs2.PNG.sync.write(diff)
|
|
6735
|
-
};
|
|
6736
|
-
} catch (error) {
|
|
6737
|
-
console.error("Error comparing screenshots:", error);
|
|
6738
|
-
return {
|
|
6739
|
-
diffPixels: -1,
|
|
6740
|
-
diffPercentage: 1,
|
|
6741
|
-
isMatch: false
|
|
6742
|
-
};
|
|
6743
|
-
}
|
|
6744
|
-
}
|
|
6745
|
-
function createVisualTestScenario(sceneName) {
|
|
6746
|
-
return {
|
|
6747
|
-
sceneName
|
|
6748
|
-
};
|
|
6749
|
-
}
|
|
6750
6594
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6751
6595
|
0 && (module.exports = {
|
|
6752
6596
|
BrowserInputSource,
|
|
@@ -6784,12 +6628,9 @@ function createVisualTestScenario(sceneName) {
|
|
|
6784
6628
|
captureAudioEvents,
|
|
6785
6629
|
captureCanvasDrawCalls,
|
|
6786
6630
|
captureFramebufferAsPNG,
|
|
6787
|
-
captureGameScreenshot,
|
|
6788
|
-
captureGameState,
|
|
6789
6631
|
captureTexture,
|
|
6790
6632
|
captureWebGLFramebuffer,
|
|
6791
6633
|
compareSaveGames,
|
|
6792
|
-
compareScreenshots,
|
|
6793
6634
|
compareSnapshots,
|
|
6794
6635
|
createBandwidthTestScenario,
|
|
6795
6636
|
createBinaryStreamMock,
|
|
@@ -6801,7 +6642,6 @@ function createVisualTestScenario(sceneName) {
|
|
|
6801
6642
|
createConfigStringArrayMock,
|
|
6802
6643
|
createConfigStringMock,
|
|
6803
6644
|
createControlledTimer,
|
|
6804
|
-
createCustomNetworkCondition,
|
|
6805
6645
|
createCvarMock,
|
|
6806
6646
|
createDeltaSnapshot,
|
|
6807
6647
|
createEntity,
|
|
@@ -6940,7 +6780,6 @@ function createVisualTestScenario(sceneName) {
|
|
|
6940
6780
|
createPhysicsTestScenario,
|
|
6941
6781
|
createPlayerEntityFactory,
|
|
6942
6782
|
createPlayerStateFactory,
|
|
6943
|
-
createPlaywrightTestClient,
|
|
6944
6783
|
createPowerArmorState,
|
|
6945
6784
|
createPredictionTestScenario,
|
|
6946
6785
|
createProjectileEntityFactory,
|
|
@@ -6962,7 +6801,6 @@ function createVisualTestScenario(sceneName) {
|
|
|
6962
6801
|
createTriggerEntityFactory,
|
|
6963
6802
|
createVector3,
|
|
6964
6803
|
createViewTestScenario,
|
|
6965
|
-
createVisualTestScenario,
|
|
6966
6804
|
createWebGLPlaywrightSetup,
|
|
6967
6805
|
createWebGLRenderTestSetup,
|
|
6968
6806
|
createWebGPULifecycle,
|
|
@@ -7015,7 +6853,6 @@ function createVisualTestScenario(sceneName) {
|
|
|
7015
6853
|
simulateHandshake,
|
|
7016
6854
|
simulateJump,
|
|
7017
6855
|
simulateMovement,
|
|
7018
|
-
simulateNetworkCondition,
|
|
7019
6856
|
simulateNetworkDelay,
|
|
7020
6857
|
simulatePacketLoss,
|
|
7021
6858
|
simulatePlayerInput,
|
|
@@ -7028,7 +6865,6 @@ function createVisualTestScenario(sceneName) {
|
|
|
7028
6865
|
spawnEntity,
|
|
7029
6866
|
spawnTestEntity,
|
|
7030
6867
|
stairTrace,
|
|
7031
|
-
takeScreenshot,
|
|
7032
6868
|
teardownBrowserEnvironment,
|
|
7033
6869
|
teardownMockAudioContext,
|
|
7034
6870
|
teardownNodeEnvironment,
|
|
@@ -7038,9 +6874,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
7038
6874
|
testWebGLAnimation,
|
|
7039
6875
|
testWebGLRenderer,
|
|
7040
6876
|
textData,
|
|
7041
|
-
throttleBandwidth,
|
|
7042
6877
|
verifySmoothing,
|
|
7043
|
-
verifySnapshotConsistency
|
|
7044
|
-
waitForGameReady
|
|
6878
|
+
verifySnapshotConsistency
|
|
7045
6879
|
});
|
|
7046
6880
|
//# sourceMappingURL=index.cjs.map
|