refactor: convert scheduler to typed module

This commit is contained in:
sjg
2026-08-01 13:23:30 +02:00
parent c7994347e9
commit 0338c8b8d2
11 changed files with 1747 additions and 1533 deletions
@@ -0,0 +1,43 @@
// 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("scheduler registers a typed module service without lifecycle globals", async () => {
const window = { trx: { modules: {} }, trxUi: { confirm: async () => true } };
const context = vm.createContext({
window,
document: {
activeElement: null,
addEventListener() {},
getElementById: () => null,
querySelector: () => null,
},
localStorage: { getItem: () => null, setItem() {} },
setInterval: () => 1,
clearInterval() {},
setTimeout: () => 1,
HTMLElement: class HTMLElement {},
Element: class Element {},
Date,
Number,
String,
Array,
Promise,
WeakSet,
console,
});
const source = await readFile(new URL("../../assets/web/generated/scheduler.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
const service = window.trx.modules.scheduler;
assert.equal(typeof service.initialize, "function");
assert.equal(typeof service.setRig, "function");
assert.equal(typeof service.getConfig, "function");
assert.equal(window.initScheduler, undefined);
assert.equal(window.schedulerBridge, undefined);
});