refactor: convert WebGL renderer to TypeScript
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// 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("WebGL color helpers normalize CSS and HSL colors", async () => {
|
||||
const window = {};
|
||||
const context = vm.createContext({
|
||||
window,
|
||||
document: {
|
||||
body: { appendChild() {} },
|
||||
createElement: () => ({ style: {} }),
|
||||
},
|
||||
getComputedStyle: () => ({ color: "rgb(0, 0, 0)" }),
|
||||
Map,
|
||||
Math,
|
||||
Number,
|
||||
String,
|
||||
parseInt,
|
||||
});
|
||||
const source = await readFile(
|
||||
new URL("../../assets/web/generated/webgl-renderer.js", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
new vm.Script(source).runInContext(context);
|
||||
|
||||
assert.deepEqual(Array.from(window.trxParseCssColor("#ff800080")), [1, 128 / 255, 0, 128 / 255]);
|
||||
assert.deepEqual(Array.from(window.trxHslToRgba(0, 100, 50)), [1, 0, 0, 1]);
|
||||
});
|
||||
Reference in New Issue
Block a user