Skip to content

test: add unit tests for string and id utils - #2509

Open
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-string-id
Open

test: add unit tests for string and id utils#2509
ZayanKhan-12 wants to merge 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-string-id

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

Why

src/utils/string.ts and src/utils/id.ts previously had no unit tests, even though they back user-visible behavior: toSnakeCase drives telemetry flag-name generation (src/telemetry/flagUtils.ts), and createIdGenerator/stableIdSymbol back the stable IDs attached to collected resources (PageCollector, ServiceWorkerCollector, HeapSnapshotManager). This PR adds tests/utils/string.test.ts and tests/utils/id.test.ts, following the existing conventions in tests/utils/. No source changes.

What is covered

toSnakeCase:

  • camelCase and PascalCase conversion (including real flag names such as browserUrl -> browser_url, acceptInsecureCerts -> accept_insecure_certs)
  • acronym runs (APIFlags -> api_flags, parseHTML -> parse_html, XMLHttpRequest -> xml_http_request)
  • letter-to-digit transitions (version2 -> version_2, getHTTP2Response -> get_http_2_response) and the documented absence of digit-to-lowercase splitting (2fast -> 2fast)
  • already-snake_case input, non-alphanumeric collapsing, leading/trailing underscore stripping, non-ASCII (Unicode-aware regex) input, empty string, and single characters

createIdGenerator:

  • first generated id is 1
  • ids increment sequentially
  • independent generators do not share state
  • generated ids can be attached to and read from an object via stableIdSymbol without appearing in regular key enumeration (the pattern used by the collectors)

Testing

  • node scripts/test.js tests/utils/string.test.ts tests/utils/id.test.ts — all tests pass
  • npm run test:no-build — full suite passes, no failures
  • npm run check-format — ESLint and Prettier both clean

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ZayanKhan-12
ZayanKhan-12 force-pushed the chore/tests-string-id branch from 37d8ff3 to 96aff9f Compare August 8, 2026 21:46
@OrKoN
OrKoN enabled auto-merge August 10, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants