Files
workinf_Blender_Wasm/web/tests/unit/viewport-dpr.test.mjs
mes123456 380cbed4ff
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Checkpoint web parity through Chromium input tasks
2026-08-19 10:39:03 -04:00

25 lines
1.4 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
import ts from "../../node_modules/typescript/lib/typescript.js";
const root = path.resolve(import.meta.dirname, "../../..");
const sourcePath = path.join(root, "web/protocol/viewport-dpr.ts");
const output = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
assert.deepEqual(output.diagnostics, []);
const dpr = await import(`data:text/javascript;base64,${Buffer.from(output.outputText).toString("base64")}`);
test("M14-04B clamps DPR and computes stable backing dimensions", () => {
for (const [observed, expected] of [[1, 1], [1.5, 1.5], [2, 2], [3, 2], [0, 1], [Number.NaN, 1]]) {
const metrics = dpr.resolveViewportPixelMetrics(101, 57, observed);
assert.equal(metrics.pixelRatio, expected);
assert.deepEqual([metrics.backingWidth, metrics.backingHeight], [Math.floor(101 * expected), Math.floor(57 * expected)]);
}
});
test("M14-04B uses CSS bounds for DPR-independent NDC", () => {
assert.deepEqual(dpr.viewportNDC(150, 75, { left: 100, top: 25, width: 100, height: 100 }), { x: 0, y: 0 });
assert.throws(() => dpr.viewportNDC(0, 0, { left: 0, top: 0, width: 0, height: 1 }), /VIEWPORT_BOUNDS_INVALID/);
});