@quake2ts/test-utils 0.0.762 → 0.0.765
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 +63 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -1
- package/package.json +21 -11
- package/src/index.ts +2 -0
- package/src/setup/headless-webgl.ts +106 -0
package/dist/index.cjs
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
captureGameScreenshot: () => captureGameScreenshot,
|
|
63
63
|
captureGameState: () => captureGameState,
|
|
64
64
|
captureTexture: () => captureTexture,
|
|
65
|
+
captureWebGLFramebuffer: () => captureWebGLFramebuffer,
|
|
65
66
|
compareSaveGames: () => compareSaveGames,
|
|
66
67
|
compareScreenshots: () => compareScreenshots,
|
|
67
68
|
compareSnapshots: () => compareSnapshots,
|
|
@@ -83,6 +84,7 @@ __export(index_exports, {
|
|
|
83
84
|
createGameImportsAndEngine: () => createGameImportsAndEngine,
|
|
84
85
|
createGameStateSnapshotFactory: () => createGameStateSnapshotFactory,
|
|
85
86
|
createHeadlessTestContext: () => createHeadlessTestContext,
|
|
87
|
+
createHeadlessWebGL: () => createHeadlessWebGL,
|
|
86
88
|
createInputInjector: () => createInputInjector,
|
|
87
89
|
createInterpolationTestData: () => createInterpolationTestData,
|
|
88
90
|
createItemEntityFactory: () => createItemEntityFactory,
|
|
@@ -227,6 +229,7 @@ __export(index_exports, {
|
|
|
227
229
|
createVisualTestScenario: () => createVisualTestScenario,
|
|
228
230
|
expectSnapshot: () => expectSnapshot,
|
|
229
231
|
findPakFile: () => findPakFile,
|
|
232
|
+
flipPixelsVertically: () => flipPixelsVertically,
|
|
230
233
|
getSnapshotPath: () => getSnapshotPath,
|
|
231
234
|
initHeadlessWebGPU: () => initHeadlessWebGPU,
|
|
232
235
|
intersects: () => import_shared3.intersects,
|
|
@@ -3003,6 +3006,63 @@ async function createHeadlessTestContext() {
|
|
|
3003
3006
|
};
|
|
3004
3007
|
}
|
|
3005
3008
|
|
|
3009
|
+
// src/setup/headless-webgl.ts
|
|
3010
|
+
var import_module = require("module");
|
|
3011
|
+
var import_meta = {};
|
|
3012
|
+
var require2 = (0, import_module.createRequire)(import_meta.url);
|
|
3013
|
+
var headlessGL;
|
|
3014
|
+
try {
|
|
3015
|
+
headlessGL = require2("gl");
|
|
3016
|
+
} catch (e) {
|
|
3017
|
+
console.warn('Failed to load "gl" package. Headless WebGL creation will fail.', e);
|
|
3018
|
+
}
|
|
3019
|
+
function createHeadlessWebGL(options = {}) {
|
|
3020
|
+
if (!headlessGL) {
|
|
3021
|
+
throw new Error("Headless GL package is not available or failed to load.");
|
|
3022
|
+
}
|
|
3023
|
+
const width = options.width ?? 256;
|
|
3024
|
+
const height = options.height ?? 256;
|
|
3025
|
+
const antialias = options.antialias ?? false;
|
|
3026
|
+
const preserveDrawingBuffer = options.preserveDrawingBuffer ?? true;
|
|
3027
|
+
const context = headlessGL(width, height, {
|
|
3028
|
+
antialias,
|
|
3029
|
+
preserveDrawingBuffer,
|
|
3030
|
+
stencil: true,
|
|
3031
|
+
depth: true,
|
|
3032
|
+
alpha: true
|
|
3033
|
+
});
|
|
3034
|
+
if (!context) {
|
|
3035
|
+
throw new Error("Failed to create headless WebGL context");
|
|
3036
|
+
}
|
|
3037
|
+
const gl2 = context;
|
|
3038
|
+
return {
|
|
3039
|
+
gl: gl2,
|
|
3040
|
+
width,
|
|
3041
|
+
height,
|
|
3042
|
+
cleanup: () => {
|
|
3043
|
+
const ext = context.getExtension("STACKGL_destroy_context");
|
|
3044
|
+
if (ext && typeof ext.destroy === "function") {
|
|
3045
|
+
ext.destroy();
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3050
|
+
function flipPixelsVertically(pixels, width, height) {
|
|
3051
|
+
const flipped = new Uint8ClampedArray(pixels.length);
|
|
3052
|
+
const rowSize = width * 4;
|
|
3053
|
+
for (let y = 0; y < height; y++) {
|
|
3054
|
+
const srcRowStart = y * rowSize;
|
|
3055
|
+
const dstRowStart = (height - 1 - y) * rowSize;
|
|
3056
|
+
flipped.set(pixels.subarray(srcRowStart, srcRowStart + rowSize), dstRowStart);
|
|
3057
|
+
}
|
|
3058
|
+
return flipped;
|
|
3059
|
+
}
|
|
3060
|
+
function captureWebGLFramebuffer(gl, width, height) {
|
|
3061
|
+
const pixels = new Uint8ClampedArray(width * height * 4);
|
|
3062
|
+
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
3063
|
+
return flipPixelsVertically(pixels, width, height);
|
|
3064
|
+
}
|
|
3065
|
+
|
|
3006
3066
|
// src/engine/mocks/webgpu.ts
|
|
3007
3067
|
var import_vitest11 = require("vitest");
|
|
3008
3068
|
var import_webgpu = require("webgpu");
|
|
@@ -5171,6 +5231,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
5171
5231
|
captureGameScreenshot,
|
|
5172
5232
|
captureGameState,
|
|
5173
5233
|
captureTexture,
|
|
5234
|
+
captureWebGLFramebuffer,
|
|
5174
5235
|
compareSaveGames,
|
|
5175
5236
|
compareScreenshots,
|
|
5176
5237
|
compareSnapshots,
|
|
@@ -5192,6 +5253,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
5192
5253
|
createGameImportsAndEngine,
|
|
5193
5254
|
createGameStateSnapshotFactory,
|
|
5194
5255
|
createHeadlessTestContext,
|
|
5256
|
+
createHeadlessWebGL,
|
|
5195
5257
|
createInputInjector,
|
|
5196
5258
|
createInterpolationTestData,
|
|
5197
5259
|
createItemEntityFactory,
|
|
@@ -5336,6 +5398,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
5336
5398
|
createVisualTestScenario,
|
|
5337
5399
|
expectSnapshot,
|
|
5338
5400
|
findPakFile,
|
|
5401
|
+
flipPixelsVertically,
|
|
5339
5402
|
getSnapshotPath,
|
|
5340
5403
|
initHeadlessWebGPU,
|
|
5341
5404
|
intersects,
|