25 lines
1.5 KiB
JavaScript
25 lines
1.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
|
import { SimSession, CONTEXT_ID } from "./sim-session.mjs";
|
|
|
|
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
|
|
const session = new SimSession(core, { sessionId: "wasm-motion-event" });
|
|
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
|
|
let sequence = 0;
|
|
const send = (kind, operationId, payload = {}) => session.accept({ ...base, kind, seq: ++sequence, operation_id: operationId, payload });
|
|
|
|
send("HELLO", "hello");
|
|
send("SESSION_ATTACH", "attach");
|
|
send("LOAD_WORKSPACE", "workspace", { root_path: "/workspace" });
|
|
send("PROGRAM_LOAD", "program", { source: "G21 G90\nG0 X0 Y0 Z0\nG1 X10 Y5 F120\nG17 G02 I1 J1\nM2\n", path: "wasm-motion-event.ngc" });
|
|
send("PROGRAM_RUN", "run");
|
|
const first = send("SIM_STEP", "step-1", { cycles: 4 });
|
|
const events = first.payload.program_steps.filter((step) => step.motion?.source === "wasm_interpreter_canonical_motion");
|
|
assert.ok(events.length >= 1);
|
|
assert.equal(events[0].motion.start.x, 0);
|
|
assert.equal(events[0].motion.end.x, 0);
|
|
assert.equal(events.at(-1).motion.motion_type, 2);
|
|
assert.equal(events.at(-1).motion.source_line, 4);
|
|
console.log(JSON.stringify({ schema: "wasm-motion-event.v1", status: "verified", events: events.length, last_motion: events.at(-1).motion }));
|