43 lines
2.1 KiB
JavaScript
43 lines
2.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { after, before, test } from "node:test";
|
|
import { createServer } from "vite";
|
|
|
|
let server, readNativeRerunCameraEye;
|
|
before(async () => {
|
|
server = await createServer({ appType: "custom", logLevel: "silent",
|
|
server: { middlewareMode: true } });
|
|
({ readNativeRerunCameraEye } = await server.ssrLoadModule(
|
|
"/src/components/rerun/recordedRerunCameraJournal.ts"));
|
|
});
|
|
after(async () => { await server?.close(); });
|
|
|
|
test("camera snapshot copies exact native pose, without approximating input", () => {
|
|
const native = { position: [287, -74, 8], lookTarget: [286, -72, 0], eyeUp: [0, 0, 1] };
|
|
const eye = readNativeRerunCameraEye(native);
|
|
assert.deepEqual(eye, native);
|
|
native.position[0] = 999;
|
|
assert.equal(eye.position[0], 287);
|
|
assert.equal(readNativeRerunCameraEye(null), null);
|
|
});
|
|
|
|
test("invalid native pose fails closed instead of substituting a guessed camera", () => {
|
|
for (const value of [{}, "pose", { position: [NaN, 0, 1], lookTarget: [0, 0, 0], eyeUp: [0, 0, 1] }]) {
|
|
assert.throws(() => readNativeRerunCameraEye(value), /Invalid native Rerun camera/);
|
|
}
|
|
});
|
|
|
|
test("iframe owner reads the native camera and installs no shadow input listeners", () => {
|
|
const owner = readFileSync(new URL("../src/components/rerun/recordedRerunOwner.ts", import.meta.url), "utf8");
|
|
const camera = readFileSync(new URL("../src/components/rerun/recordedRerunCameraJournal.ts", import.meta.url), "utf8");
|
|
assert.match(owner, /get_camera_eye\?\.\(\)/);
|
|
assert.doesNotMatch(owner + camera, /createRecordedRerunCameraJournal|addEventListener|Math\.exp/);
|
|
});
|
|
|
|
test("display blueprint activation carries the current native eye, not the embedded preset", () => {
|
|
const viewport = readFileSync(new URL("../src/components/RerunViewport.tsx", import.meta.url), "utf8");
|
|
assert.match(viewport, /!enablingFollow \? active\.getCameraEye\?\.\(\) \?\? undefined : undefined/);
|
|
assert.match(viewport, /requestBlueprint\(\s*firstEye,\s*firstEyeIsTrackingRelative,/);
|
|
assert.match(viewport, /currentTimeNs: eyeRelativeToTracking \? currentTimeNs : undefined/);
|
|
});
|