Files
gods-eye-view/src/globe/testing/contractSuite/camera.test.mjs
T
German Khokhlov 6c77b1ed41 Complete camera flights at their duration on both engines
Navara's own flight clock loses time on slow frames (a one-second flight
took 1.55 s at 50 ms frames and 3.1 s at 100 ms), so stories waited for
the director's timeout. The adapter now owns the flight deadline and lands
the camera on time. On Cesium a flight still counted as active inside its
complete callback, because Cesium removes its tween only afterwards. The
contract suite checks completion time and state for every easing.
2026-11-12 00:42:17 +04:00

44 lines
1.3 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createFakeEngine } from '../fakeEngine.js';
import { createContractSuite } from './index.mjs';
for (const timing of ['on time', 'late', 'missing']) {
test(`flight duration check: ${timing} completion`, async (context) => {
let now = 0;
context.mock.method(performance, 'now', () => now);
const engine = createFakeEngine();
const flyTo = engine.camera.flyTo;
engine.camera.flyTo = (options) =>
flyTo({
...options,
complete: () => {
if (timing === 'missing') return;
if (timing === 'late') now += 200;
options.complete?.();
},
});
const check = createContractSuite(engine, {
waitFrames: async (count) => {
for (let frame = 0; frame < count; frame++) {
now += 50;
engine.fake.frame(50);
}
},
}).find(({ name }) => name.startsWith('camera.flyTo: completes within'));
try {
if (timing === 'on time') await check.run();
else
await assert.rejects(
check.run(),
timing === 'late'
? /flight completed after 600 ms/
: /flight missed its duration/,
);
assert.equal(engine.camera.flightActive(), false);
} finally {
engine.destroy();
}
});
}