refactor: make FT8 family a typed module

This commit is contained in:
sjg
2026-08-01 12:21:13 +02:00
parent 03bdc10b02
commit 5ba3ecf59b
8 changed files with 562 additions and 930 deletions
@@ -37,5 +37,34 @@ test("FT2 entry normalizes audio offsets and registers typed callbacks", async (
assert.equal(mapMessages[0][4].freq_hz, 14_075_250);
const bar = barRenderer();
assert.equal(bar.count, 1);
assert.match(bar.html, /CQ SP0ABC JO91/);
assert.match(bar.html, /CQ SP0ABC/);
assert.match(bar.html, /JO91/);
});
test("FT8 entry installs shared parsing without relying on script globals", async () => {
const forwarded = [];
const window = {
ft8BaseHz: 7_074_000,
trxUi: { confirm: async () => true },
mapAddLocator: (...args) => { forwarded.push(args); },
setInterval() { return 1; },
};
const context = vm.createContext({
window,
document: { getElementById: () => null, createElement: () => ({ dataset: {} }), createDocumentFragment: () => ({ appendChild() {} }) },
Date,
Number,
String,
Array,
Set,
console,
});
const source = await readFile(new URL("../../assets/web/generated/ft8.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
const details = window.ft8ExtractLocatorDetails("K1ABC SP0ABC JO91");
assert.equal(details[0].source, "SP0ABC");
assert.equal(details[0].target, "K1ABC");
window.onServerFt8({ message: "K1ABC SP0ABC JO91", freq_hz: 500, ts_ms: Date.now() });
assert.equal(forwarded[0][4].freq_hz, 7_074_500);
});