@quake2ts/test-utils 0.0.799 → 0.0.804
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 +35 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +35 -14
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/engine/helpers/webgl-playwright.ts +49 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quake2ts/test-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.804",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"pngjs": "^7.0.0",
|
|
45
45
|
"vitest": "^1.6.0",
|
|
46
46
|
"webgpu": "^0.3.8",
|
|
47
|
-
"@quake2ts/engine": "^0.0.
|
|
48
|
-
"@quake2ts/game": "0.0.
|
|
49
|
-
"@quake2ts/server": "0.0.
|
|
50
|
-
"@quake2ts/shared": "0.0.
|
|
47
|
+
"@quake2ts/engine": "^0.0.804",
|
|
48
|
+
"@quake2ts/game": "0.0.804",
|
|
49
|
+
"@quake2ts/server": "0.0.804",
|
|
50
|
+
"@quake2ts/shared": "0.0.804"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"@quake2ts/engine": {
|
|
@@ -100,10 +100,10 @@
|
|
|
100
100
|
"vitest": "^4.0.16",
|
|
101
101
|
"serve-handler": "^6.1.6",
|
|
102
102
|
"webgpu": "^0.3.8",
|
|
103
|
-
"@quake2ts/
|
|
104
|
-
"@quake2ts/
|
|
105
|
-
"@quake2ts/server": "0.0.
|
|
106
|
-
"@quake2ts/shared": "0.0.
|
|
103
|
+
"@quake2ts/engine": "^0.0.804",
|
|
104
|
+
"@quake2ts/game": "0.0.804",
|
|
105
|
+
"@quake2ts/server": "0.0.804",
|
|
106
|
+
"@quake2ts/shared": "0.0.804"
|
|
107
107
|
},
|
|
108
108
|
"dependencies": {
|
|
109
109
|
"upng-js": "^2.1.0"
|
|
@@ -132,32 +132,54 @@ export async function createWebGLPlaywrightSetup(
|
|
|
132
132
|
*
|
|
133
133
|
* @param page - Playwright page
|
|
134
134
|
* @param renderFn - Function code as string that uses window.testRenderer
|
|
135
|
+
* @param width - Optional width to resize the canvas to
|
|
136
|
+
* @param height - Optional height to resize the canvas to
|
|
135
137
|
* @returns Captured pixel data
|
|
136
138
|
*/
|
|
137
139
|
export async function renderAndCaptureWebGLPlaywright(
|
|
138
140
|
page: Page,
|
|
139
|
-
renderFn: string
|
|
141
|
+
renderFn: string,
|
|
142
|
+
width?: number,
|
|
143
|
+
height?: number
|
|
140
144
|
): Promise<Uint8ClampedArray> {
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
try {
|
|
146
|
+
const pixelData = await page.evaluate(({ code, width, height }) => {
|
|
147
|
+
const renderer = (window as any).testRenderer;
|
|
148
|
+
const gl = (window as any).testGl;
|
|
149
|
+
const canvas = (window as any).testCanvas;
|
|
150
|
+
|
|
151
|
+
if (!renderer || !gl || !canvas) {
|
|
152
|
+
throw new Error('Renderer not initialized');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Resize canvas if needed
|
|
156
|
+
if (width !== undefined && height !== undefined) {
|
|
157
|
+
canvas.width = width;
|
|
158
|
+
canvas.height = height;
|
|
159
|
+
gl.viewport(0, 0, width, height);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
// Execute the render function
|
|
164
|
+
const fn = new Function('renderer', 'gl', code);
|
|
165
|
+
fn(renderer, gl);
|
|
166
|
+
} catch (err: any) {
|
|
167
|
+
// Capture context for better debugging
|
|
168
|
+
throw new Error(`Renderer Execution Error: ${err.message}\nCode:\n${code}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Ensure rendering is complete
|
|
172
|
+
gl.finish();
|
|
173
|
+
|
|
174
|
+
// Capture pixels
|
|
175
|
+
return (window as any).captureCanvas();
|
|
176
|
+
}, { code: renderFn, width, height });
|
|
177
|
+
|
|
178
|
+
return new Uint8ClampedArray(pixelData);
|
|
179
|
+
} catch (err: any) {
|
|
180
|
+
// Re-throw with clear message
|
|
181
|
+
throw new Error(`Browser Test Error: ${err.message}`);
|
|
182
|
+
}
|
|
161
183
|
}
|
|
162
184
|
|
|
163
185
|
/**
|
|
@@ -190,7 +212,12 @@ export async function testWebGLRenderer(
|
|
|
190
212
|
const setup = await createWebGLPlaywrightSetup(options);
|
|
191
213
|
|
|
192
214
|
try {
|
|
193
|
-
const pixels = await renderAndCaptureWebGLPlaywright(
|
|
215
|
+
const pixels = await renderAndCaptureWebGLPlaywright(
|
|
216
|
+
setup.page,
|
|
217
|
+
renderCode,
|
|
218
|
+
options.width,
|
|
219
|
+
options.height
|
|
220
|
+
);
|
|
194
221
|
|
|
195
222
|
await expectSnapshot(pixels, {
|
|
196
223
|
name: options.name,
|