refactor: convert AIS plugin to TypeScript

This commit is contained in:
sjg
2026-08-01 12:39:20 +02:00
parent ec59908e0d
commit d93f784aad
6 changed files with 466 additions and 408 deletions
@@ -0,0 +1,34 @@
// 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("AIS entry forwards positioned vessels with normalized metadata", async () => {
const forwarded = [];
const window = {
trxUi: { confirm: async () => true },
aisMapAddVessel: (message) => { forwarded.push(message); },
};
const context = vm.createContext({
window,
document: { getElementById: () => null },
Date,
Number,
String,
Array,
Map,
console,
});
const source = await readFile(new URL("../../assets/web/generated/ais.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
window.onServerAis({ mmsi: 261000001, lat: 54.5, lon: 18.5, channel: "A", ts_ms: Date.now() });
assert.equal(forwarded.length, 1);
assert.equal(forwarded[0].mmsi, 261000001);
assert.equal(forwarded[0].rig_id, null);
assert.equal(typeof forwarded[0]._tsMs, "number");
});