|
| 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