Checkpoint web parity through Chromium input tasks
This commit is contained in:
42
web/tests/unit/stl-export.test.mjs
Normal file
42
web/tests/unit/stl-export.test.mjs
Normal file
@@ -0,0 +1,42 @@
|
||||
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(), "stl-export-unit-"));
|
||||
const sourcePath = path.join(root, "web/protocol/stl-export.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, "stl-export.mjs");
|
||||
fs.writeFileSync(modulePath, transpiled.outputText);
|
||||
const protocol = await import(pathToFileURL(modulePath));
|
||||
const document = {
|
||||
schemaVersion: 1,
|
||||
variant: "STL_BINARY",
|
||||
unitScale: 1,
|
||||
declaredTriangleCount: 1,
|
||||
triangleCount: 1,
|
||||
removedDegenerateTriangles: 0,
|
||||
normals: [[0, 1, 0]],
|
||||
vertices: [[[-1, 0, 1], [1, 0, 1], [1, 0, -1]]],
|
||||
bounds: { min: [-1, 0, -1], max: [1, 0, 1] },
|
||||
};
|
||||
|
||||
test("M12-07F serializes binary STL and reports material loss", () => {
|
||||
const output = protocol.exportBinarySTL(document);
|
||||
assert.equal(output.byteLength, 134);
|
||||
assert.equal(new DataView(output).getUint32(80, true), 1);
|
||||
assert.deepEqual(protocol.createSTLLossReport(2), {
|
||||
schemaVersion: 1,
|
||||
operation: "STL_EXPORT_LOSS_REPORT",
|
||||
canRoundTrip: true,
|
||||
warningCount: 1,
|
||||
warnings: [{ code: "STL_MATERIAL_UNSUPPORTED", severity: "warning", message: "STL has no material slots; 2 source material assignments are omitted" }],
|
||||
});
|
||||
});
|
||||
|
||||
test.after(() => fs.rmSync(temporary, { recursive: true, force: true }));
|
||||
Reference in New Issue
Block a user