Skip to content

feat(testing): pressKey, consoleMessages and expectNoConsoleErrors for an e2e page - #1340

Open
sebyx07 wants to merge 2 commits into
mainfrom
fix/e2e-keys-console
Open

sebyx07 wants to merge 2 commits into
mainfrom
fix/e2e-keys-console

Conversation

@sebyx07

@sebyx07 sebyx07 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Problem

The page an app's e2e test holds (PageLike) has no key presses and no console capture, so an app cannot check keyboard order (Tab, Enter, Escape, shortcuts) or that a page logs no console error. The raw-CDP tab already had press(key), but only for single keys, and nothing reached it from PageLike.

Change (additive)

App-facing, from @ultimat3/testing — free functions over PageLike, because adding required members to PageLike is a public-API break (X_PUBLIC_API_BREAK_UNDECLARED) and optional members would make every call page.press?.(), a silent no-op on a page without it:

Call Does
pressKey(page, key): Promise<void> a trusted key press at the focused element: a PRESS_KEYS name, one letter or digit, or a chord with Alt/Control/Meta/Shift held (Shift+Tab, Control+k, Meta+Shift+Enter)
consoleMessages(page): Promise<readonly E2eConsoleMessage[]> every console.* line and uncaught exception since the running e2eTest began, after one round trip so a line printed just before is included. E2eConsoleMessage = { level: 'debug'|'log'|'info'|'warning'|'error', text, source: 'console'|'exception' }
expectNoConsoleErrors(page): Promise<void> refuses with the new X_E2E_CONSOLE_ERRORS, quoting every error (console.error, failed console.assert, uncaught throw); warnings pass

Underneath:

  • E2eBrowserPage gains optional press?(key) and consoleMessages?() (optional = compatible, as offline? is). A page whose port lacks one, or a PageLike no e2e driver built, is X_TEST_FIXTURE_UNAVAILABLE naming what is missing.
  • cdpE2eTab: press() takes chords (CDP modifiers bitmask; no text typed under Control/Meta/Alt, upper case under Shift); the tab captures Runtime.consoleAPICalled / Runtime.exceptionThrown for its own session and stops listening on close(). New modules cdp-key-chord.ts, cdp-console-capture.ts, e2e-console.ts, e2e-page-input.ts.
  • e2ePage() binds the PageLike to its port (a WeakMap); e2eRunner marks the console start as each test begins, so a suite-shared tab does not carry the previous test's errors.
  • New code X_E2E_CONSOLE_ERRORS registered in e2e-error-codes.ts, rows in wiki/Error-Codes*.md, manifest regenerated.
  • Docs: wiki/Testing.md (example + table), packages/testing/README.md, CHANGELOG (Added).

Tests

  • cdp-e2e-page-input.test.ts (fake connection, written first): chord modifiers and text, unchanged single keys, refusals; console capture filters by session, maps levels and exceptions, close() unsubscribes.
  • e2e-page-input.test.ts: forwarding, refusals by name, test-scoped console with the flush round trip, X_E2E_CONSOLE_ERRORS content.
  • cdp-e2e-page.e2e.test.ts (real Chrome, run locally: 4 pass): Shift+Tab moves focus back, Control+k reaches a keydown with ctrlKey, a console.error and an uncaught throw are captured.

🤖 Generated with Claude Code

sebyx07 and others added 2 commits November 24, 2026 04:09
…r an e2e page

An app's e2e test could not press a key (Tab, Enter, Escape, a shortcut)
or check that the page logged no console error. pressKey(page, key) sends
a trusted key press or chord (Shift+Tab, Control+k); consoleMessages(page)
answers every console line and uncaught exception since the running test
began; expectNoConsoleErrors(page) refuses with X_E2E_CONSOLE_ERRORS.
Free functions over PageLike, which does not grow; E2eBrowserPage gains
optional press?() and consoleMessages?(), and cdpE2eTab implements both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…index regenerated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sebyx07
sebyx07 force-pushed the fix/e2e-keys-console branch from bcf28b6 to bd181a2 Compare November 24, 2026 09:11

This branch has not been deployed

No deployments
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.

1 participant