Files
workinf_Blender_Wasm/web/tests/unit/glb-loss-report.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

59 lines
2.1 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";
import test from "node:test";
import ts from "typescript";
const root = path.resolve(import.meta.dirname, "../../..");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "glb-loss-report-unit-"));
const sourcePath = path.join(root, "web/protocol/glb-loss-report.ts");
const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), {
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
fileName: sourcePath,
reportDiagnostics: true,
});
assert.deepEqual(transpiled.diagnostics, []);
const modulePath = path.join(temporary, "glb-loss-report.mjs");
fs.writeFileSync(modulePath, transpiled.outputText);
const protocol = await import(pathToFileURL(modulePath));
test("M12-06D produces deterministic sorted machine loss entries", () => {
const snapshot = {
sceneId: "scene:test",
revision: 7,
nodes: [{}, {}],
meshes: [{}],
materials: [{}, {}],
images: [{}],
animations: [{}],
nonMeshData: [{}],
};
const report = protocol.createGLBLossReport(snapshot, {
canExport: false,
warnings: [
{ code: "Z_LOSS", severity: "warning", message: "z", id: "id:z" },
{ code: "A_BLOCK", severity: "error", message: "a", id: "id:a" },
{ code: "A_BLOCK", severity: "warning", message: "b", id: undefined },
],
});
assert.deepEqual(report, {
schemaVersion: 1,
operation: "GLB_EXPORT_LOSS_REPORT",
sceneId: "scene:test",
sourceRevision: 7,
canExport: false,
errorCount: 1,
warningCount: 2,
losses: [
{ code: "A_BLOCK", severity: "error", message: "a", id: "id:a" },
{ code: "A_BLOCK", severity: "warning", message: "b", id: null },
{ code: "Z_LOSS", severity: "warning", message: "z", id: "id:z" },
],
surface: { nodeCount: 2, meshCount: 1, materialCount: 2, imageCount: 1, animationCount: 1, nonMeshCount: 1 },
});
});
test.after(() => fs.rmSync(temporary, { recursive: true, force: true }));