Skip to content

[Test Improver] Add 116 unit tests for untested string.js utilities#17843

Draft
github-actions[bot] wants to merge 2 commits into
masterfrom
test-assist/string-utils-tests-fa9fce60416898ce
Draft

[Test Improver] Add 116 unit tests for untested string.js utilities#17843
github-actions[bot] wants to merge 2 commits into
masterfrom
test-assist/string-utils-tests-fa9fce60416898ce

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Test Improver — automated AI assistant

Goal and Rationale

shell/utils/string.js is a large (407-line) utility module used extensively across the codebase. Despite its size and importance, roughly half its exported functions had no unit tests. This PR adds tests for 25 previously untested pure functions.

Approach

Added shell/utils/__tests__/string-utils.test.ts with 116 tests covering:

Function Cases
camelToTitle simple, multi-hump, empty, null
ucFirst / lcFirst upper/lower, already correct, empty, null
strPad left/right padding, already-at-length, custom chars
escapeHtml &, <>, ", ', plain
escapeRegex dots, brackets, all specials
formatPercent <1%, 1–10%, ≥10%, precision edge cases
pluralize consonant+y, vowel+y, -ics, -s, regular
indent string, array, custom token, null, afterRegex
decamelize / dasherize camel, underscore, spaces
asciiLike ASCII, tab, newline, non-ASCII, empty
coerceStringTypeToScalarType float, int, boolean, NaN, passthrough
ensureRegex regex passthrough, exact string, non-exact
matchesSomeRegex match, no match, empty list, null string
nlToBr LF, CR+LF, CR, HTML escaping, null
splitObjectPath dotted, double-quoted, single-quoted, single
joinObjectPath simple, dot-containing segment, single
shortenedImage docker.io prefix, index.docker.io, :latest, sha256, null
isIpv4 valid, boundaries, out-of-range, too few octets, hostname
sanitizeKey / sanitizeValue / sanitizeIP allowed chars, strips invalid, null
xOfy numbers, non-number x/y, both
isBase64 valid, invalid padding, empty, non-base64

Coverage Impact

Running both string.test.ts (existing) and string-utils.test.ts (new):

Metric Before Combined
Statements 0% (new file) 89.4%
Branches 0% (new file) 98.2%
Functions 0% (new file) 88.2%
Lines 0% (new file) 89.4%

Remaining uncovered functions are non-deterministic (random32, randomStr, generateRandomAlphaString) and DOM-dependent (decodeHtml) — already covered in string.test.ts.

Trade-offs

  • Created a separate file rather than modifying the existing string.test.ts (per AGENTS.md: never overwrite existing test files).
  • Random functions intentionally excluded — non-deterministic by nature.

Reproducibility

# Run new tests only
node_modules/.bin/jest --no-coverage shell/utils/__tests__/string-utils.test.ts

# Run with coverage (both files)
node_modules/.bin/jest --collectCoverage --coverageDirectory /tmp/cov \
  --collectCoverageFrom 'shell/utils/string.js' \
  shell/utils/__tests__/string.test.ts \
  shell/utils/__tests__/string-utils.test.ts

Test Status

✅ 116/116 tests pass
✅ ESLint: 0 warnings, 0 errors

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 2.4M ·

Cover camelToTitle, ucFirst, lcFirst, strPad, escapeHtml, escapeRegex,
formatPercent, pluralize, indent, decamelize, dasherize, asciiLike,
coerceStringTypeToScalarType, ensureRegex, matchesSomeRegex, nlToBr,
splitObjectPath, joinObjectPath, shortenedImage, isIpv4, sanitizeKey,
sanitizeValue, sanitizeIP, xOfy, and isBase64.

All 116 tests pass. Combined with the existing string.test.ts:
89.4% stmts, 98.2% branches, 88.2% fns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants