Skip to content

Commit 090e872

Browse files
committed
refactor(install): extract setup core helpers
1 parent b8512ab commit 090e872

5 files changed

Lines changed: 545 additions & 394 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
"smoke": "npm run smoke:analytics",
3030
"smoke:analytics": "npm run build && node scripts/smoke-analytics.mjs",
3131
"test": "npm run test:all",
32-
"test:all": "npm run test:worker && npm run test:registry && npm run test:install && npm run test:maintenance && npm run test:upstream-release && npm run test:build-core && npm run test:build-html-core",
32+
"test:all": "npm run test:worker && npm run test:registry && npm run test:install && npm run test:install-core && npm run test:maintenance && npm run test:upstream-release && npm run test:build-core && npm run test:build-html-core",
3333
"test:build-core": "node scripts/build-site-core.test.mjs",
3434
"test:build-html-core": "node scripts/build-html-core.test.mjs",
3535
"test:install": "node scripts/install.test.mjs",
36+
"test:install-core": "node scripts/install-core.test.mjs",
3637
"test:maintenance": "node scripts/maintenance.test.mjs",
3738
"test:registry": "node scripts/registry.test.mjs",
3839
"test:upstream-release": "node scripts/upstream-release.test.mjs",

scripts/install-core.test.mjs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env node
2+
3+
import assert from "node:assert/strict";
4+
import {
5+
analyticsDisclosureDefault,
6+
defaultBrandingSlogan,
7+
defaultContactEmail,
8+
normalizeAccessTeamDomain,
9+
normalizeArgs,
10+
normalizeAnalyticsProviders,
11+
normalizeDomain,
12+
normalizeLanguages,
13+
normalizeRandomSlugLength,
14+
normalizeSloganMap,
15+
parseArgs,
16+
slugifyOwner,
17+
slugifyWorker,
18+
suggestWordmarkSplit
19+
} from "./lib/install/core.mjs";
20+
21+
{
22+
assert.deepEqual(parseArgs(["--domain", "https://Go.Example/path", "--no-check", "--customize-public"]), {
23+
analytics: "disabled",
24+
check: false,
25+
customizePublic: true,
26+
dryRun: false,
27+
domain: "https://Go.Example/path",
28+
force: false,
29+
owner: "owner"
30+
});
31+
assert.throws(() => parseArgs(["--domain"]), /Missing value/);
32+
assert.throws(() => parseArgs(["unexpected"]), /Unknown argument/);
33+
}
34+
35+
{
36+
assert.equal(normalizeDomain("https://Go.Example/path"), "go.example");
37+
assert.equal(slugifyWorker("Go Example!!!"), "go-example");
38+
assert.equal(slugifyOwner("Team Name!"), "team-name");
39+
assert.deepEqual(normalizeLanguages("fr-CA,en,fr,de"), ["en", "fr", "de"]);
40+
assert.equal(normalizeAnalyticsProviders("Umami, FATHOM"), "umami,fathom");
41+
assert.throws(() => normalizeAnalyticsProviders("plausible"), /Unsupported analytics provider/);
42+
assert.equal(normalizeRandomSlugLength("12"), 12);
43+
assert.throws(() => normalizeRandomSlugLength("0"), /Random slug length/);
44+
}
45+
46+
{
47+
assert.equal(defaultContactEmail("security", "https://Example.com/path"), "security@example.com");
48+
assert.equal(normalizeAccessTeamDomain("https://team.cloudflareaccess.com/"), "team.cloudflareaccess.com");
49+
assert.deepEqual(suggestWordmarkSplit("go.example"), { black: "go.", green: "example" });
50+
}
51+
52+
{
53+
assert.equal(analyticsDisclosureDefault("disabled"), "No analytics enabled.");
54+
assert.equal(
55+
analyticsDisclosureDefault("umami"),
56+
"Privacy-respecting analytics are configured for operations, security, and reliability."
57+
);
58+
assert.equal(
59+
defaultBrandingSlogan({ operatorLegalName: "Example Inc." }, "en"),
60+
"A short-link service for Example Inc.'s projects"
61+
);
62+
assert.deepEqual(normalizeSloganMap("Hello", ["en", "fr"], { operatorLegalName: "Example Inc." }), {
63+
en: "Hello",
64+
fr: "Un service de liens courts pour les projets de Example Inc."
65+
});
66+
}
67+
68+
{
69+
const normalized = normalizeArgs(
70+
{
71+
analytics: "umami",
72+
domain: "https://Go.Example/path",
73+
owner: "Team Name",
74+
operatorAbuseContact: "abuse@example.com",
75+
operatorSecurityContact: "security@example.com",
76+
operatorTimezone: "America/Toronto",
77+
wordmarkBlack: "Go.",
78+
wordmarkGreen: "Example"
79+
},
80+
{
81+
defaultRandomSlugLength: 5,
82+
fallbackLastUpdated: "2026-06-05"
83+
}
84+
);
85+
86+
assert.equal(normalized.domain, "go.example");
87+
assert.equal(normalized.workerName, "go-example");
88+
assert.equal(normalized.owner, "team-name");
89+
assert.equal(normalized.randomSlugLength, 5);
90+
assert.equal(normalized.operator.short_domain, "go.example");
91+
assert.equal(normalized.operator.last_updated, "2026-06-05");
92+
assert.equal(normalized.operator.analytics_retention, "180 days");
93+
assert.equal(normalized.configureBranding, true);
94+
}
95+
96+
{
97+
assert.throws(
98+
() =>
99+
normalizeArgs(
100+
{
101+
domain: "go.example",
102+
operatorAbuseContact: "abuse@example.com",
103+
operatorSecurityContact: "security@example.com",
104+
operatorTimezone: "-4"
105+
},
106+
{ fallbackLastUpdated: "2026-06-05" }
107+
),
108+
/Operator timezone must be an IANA timezone name/
109+
);
110+
}
111+
112+
console.log("install core tests ok");

0 commit comments

Comments
 (0)