32 lines
1.5 KiB
JavaScript
32 lines
1.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import vm from 'node:vm';
|
|
|
|
const source = fs.readFileSync(new URL('../www/views/goniometer_rtw.js', import.meta.url), 'utf8');
|
|
const functionSource = source.match(/export function resolveGoniometerPersistenceMs[\s\S]*?\n\}/)?.[0];
|
|
assert.ok(functionSource, 'persistence resolver must remain testable');
|
|
const context = vm.createContext({ Number, String, Math });
|
|
vm.runInContext(functionSource.replace('export function', 'function'), context);
|
|
|
|
assert.equal(context.resolveGoniometerPersistenceMs({ GONIO_PERSISTENCE_MODE: 'fast' }), 50);
|
|
assert.equal(context.resolveGoniometerPersistenceMs({ GONIO_PERSISTENCE_MODE: 'medium' }), 150);
|
|
assert.equal(context.resolveGoniometerPersistenceMs({ GONIO_PERSISTENCE_MODE: 'slow' }), 300);
|
|
assert.equal(context.resolveGoniometerPersistenceMs({
|
|
GONIO_PERSISTENCE_MODE: 'custom',
|
|
GONIO_LINE_FADE_MS: 470,
|
|
}), 470);
|
|
assert.equal(context.resolveGoniometerPersistenceMs({
|
|
GONIO_PERSISTENCE_MODE: 'custom',
|
|
GONIO_LINE_FADE_MS: 900,
|
|
}), 600);
|
|
|
|
assert.match(source, /Math\.min\(targetPoints, total, MAX_TRACE_POINTS\)/,
|
|
'drawing must not upsample invented XY points');
|
|
assert.match(source, /while \(trails\.length >= MAX_TRAIL_FRAMES\)/,
|
|
'trail history must remain bounded');
|
|
assert.match(source, /pool\.pop\(\)/, 'trail buffers must be reused');
|
|
assert.doesNotMatch(source, /utils\.correlation\(/,
|
|
'browser must not recalculate or smooth backend correlation');
|
|
|
|
console.log('goniometer regression tests passed');
|