chrome-extension / test / address.test.tsmain at c58198b
// The panel's address rule (public/address.js) against the rule that every other client uses
// (iterate/mind-api `mindAddressOf`): the extension carries its own copy, and the two answer alike.
import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { test } from "node:test";
import { mindIssuerOf } from "../public/address.js";
// The shared rule is the platform's, in the repo /repos/kernel. This repo has no copy of it: the
// two tests read it from a checkout of kernel in the folder beside this one, with its packages
// installed (`pnpm install` there), and are skipped without one.
type Rule = (typed: string) => { address: string } | { error: string };
const kernel = new URL("../../kernel/core/lib/src/mind-api.ts", import.meta.url);
let mindAddressOf: Rule = () => ({ error: "skipped" });
let skip: string | false = "no checkout of /repos/kernel beside this repo";
if (existsSync(kernel)) {
try {
mindAddressOf = ((await import(kernel.href)) as { mindAddressOf: Rule }).mindAddressOf;
skip = false;
} catch (error) {
skip = `the checkout of /repos/kernel beside this repo does not load: ${(error as Error).message}`;
}
}
void test("what a person typed names the same mind in the panel as in every other client", { skip }, () => {
for (const typed of [
"example.com",
" Example.COM. ",
// a control plane at a zone's apex, and at a hostname of the person's choice
"https://example.com",
"example.com/",
"control.example.com",
"iterate.example.com",
"https://iterate.example.com/minds/x",
"example.co.uk",
]) {
const shared = mindAddressOf(typed);
assert.ok("address" in shared, typed);
assert.equal(mindIssuerOf(typed), `https://${shared.address}`, typed);
}
assert.equal(mindIssuerOf("https://example.com"), "https://example.com");
assert.equal(mindIssuerOf("control.example.com"), "https://control.example.com");
});
void test("what is no address in the other clients is none in the panel", { skip }, () => {
for (const typed of ["", "example", "192.0.2.1", "https://[2001:db8::1]/", "foo_bar.com"]) {
assert.ok("error" in mindAddressOf(typed), typed);
assert.throws(() => mindIssuerOf(typed), typed);
}
});