37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
// 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);
|
|
});
|