Files
linuxcncWebWASM/web/workspace/test_sim_case_loader.mjs

31 lines
1.8 KiB
JavaScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { loadSimulationCase, toWorkerConfiguration } from "./sim-case-loader.mjs";
const fetchImpl = async (url) => {
const path = new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url);
try {
const body = await readFile(path);
return { ok: true, text: async () => body.toString("utf8") };
} catch {
return { ok: false, text: async () => "" };
}
};
const ready = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/corexy/corexy_by_hal.ini", fetchImpl });
assert.equal(ready.status, "ready");
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/corexy_base.inc"]);
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/3joint_xyz.hal"]);
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/corexy_by_hal.hal"]);
assert.equal(toWorkerConfiguration(ready).entrypoint, ready.entrypoint);
assert.match(ready.state_hash, /^fnv1a64:/);
const blocked = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/anglejog/anglejog.ini", fetchImpl });
assert.equal(blocked.status, "blocked");
assert.ok(blocked.missing.includes("linuxcnc/configs/sim/axis/anglejog/anglejog.var"));
assert.equal(blocked.catalog.status, "blocked");
assert.equal((await loadSimulationCase({ path: ready.entrypoint, fetchImpl })).state_hash, ready.state_hash);
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/linuxcnc.var"]);
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/tool.tbl"]);
console.log(JSON.stringify({ schema: "simulation-case-loader-sample.v1", status: "verified", case: { entrypoint: ready.entrypoint, files: ready.fetched.length, missing: ready.missing.length, state_hash: ready.state_hash }, blocked: { entrypoint: blocked.entrypoint, missing: blocked.missing.length, state_hash: blocked.state_hash } }));