refactor: add typed decoder plugin runtime
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// 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("plugin runtime queues lazy decoder traffic and flushes in order on registration", async () => {
|
||||
const window = {};
|
||||
const context = vm.createContext({ window, Map, Error });
|
||||
const source = await readFile(new URL("../../assets/web/generated/plugin-runtime.js", import.meta.url), "utf8");
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
assert.equal(window.trxPluginRuntime.dispatch("late", { sequence: 1 }), false);
|
||||
assert.equal(window.trxPluginRuntime.restore("late", [{ sequence: 2 }]), false);
|
||||
const received = [];
|
||||
window.trxPluginRuntime.registerDecoder({
|
||||
id: "late",
|
||||
onMessage: (message) => { received.push(["message", message.sequence]); },
|
||||
restore: (messages) => { received.push(["restore", messages[0].sequence]); },
|
||||
});
|
||||
assert.deepEqual(received, [["message", 1], ["restore", 2]]);
|
||||
});
|
||||
Reference in New Issue
Block a user