Files
VibemakerSandbox/app/test/runtime-ownership.test.js
T
chenlin fc5ee4f2c6 feat: release v0.2 multi-robot simulator
Add declarative robot packages, shared simulation lifecycle and Microban ONNX/PD walking with independent head control.

Unify comic UI and chase camera; default robot packages to a 4.5m arena with real collision walls. Include regression tests, asset provenance/licenses and verification evidence.
2026-10-28 14:00:26 +08:00

44 lines
1.5 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { Disposables } from "../src/platform/runtime/Disposables.js";
import { SimulationClock } from "../src/platform/runtime/SimulationClock.js";
test("resources release once in LIFO order, including after disposal", async () => {
const scope = new Disposables(),
calls = [];
scope.add(() => calls.push(1));
scope.add(async () => calls.push(2));
await scope.dispose();
await scope.dispose();
await scope.add(() => calls.push(3));
assert.deepEqual(calls, [2, 1, 3]);
});
test("cleanup continues after release failure and removes listeners", async () => {
const scope = new Disposables(),
target = new EventTarget();
let count = 0;
scope.listen(target, "test", () => count++);
scope.add(() => {
throw new Error("release");
});
target.dispatchEvent(new Event("test"));
await assert.rejects(scope.dispose(), AggregateError);
target.dispatchEvent(new Event("test"));
assert.equal(count, 1);
});
test("simulation timers are frozen without steps and reset clears callbacks", () => {
const clock = new SimulationClock();
let fired = 0;
clock.setTimeout(() => fired++, 800);
clock.advance(0.78);
assert.equal(fired, 0);
clock.advance(0.02);
assert.equal(fired, 1);
const id = clock.setTimeout(() => fired++, 1);
clock.clearTimeout(id);
clock.advance(1);
clock.setTimeout(() => fired++, 1);
clock.reset();
clock.advance(1);
assert.equal(fired, 1);
});