@quake2ts/test-utils 0.0.873 → 0.0.875
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 +165 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +159 -15
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/engine/helpers/webgl-playwright.ts +56 -6
- package/src/index.ts +1 -1
- package/src/setup/headless-webgl.ts +3 -2
- package/src/shared/md2.ts +143 -0
package/dist/index.cjs
CHANGED
|
@@ -229,6 +229,7 @@ __export(index_exports, {
|
|
|
229
229
|
createRenderTestSetup: () => createRenderTestSetup,
|
|
230
230
|
createSaveGameSnapshot: () => createSaveGameSnapshot,
|
|
231
231
|
createServerSnapshot: () => createServerSnapshot,
|
|
232
|
+
createSimpleMd2Model: () => createSimpleMd2Model,
|
|
232
233
|
createSolidTexture: () => createSolidTexture,
|
|
233
234
|
createSpawnRegistry: () => createSpawnRegistry,
|
|
234
235
|
createSpawnTestContext: () => createSpawnTestContext,
|
|
@@ -258,6 +259,7 @@ __export(index_exports, {
|
|
|
258
259
|
intersects: () => import_shared3.intersects,
|
|
259
260
|
ladderTrace: () => import_shared3.ladderTrace,
|
|
260
261
|
loadMapFromPak: () => loadMapFromPak,
|
|
262
|
+
loadMd2Model: () => loadMd2Model,
|
|
261
263
|
loadPNG: () => loadPNG,
|
|
262
264
|
makeAxisBrush: () => makeAxisBrush,
|
|
263
265
|
makeBrushFromMinsMaxs: () => makeBrushFromMinsMaxs,
|
|
@@ -324,6 +326,10 @@ __export(index_exports, {
|
|
|
324
326
|
});
|
|
325
327
|
module.exports = __toCommonJS(index_exports);
|
|
326
328
|
|
|
329
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
330
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
331
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
332
|
+
|
|
327
333
|
// src/shared/mocks.ts
|
|
328
334
|
var import_vitest2 = require("vitest");
|
|
329
335
|
|
|
@@ -784,6 +790,127 @@ function createMockPlayerState(overrides) {
|
|
|
784
790
|
};
|
|
785
791
|
}
|
|
786
792
|
|
|
793
|
+
// src/shared/md2.ts
|
|
794
|
+
function createSimpleMd2Model() {
|
|
795
|
+
const scale = { x: 1, y: 1, z: 1 };
|
|
796
|
+
const translate = { x: 0, y: 0, z: 0 };
|
|
797
|
+
const basePositions = [
|
|
798
|
+
{ x: -10, y: -10, z: -10 },
|
|
799
|
+
// 0
|
|
800
|
+
{ x: 10, y: -10, z: -10 },
|
|
801
|
+
// 1
|
|
802
|
+
{ x: 10, y: 10, z: -10 },
|
|
803
|
+
// 2
|
|
804
|
+
{ x: -10, y: 10, z: -10 },
|
|
805
|
+
// 3
|
|
806
|
+
{ x: -10, y: -10, z: 10 },
|
|
807
|
+
// 4
|
|
808
|
+
{ x: 10, y: -10, z: 10 },
|
|
809
|
+
// 5
|
|
810
|
+
{ x: 10, y: 10, z: 10 },
|
|
811
|
+
// 6
|
|
812
|
+
{ x: -10, y: 10, z: 10 }
|
|
813
|
+
// 7
|
|
814
|
+
];
|
|
815
|
+
const createFrame = (name, offset) => {
|
|
816
|
+
const vertices = basePositions.map((pos, index) => {
|
|
817
|
+
const modPos = {
|
|
818
|
+
x: pos.x + (index % 2 === 0 ? offset : -offset),
|
|
819
|
+
y: pos.y,
|
|
820
|
+
z: pos.z
|
|
821
|
+
};
|
|
822
|
+
return {
|
|
823
|
+
position: modPos,
|
|
824
|
+
normalIndex: 0,
|
|
825
|
+
// Dummy normal index
|
|
826
|
+
normal: { x: 0, y: 0, z: 1 }
|
|
827
|
+
// Dummy normal
|
|
828
|
+
};
|
|
829
|
+
});
|
|
830
|
+
return {
|
|
831
|
+
name,
|
|
832
|
+
vertices,
|
|
833
|
+
minBounds: { x: -20, y: -20, z: -20 },
|
|
834
|
+
maxBounds: { x: 20, y: 20, z: 20 }
|
|
835
|
+
};
|
|
836
|
+
};
|
|
837
|
+
const frames = [];
|
|
838
|
+
for (let i = 0; i < 20; i++) {
|
|
839
|
+
frames.push(createFrame(`frame${i}`, i * 0.5));
|
|
840
|
+
}
|
|
841
|
+
const triangles = [
|
|
842
|
+
// Front
|
|
843
|
+
{ vertexIndices: [0, 1, 2], texCoordIndices: [0, 1, 2] },
|
|
844
|
+
{ vertexIndices: [0, 2, 3], texCoordIndices: [0, 2, 3] },
|
|
845
|
+
// Back
|
|
846
|
+
{ vertexIndices: [5, 4, 7], texCoordIndices: [1, 0, 3] },
|
|
847
|
+
{ vertexIndices: [5, 7, 6], texCoordIndices: [1, 3, 2] },
|
|
848
|
+
// Top
|
|
849
|
+
{ vertexIndices: [3, 2, 6], texCoordIndices: [0, 1, 2] },
|
|
850
|
+
{ vertexIndices: [3, 6, 7], texCoordIndices: [0, 2, 3] },
|
|
851
|
+
// Bottom
|
|
852
|
+
{ vertexIndices: [4, 5, 1], texCoordIndices: [0, 1, 2] },
|
|
853
|
+
{ vertexIndices: [4, 1, 0], texCoordIndices: [0, 2, 3] },
|
|
854
|
+
// Right
|
|
855
|
+
{ vertexIndices: [1, 5, 6], texCoordIndices: [0, 1, 2] },
|
|
856
|
+
{ vertexIndices: [1, 6, 2], texCoordIndices: [0, 2, 3] },
|
|
857
|
+
// Left
|
|
858
|
+
{ vertexIndices: [4, 0, 3], texCoordIndices: [0, 1, 2] },
|
|
859
|
+
{ vertexIndices: [4, 3, 7], texCoordIndices: [0, 2, 3] }
|
|
860
|
+
];
|
|
861
|
+
const glCommands = triangles.map((t) => ({
|
|
862
|
+
mode: "strip",
|
|
863
|
+
// or 'fan', doesn't matter for 3 verts
|
|
864
|
+
vertices: [
|
|
865
|
+
{ s: 0, t: 0, vertexIndex: t.vertexIndices[0] },
|
|
866
|
+
{ s: 1, t: 0, vertexIndex: t.vertexIndices[1] },
|
|
867
|
+
{ s: 1, t: 1, vertexIndex: t.vertexIndices[2] }
|
|
868
|
+
]
|
|
869
|
+
}));
|
|
870
|
+
const header = {
|
|
871
|
+
ident: 844121161,
|
|
872
|
+
version: 8,
|
|
873
|
+
skinWidth: 32,
|
|
874
|
+
skinHeight: 32,
|
|
875
|
+
frameSize: 40 + 8 * 4,
|
|
876
|
+
// header + verts * 4
|
|
877
|
+
numSkins: 1,
|
|
878
|
+
numVertices: 8,
|
|
879
|
+
numTexCoords: 4,
|
|
880
|
+
// Simplified
|
|
881
|
+
numTriangles: 12,
|
|
882
|
+
numGlCommands: 12,
|
|
883
|
+
// One per triangle for simplicity
|
|
884
|
+
numFrames: 20,
|
|
885
|
+
offsetSkins: 0,
|
|
886
|
+
offsetTexCoords: 0,
|
|
887
|
+
offsetTriangles: 0,
|
|
888
|
+
offsetFrames: 0,
|
|
889
|
+
offsetGlCommands: 0,
|
|
890
|
+
offsetEnd: 0,
|
|
891
|
+
magic: 844121161
|
|
892
|
+
};
|
|
893
|
+
return {
|
|
894
|
+
header,
|
|
895
|
+
skins: [{ name: "skin.pcx" }],
|
|
896
|
+
texCoords: [
|
|
897
|
+
{ s: 0, t: 0 },
|
|
898
|
+
{ s: 32, t: 0 },
|
|
899
|
+
{ s: 32, t: 32 },
|
|
900
|
+
{ s: 0, t: 32 }
|
|
901
|
+
],
|
|
902
|
+
triangles,
|
|
903
|
+
frames,
|
|
904
|
+
glCommands
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
async function loadMd2Model(filename) {
|
|
908
|
+
if (filename === "simple-cube.md2") {
|
|
909
|
+
return createSimpleMd2Model();
|
|
910
|
+
}
|
|
911
|
+
throw new Error(`Model ${filename} not found in test fixtures`);
|
|
912
|
+
}
|
|
913
|
+
|
|
787
914
|
// src/game/factories.ts
|
|
788
915
|
var import_game = require("@quake2ts/game");
|
|
789
916
|
var createPlayerStateFactory = (overrides) => ({
|
|
@@ -3304,14 +3431,16 @@ function createWebGPULifecycle() {
|
|
|
3304
3431
|
}
|
|
3305
3432
|
|
|
3306
3433
|
// src/setup/headless-webgl.ts
|
|
3434
|
+
var import_module = require("module");
|
|
3307
3435
|
function createHeadlessWebGL(options = {}) {
|
|
3308
3436
|
const width = options.width ?? 256;
|
|
3309
3437
|
const height = options.height ?? 256;
|
|
3310
3438
|
let createGL;
|
|
3311
3439
|
try {
|
|
3312
|
-
|
|
3440
|
+
const require2 = (0, import_module.createRequire)(importMetaUrl);
|
|
3441
|
+
createGL = require2("gl");
|
|
3313
3442
|
} catch (e) {
|
|
3314
|
-
throw new Error("gl package not found or failed to load. Install it to run WebGL tests.");
|
|
3443
|
+
throw new Error("gl package not found or failed to load. Install it to run WebGL tests. Error: " + e);
|
|
3315
3444
|
}
|
|
3316
3445
|
const glContext = createGL(width, height, {
|
|
3317
3446
|
antialias: options.antialias ?? false,
|
|
@@ -4963,6 +5092,7 @@ async function expectAnimationSnapshot(renderAndCaptureFrame, options) {
|
|
|
4963
5092
|
var import_http = require("http");
|
|
4964
5093
|
var import_path3 = __toESM(require("path"), 1);
|
|
4965
5094
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
5095
|
+
var sharedSetup;
|
|
4966
5096
|
function findWorkspaceRoot(startDir) {
|
|
4967
5097
|
let currentDir = startDir;
|
|
4968
5098
|
while (currentDir !== import_path3.default.parse(currentDir).root) {
|
|
@@ -4977,6 +5107,25 @@ async function createWebGLPlaywrightSetup(options = {}) {
|
|
|
4977
5107
|
const width = options.width ?? 256;
|
|
4978
5108
|
const height = options.height ?? 256;
|
|
4979
5109
|
const headless = options.headless ?? true;
|
|
5110
|
+
if (sharedSetup) {
|
|
5111
|
+
const { page: page2, browser: browser2, context: context2, server } = sharedSetup;
|
|
5112
|
+
if (!page2.isClosed()) {
|
|
5113
|
+
await page2.setViewportSize({ width, height });
|
|
5114
|
+
return {
|
|
5115
|
+
browser: browser2,
|
|
5116
|
+
context: context2,
|
|
5117
|
+
page: page2,
|
|
5118
|
+
width,
|
|
5119
|
+
height,
|
|
5120
|
+
server,
|
|
5121
|
+
// No-op cleanup for shared instance to keep it alive for next test
|
|
5122
|
+
cleanup: async () => {
|
|
5123
|
+
}
|
|
5124
|
+
};
|
|
5125
|
+
} else {
|
|
5126
|
+
sharedSetup = void 0;
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
4980
5129
|
let chromium;
|
|
4981
5130
|
let handler;
|
|
4982
5131
|
try {
|
|
@@ -5033,7 +5182,6 @@ async function createWebGLPlaywrightSetup(options = {}) {
|
|
|
5033
5182
|
const page = await context.newPage();
|
|
5034
5183
|
page.on("console", (msg) => {
|
|
5035
5184
|
if (msg.type() === "error") console.error(`[Browser Error] ${msg.text()}`);
|
|
5036
|
-
else console.log(`[Browser] ${msg.text()}`);
|
|
5037
5185
|
});
|
|
5038
5186
|
page.on("pageerror", (err) => {
|
|
5039
5187
|
console.error(`[Browser Page Error] ${err.message}`);
|
|
@@ -5041,9 +5189,14 @@ async function createWebGLPlaywrightSetup(options = {}) {
|
|
|
5041
5189
|
await page.goto(serverUrl, { waitUntil: "domcontentloaded" });
|
|
5042
5190
|
await page.evaluate(`window.createRendererTest()`);
|
|
5043
5191
|
await page.waitForFunction(() => window.testRenderer !== void 0, { timeout: 5e3 });
|
|
5192
|
+
sharedSetup = {
|
|
5193
|
+
browser,
|
|
5194
|
+
context,
|
|
5195
|
+
page,
|
|
5196
|
+
server: staticServer,
|
|
5197
|
+
serverUrl
|
|
5198
|
+
};
|
|
5044
5199
|
const cleanup = async () => {
|
|
5045
|
-
await browser.close();
|
|
5046
|
-
staticServer.close();
|
|
5047
5200
|
};
|
|
5048
5201
|
return {
|
|
5049
5202
|
browser,
|
|
@@ -5065,9 +5218,11 @@ async function renderAndCaptureWebGLPlaywright(page, renderFn, width, height, fr
|
|
|
5065
5218
|
throw new Error("Renderer not initialized");
|
|
5066
5219
|
}
|
|
5067
5220
|
if (width2 !== void 0 && height2 !== void 0) {
|
|
5068
|
-
canvas.width
|
|
5069
|
-
|
|
5070
|
-
|
|
5221
|
+
if (canvas.width !== width2 || canvas.height !== height2) {
|
|
5222
|
+
canvas.width = width2;
|
|
5223
|
+
canvas.height = height2;
|
|
5224
|
+
gl.viewport(0, 0, width2, height2);
|
|
5225
|
+
}
|
|
5071
5226
|
}
|
|
5072
5227
|
try {
|
|
5073
5228
|
const fn = new Function("renderer", "gl", "frameIndex", code);
|
|
@@ -6793,6 +6948,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
6793
6948
|
createRenderTestSetup,
|
|
6794
6949
|
createSaveGameSnapshot,
|
|
6795
6950
|
createServerSnapshot,
|
|
6951
|
+
createSimpleMd2Model,
|
|
6796
6952
|
createSolidTexture,
|
|
6797
6953
|
createSpawnRegistry,
|
|
6798
6954
|
createSpawnTestContext,
|
|
@@ -6822,6 +6978,7 @@ function createVisualTestScenario(sceneName) {
|
|
|
6822
6978
|
intersects,
|
|
6823
6979
|
ladderTrace,
|
|
6824
6980
|
loadMapFromPak,
|
|
6981
|
+
loadMd2Model,
|
|
6825
6982
|
loadPNG,
|
|
6826
6983
|
makeAxisBrush,
|
|
6827
6984
|
makeBrushFromMinsMaxs,
|