Skip to content

test: add unit tests for keyboard key parsing - #2512

Merged
OrKoN merged 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-keyboard
Aug 10, 2026
Merged

test: add unit tests for keyboard key parsing#2512
OrKoN merged 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:chore/tests-keyboard

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

Why

src/utils/keyboard.ts (parseKey) validates and parses the user-supplied key argument for the press_key tool, so it is a small but agent-facing input-validation path. Its only coverage so far was a handful of inline assertions inside tests/tools/input.test.ts. This PR gives the module a dedicated unit test file under tests/utils/ (alongside files.test.ts and url.test.ts), moves the existing inline assertions there, and expands coverage.

Coverage

  • Single keys (Enter, Escape, F5, 5, Numpad5, KeyA, a, A, ' ', \r, \n) and lone modifiers (Shift, Control, Meta)
  • Primary key returned first, followed by modifiers in original order (Control+Shift+P['P', 'Control', 'Shift'], Alt+Control+Delete vs Control+Alt+Delete)
  • Literal plus as a key (+, Shift++, Control+Shift++)
  • Trailing separator is ignored (Shift+['Shift'], ++['+'])
  • Case sensitivity (Shift+a vs Shift+A; shift+a and ENTER throw)
  • No whitespace trimming (Shift + a, Enter throw)
  • Invalid key names throw with the <key> is invalid. Valid keys are: ... message shape (including NotAKey+Enter and +a)
  • Empty input throws Key could not be parsed.
  • Duplicate keys throw (Shift+Shift, Control+a+Control, a+a)

No src/ changes; the tests assert current behavior. One observation (not changed here): a trailing + after a valid key is silently dropped (Shift+ parses as just Shift), which may or may not be intended.

Testing

  • npm run build — clean
  • node scripts/test.js tests/utils/keyboard.test.ts tests/tools/input.test.ts — all pass (exit 0)
  • npm run test:no-build — only failures were the known Timeout uninstalling extension flakes in console/extensions/pages; re-ran node scripts/test.js tests/tools/console.test.ts tests/tools/extensions.test.ts tests/tools/pages.test.ts in isolation — all pass (exit 0)
  • npm run check-format — eslint and prettier 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.

Adds dedicated unit tests for parseKey in src/utils/keyboard.ts, which
validates and parses the key input for the press_key tool. Moves the
existing inline parseKey assertions out of tests/tools/input.test.ts
into the new tests/utils/keyboard.test.ts and expands coverage:
modifier ordering, literal plus handling, case sensitivity, whitespace
handling, duplicate keys, error message shapes, and empty input.
@ZayanKhan-12
ZayanKhan-12 force-pushed the chore/tests-keyboard branch from a4145c4 to 66e981f Compare August 8, 2026 21:46
@OrKoN
OrKoN enabled auto-merge August 10, 2026 09:01
@OrKoN
OrKoN added this pull request to the merge queue Aug 10, 2026
Merged via the queue into ChromeDevTools:main with commit 96db054 Aug 10, 2026
19 checks passed
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