home / client / test / harness.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Shared setup for the vector tests: install the stubbed DOM (the SAME module
// the fixture generator used, so a diff is a real diff), lay out the shell the
// renderers look for, then load the compiled testlib.
//
// Order matters: home.i18n hydrates the static markup at namespace load, so the
// document has to exist before the import.
import { readFileSync } from "node:fs";
import { installDom, serialize, h, flush } from "./dom-stub.mjs";

export { serialize, h, flush };

export function shell(env) {
  const body = env.body;
  body.replaceChildren();
  const nav = h("nav", { id: "tabs", "aria-label": "sections", "data-i18n-attr": "aria-label:nav.aria" });
  for (const [href, key, text] of [
    ["#/apps", "nav.apps", "apps"],
    ["#/about", "nav.about", "why"],
    ["#/you", "nav.you", "you"],
    ["#/boards", "nav.boards", "boards"],
    ["#/bots", "nav.bots", "bots"],
  ]) {
    const a = h("a", { href, "data-i18n": key });
    a.textContent = text;
    nav.appendChild(a);
  }
  body.appendChild(nav);
  const views = {};
  for (const v of ["apps", "about", "you", "boards", "bots"]) {
    views[v] = h("section", { class: "view", id: `view-${v}` });
    body.appendChild(views[v]);
  }
  views.apps.appendChild(h("div", { class: "apps" }));
  views.you.append(
    h("section", { class: "id-card", id: "identity" }),
    h("section", { class: "soc", id: "social" }),
    h("section", { class: "soc on", id: "you-lang" }),
  );
  views.boards.appendChild(h("section", { class: "soc", id: "lb" }));
  views.bots.appendChild(h("section", { class: "soc", id: "bots" }));
  body.appendChild(h("span", { id: "footer-lang" }));
  return views;
}

/** installDom + shell + the compiled testlib, in the one order that works. */
export async function boot(opts = {}) {
  const env = installDom(opts);
  const views = shell(env);
  const lib = await import("../test-dist/testlib.js");
  return { env, views, lib };
}

export function vectors(name) {
  return JSON.parse(readFileSync(new URL(`./vectors/${name}.json`, import.meta.url), "utf8"));
}

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/home.git