g1t/services/deployments/src/names.test.ts

33 lines1,285 bytesCodeBlame
1import assert from "node:assert/strict";
2import { registerHooks } from "node:module";
3import { test } from "node:test";
4
5// The contracts import their own modules without extensions.
6registerHooks({
7 resolve(specifier, context, next) {
8 try {
9 return next(specifier, context);
10 } catch (error) {
11 if (specifier.startsWith(".")) return next(`${specifier}.ts`, context);
12 throw error;
13 }
14 },
15});
16
17const { hostWorkspace, label } = await import("./names.ts");
18
19test("a workspace named like a domain loses that hyphen in hostnames", () => {
20 assert.equal(hostWorkspace("flagon-io"), "flagonio");
21 assert.equal(hostWorkspace("acme-co-uk"), "acmecouk");
22 assert.equal(hostWorkspace("Big-Corp-COM"), "big-corpcom");
23 // Nothing that only looks like one.
24 assert.equal(hostWorkspace("syntaqx"), "syntaqx");
25 assert.equal(hostWorkspace("io"), "io");
26 assert.equal(hostWorkspace("acme-labs"), "acme-labs");
27});
28
29test("an app's name uses that spelling, so no label reads as another site", async () => {
30 assert.equal(await label("flagon-io", "automation-lab", null), "automation-lab-flagonio");
31 assert.equal(await label("flagon-io", "web", "fix/login"), "web-git-fix-login-flagonio");
32 assert.equal(await label("syntaqx", "hello", null), "hello-syntaqx");
33});