Files
multica/packages/views/common/github-url.test.ts
2a643cc740 MUL-6291: stop paying for jsdom in pure-logic frontend suites (#7081)
MUL-6291. Vitest's own breakdown for `@multica/views` showed the shape of the
problem: environment 633s and import 644s against only 508s of actual test
execution. Two thirds of a cold frontend-test run went on building a jsdom per
file and importing its module graph, not on running assertions.

- 94 pure-logic `.test.ts` files across views/web/desktop now declare
  `// @vitest-environment node`. Measured on the 45 converted views files:
  environment 53.15s -> 4ms, wall 8.72s -> 2.03s. Candidates were picked by
  module-graph analysis (skipping type-only imports) and rejected when the code
  under test branches on `typeof window`/`document`, where node would silently
  take the SSR path and still pass; the remainder were verified empirically and
  reverted where they failed.
- The three jsdom setup files bail out when there is no DOM, so a node-env suite
  can share them.
- schedule-editor: the pure state transitions (isFullDay, displayWindow,
  timeAnchorOf, defaultAtTime, defaultEveryTime, clampWindow, toggleDay) move
  out of the component into transitions.ts, with the full combination matrix as
  a table-driven node-env suite. 34 cases in 3ms, replacing four DOM mounts.
- Cross-layer duplicates removed where a canonical layer already owns the
  matrix: originSourceUrl (skills/lib/origin.test.ts) was re-run through the
  refresh dialog and the detail page; needsSourceBackfill
  (core/onboarding/needs-backfill.test.ts) through the backfill modal. Each
  component keeps one wiring case naming the canonical file.

No behaviour change: the transitions extraction is a pure move, and every
removal names where the same contract is still covered.

Co-authored-by: Bohan-J <[email protected]>
Co-authored-by: multica-agent <[email protected]>
2026-08-17 18:40:19 +08:00

89 lines
2.8 KiB
TypeScript

// @vitest-environment node
import { describe, it, expect } from "vitest";
import { githubShortLabel, midTruncate } from "./github-url";
describe("githubShortLabel", () => {
it("extracts owner/repo from an https URL", () => {
expect(githubShortLabel("https://github.com/octocat/hello-world")).toBe(
"octocat/hello-world",
);
});
it("ignores extra path segments after owner/repo", () => {
expect(
githubShortLabel("https://github.com/octocat/hello-world/tree/main"),
).toBe("octocat/hello-world");
});
it("strips a trailing .git suffix", () => {
expect(githubShortLabel("https://github.com/octocat/hello-world.git")).toBe(
"octocat/hello-world",
);
});
it("handles the www.github.com host", () => {
expect(githubShortLabel("https://www.github.com/octocat/hello-world")).toBe(
"octocat/hello-world",
);
});
it("handles ssh:// URLs and strips .git", () => {
expect(
githubShortLabel("ssh://[email protected]/octocat/hello-world.git"),
).toBe("octocat/hello-world");
});
it("handles scp-style shorthand ([email protected]:owner/repo.git)", () => {
expect(githubShortLabel("[email protected]:octocat/hello-world.git")).toBe(
"octocat/hello-world",
);
});
it("handles scp-style shorthand without a .git suffix", () => {
expect(githubShortLabel("[email protected]:octocat/hello-world")).toBe(
"octocat/hello-world",
);
});
it("middle-truncates so a shared long prefix stays distinguishable", () => {
const a = githubShortLabel(
"https://github.com/example-organization/very-long-repository-name-for-customer-alpha.git",
);
const b = githubShortLabel(
"https://github.com/example-organization/very-long-repository-name-for-customer-beta.git",
);
expect(a).not.toBe(b);
expect(a.length).toBeLessThanOrEqual(40);
expect(a.endsWith("alpha")).toBe(true);
expect(b.endsWith("beta")).toBe(true);
});
it("returns enterprise-host URLs unchanged", () => {
const url = "https://github.enterprise.com/octocat/hello-world";
expect(githubShortLabel(url)).toBe(url);
});
it("returns malformed input unchanged", () => {
expect(githubShortLabel("not a url")).toBe("not a url");
});
it("returns a github URL without a repo segment unchanged", () => {
const url = "https://github.com/octocat";
expect(githubShortLabel(url)).toBe(url);
});
});
describe("midTruncate", () => {
it("leaves short strings untouched", () => {
expect(midTruncate("short")).toBe("short");
});
it("caps the result at maxLen and inserts an ellipsis", () => {
const out = midTruncate("a".repeat(100), 21);
expect(out.length).toBe(21);
expect(out).toContain("…");
expect(out.startsWith("aaaaaaaaaa")).toBe(true);
expect(out.endsWith("aaaaaaaaaa")).toBe(true);
});
});