Files
nexus/frontend/scripts/test-irc.js
T
Andy DixonandClaude Sonnet 5 1a380a0e99 Rebrand: Nexus Terminal → Alchementary Link
Renames the product across the codebase: Go module path, config/data
paths, keychain service name, export file extension, build tooling,
docs, and UI text. Sidebar brand mark now reads ">_ AlchementaryLink"
with "Alchementary" in the connection-group gold accent colour, and
the window title is "Alchementary Link".

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019T8bJS8BCtY5GeSG2HBj1n
2026-09-03 16:41:23 +01:00

75 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const frontendRoot = path.resolve(__dirname, "..");
const source = fs.readFileSync(path.join(frontendRoot, "src/js/irc.js"), "utf8");
const context = {
window: {
AlchementaryLink: {
createElement: () => {
throw new Error("formatting tests must not create DOM elements");
},
},
},
};
vm.createContext(context);
vm.runInContext(source, context, { filename: "src/js/irc.js" });
const formatting = context.window.AlchementaryLink.IRCFormatting;
assert.ok(formatting, "IRC formatting helpers should be exported");
assert.strictEqual(
formatting.formatText("plain \x02bold\x02 \x1ditalic\x1d \x1funderlined\x1f"),
"plain \x1b[1mbold\x1b[22m \x1b[3mitalic\x1b[23m \x1b[4munderlined\x1b[24m",
);
assert.strictEqual(
formatting.formatText("\x0304red\x03 default"),
"\x1b[38;5;9mred\x1b[39;49m default",
);
assert.strictEqual(
formatting.formatText("\x0352extended \x0303,01matrix"),
"\x1b[38;5;196mextended \x1b[38;5;2m\x1b[48;5;0mmatrix",
);
assert.strictEqual(
formatting.formatText("\x04ff8800orange\x04 default"),
"\x1b[38;2;255;136;0morange\x1b[39;49m default",
);
assert.strictEqual(
formatting.formatText("\x0304,comma"),
"\x1b[38;5;9m,comma",
"a colour code without a background must leave its comma visible",
);
assert.strictEqual(
formatting.plainText("\x02bold\x02 \x0304red\x03"),
"bold red",
);
assert.strictEqual(
formatting.formatText("before\x1b[31munsafe\x1b]0;title\x07after"),
"beforeunsafeafter",
"untrusted ANSI and OSC sequences must not reach xterm",
);
const message = formatting.formatEvent(
{
type: "message",
from: "alice",
text: "hello \x02world\x02",
},
"12:34:56",
);
assert.ok(message.includes("[12:34:56]"));
assert.ok(message.includes("\x1b[1mworld\x1b[22m"));
assert.ok(message.includes("\x1b[1m\x1b[38;5;"), "nicknames should be bold and coloured");
assert.ok(message.endsWith("\x1b[0m"), "every line must reset terminal styling");
const action = formatting.formatEvent(
{ type: "action", from: "bob", text: "waves" },
"01:02:03",
);
assert.ok(action.includes("\x1b[3m"), "actions should be italicised");
console.log("IRC formatting regression tests passed.");