59 lines
2.1 KiB
JavaScript
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 }));
|