refactor: convert WEFAX plugin to TypeScript

This commit is contained in:
sjg
2026-08-01 12:33:38 +02:00
parent 0ab0f80986
commit 7251ec276d
6 changed files with 491 additions and 392 deletions
@@ -0,0 +1,30 @@
// 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("WEFAX entry exposes typed lifecycle handlers and renders decoder state", async () => {
const status = { textContent: "", style: { color: "" } };
const window = {};
const context = vm.createContext({
window,
document: { getElementById: (id) => id === "wefax-status" ? status : null },
Date,
Number,
String,
Uint8Array,
console,
});
const source = await readFile(new URL("../../assets/web/generated/wefax.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
assert.equal(typeof window.onServerWefaxProgress, "function");
assert.equal(typeof window.restoreWefaxHistory, "function");
window.onServerWefaxProgress({ state: "Scanning 12 MHz" });
assert.equal(status.textContent, "Scanning 12 MHz");
assert.equal(status.style.color, "var(--text-accent)");
});