36 lines
2.6 KiB
JavaScript
36 lines
2.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-07C/manifest.json"), "utf8"));
|
|
const report = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-07C/web-roundtrip-report.json"), "utf8"));
|
|
const fileHash = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
|
|
|
|
assert.deepEqual(
|
|
{ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask },
|
|
{ schemaVersion: 1, task: "M12-07C", parentTask: "M12-07B", nextTask: "M12-07D" },
|
|
);
|
|
assert.deepEqual(
|
|
{ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask },
|
|
{ schemaVersion: 1, task: "M12-07C", operation: "WEB_OBJ_TO_DESKTOP_ROUNDTRIP", nextTask: "M12-07D" },
|
|
);
|
|
assert.deepEqual(report.browser.imported, { schemaVersion: 1, objectCount: 2, positionCount: 6, texcoordCount: 6, normalCount: 2, faceCount: 2, materialCount: 2 });
|
|
assert.deepEqual(report.browser.lossReport, { schemaVersion: 1, operation: "OBJ_EXPORT_LOSS_REPORT", canRoundTrip: true, warningCount: 0, warnings: [] });
|
|
assert.equal(report.browser.missingTextureLoss.warningCount, 2);
|
|
assert.ok(report.browser.missingTextureLoss.warnings.every((warning) => warning.code === "OBJ_TEXTURE_ORIGIN_UNRESOLVED"));
|
|
assert.equal(report.desktop.schemaVersion, 1);
|
|
assert.equal(report.desktop.operation, "DESKTOP_IMPORT_WEB_OBJ");
|
|
assert.equal(report.desktop.objectCount, 2);
|
|
assert.equal(report.desktop.meshCount, 2);
|
|
assert.ok(report.desktop.objects.every((object) => object.vertexCount === 3 && object.polygonCount === 1 && object.triangleCount === 1 && object.uvLayers.includes("UVMap") && object.materials.length === 1));
|
|
assert.deepEqual(report.comparisons, { objectCountExact: true, triangleCountExact: true, uvLayerPresent: true, materialPresent: true });
|
|
for (const artifact of Object.values(manifest.artifacts)) {
|
|
const file = path.join(root, artifact.path);
|
|
assert.ok(fs.existsSync(file), `missing artifact ${artifact.path}`);
|
|
assert.equal(fileHash(file), artifact.sha256, `hash mismatch ${artifact.path}`);
|
|
}
|
|
process.stdout.write(`obj-web-roundtrip-ok objects=${report.desktop.objectCount} triangles=${report.desktop.objects.reduce((sum, object) => sum + object.triangleCount, 0)} lossWarnings=${report.browser.missingTextureLoss.warningCount} desktopExact=true next=${manifest.nextTask}\n`);
|