Skip to content

test: add unit coverage for bin/utils/url.ts helpers#1279

Open
LuisMIguelFurlanettoSousa wants to merge 1 commit into
tw93:mainfrom
LuisMIguelFurlanettoSousa:test/url-utils-coverage
Open

test: add unit coverage for bin/utils/url.ts helpers#1279
LuisMIguelFurlanettoSousa wants to merge 1 commit into
tw93:mainfrom
LuisMIguelFurlanettoSousa:test/url-utils-coverage

Conversation

@LuisMIguelFurlanettoSousa

Copy link
Copy Markdown

Closes #1278

What

Adds tests/unit/url.test.ts, the first dedicated test file for bin/utils/url.ts. Previously only safeDomainsToRegex was covered (via safe-domains.test.ts); getDomain, appendProtocol, and normalizeUrl were untested.

Coverage

  • getDomain — bare domain, www/arbitrary subdomain stripping, multi-part public suffixes (example.co.uk), and the null paths (no protocol, malformed input, single-label localhost).
  • appendProtocol — already-schemed URLs pass through; bare host gets https://; and the documented WHATWG quirk where localhost:3000 is parsed as scheme localhost: and left unchanged.
  • normalizeUrl — bare host normalization, valid URL passthrough, and the previously-uncovered throw branch.

Tests only — no change to bin/, so no dist/cli.js rebuild. All assertions characterize current behavior (verified against the live functions).

Verify

npx vitest run tests/unit/url.test.ts

Full suite: 218 passed; pnpm run format:check clean.

bin/utils/url.ts had no dedicated test file; getDomain, appendProtocol, and
normalizeUrl were untested (only safeDomainsToRegex is covered, via
safe-domains.test.ts). Add tests/unit/url.test.ts characterizing the SLD
extraction (incl. multi-part public suffixes and single-label hosts), the
add-https behavior of appendProtocol (including the WHATWG host:port quirk),
and normalizeUrl, covering its previously-untested throw branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant