// SPDX-FileCopyrightText: 2026 Stan Grams <sjg@haxx.space>
//
// SPDX-License-Identifier: GPL-2.0-or-later

import assert from "node:assert/strict";
import test from "node:test";
import vm from "node:vm";
import { bundleEntry } from "./bundle-entry.mjs";

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 bundleEntry(new URL("../src/webgl-renderer.ts", import.meta.url));
  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]);
});
