@quake2ts/test-utils 0.0.799 → 0.0.802

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.d.cts CHANGED
@@ -1841,9 +1841,11 @@ declare function createWebGLPlaywrightSetup(options?: WebGLPlaywrightOptions): P
1841
1841
  *
1842
1842
  * @param page - Playwright page
1843
1843
  * @param renderFn - Function code as string that uses window.testRenderer
1844
+ * @param width - Optional width to resize the canvas to
1845
+ * @param height - Optional height to resize the canvas to
1844
1846
  * @returns Captured pixel data
1845
1847
  */
1846
- declare function renderAndCaptureWebGLPlaywright(page: Page, renderFn: string): Promise<Uint8ClampedArray>;
1848
+ declare function renderAndCaptureWebGLPlaywright(page: Page, renderFn: string, width?: number, height?: number): Promise<Uint8ClampedArray>;
1847
1849
  /**
1848
1850
  * Runs a WebGL visual test with the actual quake2ts renderer.
1849
1851
  *
package/dist/index.d.ts CHANGED
@@ -1841,9 +1841,11 @@ declare function createWebGLPlaywrightSetup(options?: WebGLPlaywrightOptions): P
1841
1841
  *
1842
1842
  * @param page - Playwright page
1843
1843
  * @param renderFn - Function code as string that uses window.testRenderer
1844
+ * @param width - Optional width to resize the canvas to
1845
+ * @param height - Optional height to resize the canvas to
1844
1846
  * @returns Captured pixel data
1845
1847
  */
1846
- declare function renderAndCaptureWebGLPlaywright(page: Page, renderFn: string): Promise<Uint8ClampedArray>;
1848
+ declare function renderAndCaptureWebGLPlaywright(page: Page, renderFn: string, width?: number, height?: number): Promise<Uint8ClampedArray>;
1847
1849
  /**
1848
1850
  * Runs a WebGL visual test with the actual quake2ts renderer.
1849
1851
  *
package/dist/index.js CHANGED
@@ -13620,24 +13620,45 @@ async function createWebGLPlaywrightSetup(options = {}) {
13620
13620
  cleanup
13621
13621
  };
13622
13622
  }
13623
- async function renderAndCaptureWebGLPlaywright(page, renderFn) {
13624
- const pixelData = await page.evaluate((code) => {
13625
- const renderer = window.testRenderer;
13626
- const gl = window.testGl;
13627
- if (!renderer || !gl) {
13628
- throw new Error("Renderer not initialized");
13629
- }
13630
- const fn = new Function("renderer", "gl", code);
13631
- fn(renderer, gl);
13632
- gl.finish();
13633
- return window.captureCanvas();
13634
- }, renderFn);
13635
- return new Uint8ClampedArray(pixelData);
13623
+ async function renderAndCaptureWebGLPlaywright(page, renderFn, width, height) {
13624
+ try {
13625
+ const pixelData = await page.evaluate(({ code, width: width2, height: height2 }) => {
13626
+ const renderer = window.testRenderer;
13627
+ const gl = window.testGl;
13628
+ const canvas = window.testCanvas;
13629
+ if (!renderer || !gl || !canvas) {
13630
+ throw new Error("Renderer not initialized");
13631
+ }
13632
+ if (width2 !== void 0 && height2 !== void 0) {
13633
+ canvas.width = width2;
13634
+ canvas.height = height2;
13635
+ gl.viewport(0, 0, width2, height2);
13636
+ }
13637
+ try {
13638
+ const fn = new Function("renderer", "gl", code);
13639
+ fn(renderer, gl);
13640
+ } catch (err) {
13641
+ throw new Error(`Renderer Execution Error: ${err.message}
13642
+ Code:
13643
+ ${code}`);
13644
+ }
13645
+ gl.finish();
13646
+ return window.captureCanvas();
13647
+ }, { code: renderFn, width, height });
13648
+ return new Uint8ClampedArray(pixelData);
13649
+ } catch (err) {
13650
+ throw new Error(`Browser Test Error: ${err.message}`);
13651
+ }
13636
13652
  }
13637
13653
  async function testWebGLRenderer(renderCode, options) {
13638
13654
  const setup = await createWebGLPlaywrightSetup(options);
13639
13655
  try {
13640
- const pixels = await renderAndCaptureWebGLPlaywright(setup.page, renderCode);
13656
+ const pixels = await renderAndCaptureWebGLPlaywright(
13657
+ setup.page,
13658
+ renderCode,
13659
+ options.width,
13660
+ options.height
13661
+ );
13641
13662
  await expectSnapshot(pixels, {
13642
13663
  name: options.name,
13643
13664
  description: options.description,