g1t/services/deployments/src/names.test.ts
| 1 | import assert from "node:assert/strict"; |
| 2 | import { registerHooks } from "node:module"; |
| 3 | import { test } from "node:test"; |
| 4 | |
| 5 | // The contracts import their own modules without extensions. |
| 6 | registerHooks({ |
| 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 | |
| 17 | const { hostWorkspace, label } = await import("./names.ts"); |
| 18 | |
| 19 | test("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 | |
| 29 | test("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 | }); |