refactor: convert WSPR plugin to TypeScript

This commit is contained in:
sjg
2026-08-01 12:15:19 +02:00
parent a5dccd5489
commit d96624be4f
5 changed files with 623 additions and 534 deletions
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
//
// SPDX-License-Identifier: GPL-2.0-or-later
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import vm from "node:vm";
test("WSPR entry forwards decoded locators at their absolute frequency", async () => {
const forwarded = [];
const window = {
ft8BaseHz: 14_095_600,
trxUi: { confirm: async () => true },
mapAddLocator: (...args) => { forwarded.push(args); },
};
const context = vm.createContext({
window,
document: { getElementById: () => null, createDocumentFragment: () => ({ appendChild() {} }) },
setInterval() { return 1; },
Date,
Number,
String,
Set,
Element: class Element {},
console,
});
const source = await readFile(new URL("../../assets/web/generated/wspr.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
window.onServerWspr({ message: "SP0ABC JO91 37", freq_hz: 1_420, ts_ms: Date.now() });
assert.equal(forwarded.length, 1);
assert.equal(forwarded[0][1][0], "JO91");
assert.equal(forwarded[0][4].freq_hz, 14_097_020);
});