refactor: convert virtual channels to TypeScript

This commit is contained in:
sjg
2026-08-01 12:57:09 +02:00
parent fc2f55bab9
commit 6a83e2e90a
6 changed files with 639 additions and 544 deletions
@@ -0,0 +1,36 @@
// 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("virtual channels expose typed SSE and interception boundaries", async () => {
const window = {};
const context = vm.createContext({
window,
document: { getElementById: () => null },
fetch: async () => ({ ok: true, json: async () => ({ connected_sessions: 1, released_sessions: 0 }) }),
setInterval: () => 1,
clearInterval() {},
setTimeout,
Date,
Number,
String,
Array,
Set,
JSON,
Error,
console,
});
const source = await readFile(new URL("../../assets/web/generated/vchan.js", import.meta.url), "utf8");
new vm.Script(source).runInContext(context);
assert.equal(typeof window.vchanHandleSession, "function");
assert.equal(typeof window.vchanHandleChannels, "function");
assert.equal(typeof window.vchanApplyCapabilities, "function");
assert.equal(await window.vchanInterceptMode("USB"), false);
assert.equal(await window.vchanInterceptBandwidth(2400), false);
});