Skip to content

test: migrate snapshot tests to unit tests and move waitForTextOnPage tests to McpPage - #2698

Merged
OrKoN merged 2 commits into
ChromeDevTools:mainfrom
maheshsingh20:test/snapshot-unit-tests
Sep 9, 2026
Merged

OrKoN merged 2 commits into
ChromeDevTools:mainfrom
maheshsingh20:test/snapshot-unit-tests

Conversation

@maheshsingh20

@maheshsingh20 maheshsingh20 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

This PR migrates tests in tests/tools/snapshot.test.ts to mock-based unit tests using the established Sinon mock infrastructure and relocates the real-browser integration tests to tests/McpPage.test.ts.

Summary

Verification

  • npm run test tests/tools/snapshot.test.ts (4 passed, 0 failed, exit code: 0)
  • npm run test tests/McpPage.test.ts (39 passed, 0 failed, exit code: 0)
  • npm run check-format (exit code: 0)
  • npm run docs:generate (exit code: 0)
  • git status (clean working tree, exit code: 0)

@OrKoN

OrKoN commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

I think we should move existing waitFor tests to McpPage tests covering the waitForTextOnPage method, and on the tool level just test with mocks.

@maheshsingh20
maheshsingh20 force-pushed the test/snapshot-unit-tests branch from 3d0aca4 to 10a907b Compare September 8, 2026 14:09
@maheshsingh20 maheshsingh20 changed the title test: migrate takeSnapshot tests off withMcpContext to unit tests test: migrate snapshot tests to unit tests and move waitForTextOnPage tests to McpPage Sep 8, 2026
@maheshsingh20

Copy link
Copy Markdown
Contributor Author

Hi @OrKoN, updated as suggested!

  • Moved the 6 waitFor integration tests to a new waitForTextOnPage() suite in tests/McpPage.test.ts to test the method directly on McpPage.
  • Converted all tests in tests/tools/snapshot.test.ts to mock-based unit tests using createHandlerMocks(), removing withMcpContext from that file completely.
  • Verified both test suites (snapshot.test.ts and McpPage.test.ts) and formatting checks pass cleanly. PTAL!

@OrKoN
OrKoN self-requested a review September 8, 2026 14:33
Comment thread tests/tools/snapshot.test.ts Resolved
@maheshsingh20
maheshsingh20 force-pushed the test/snapshot-unit-tests branch from e3ba696 to df7376b Compare September 8, 2026 15:44
@maheshsingh20

Copy link
Copy Markdown
Contributor Author

Hi @OrKoN
Done! Renamed browser_snapshot to take_snapshot and browser_wait_for to wait_for to match the current tool names.

@maheshsingh20

Copy link
Copy Markdown
Contributor Author

Hi @OrKoN, I've updated the describe blocks to take_snapshot and wait_for as requested!

Regarding the CI failure: all our snapshot and McpPage tests passed across all platforms. The single failing check is the known flaky test on Windows CI (WaitForHelper.test.ts:43:5 - awaits navigation when action takes longer than expectNavigationIn), which passed on Node 22/24 but flaked on Node 26. Could you please re-run that failed job?

@OrKoN
OrKoN added this pull request to the merge queue Sep 9, 2026
Merged via the queue into ChromeDevTools:main with commit 7a46acf Sep 9, 2026
28 of 30 checks passed
@maheshsingh20
maheshsingh20 deleted the test/snapshot-unit-tests branch September 9, 2026 09:59
@maheshsingh20

Copy link
Copy Markdown
Contributor Author

Hi @OrKoN, snapshot is done now. What would you like tackled next?

@OrKoN

OrKoN commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

pull Bot pushed a commit to Pet3cy/chrome-devtools-mcp that referenced this pull request Sep 11, 2026
This PR migrates the mock-eligible test in
`tests/tools/extensions.test.ts` from a real-browser test
(`withMcpContext`) to a mock-based unit test using the established Sinon
mock infrastructure.

### Architectural Principle (Category 1 vs. Category 2 Split)
This PR continues issue ChromeDevTools#2639 (item 1), applying the core architectural
separation of concerns established across ChromeDevTools#2641, ChromeDevTools#2665, ChromeDevTools#2683, and
ChromeDevTools#2698:

- **Category 1 (Handler wiring & response verification -> Mock unit
tests)**:
Tests that only verify tool parameter parsing and response manipulation
should not launch real browsers. Launching Chrome just to assert that a
tool invoked `response.setListExtensions()` introduces unnecessary
startup latency and lifecycle flakiness without providing real
integration coverage. These are converted to deterministic unit tests
using `createHandlerMocks()`.

- **Category 2 (Genuine browser, extension, and protocol behavior ->
Retained real-browser tests)**:
Tests that depend on genuine browser mechanics must remain in
`withMcpContext`. Mocking them would require simulating Chrome's
internal extension loader, V8 script execution, or Puppeteer's target
lifecycle inside mocks, creating brittle and artificial tests that do
not validate real behavior.

### Summary of Changes
- **Converted to mocks (Category 1)**:
- `lists installed extensions`: Converted to `createHandlerMocks()`.
Asserts `response.setListExtensions` was invoked with
`sinon.assert.calledOnceWithExactly(response.setListExtensions)`.
- **Intentionally retained as real-browser tests (Category 2)**:
- `installs and uninstalls an extension and verifies it in
chrome://extensions`: Genuinely installs an unpacked extension into
Chrome and verifies real extension lifecycle and management.
- `reloads an extension`: Verifies Chrome's live extension reload
mechanics and registry reappearance.
- `triggers an extension action`: Validates asynchronous Puppeteer
`Target` creation when an extension action fires.
- `verifies that content script console logs are received`: Tests real
content script execution in a live navigated page and CDP console
capture.

### Verification
- `powershell -Command "Remove-Item -Recurse -Force build -ErrorAction
SilentlyContinue"; npm run build` (exit code: 0)
- `node scripts/test.js tests/tools/extensions.test.ts` (6 passed, 0
failed, exit code: 0)
- `npm run check-format` (exit code: 0)
- `npm run docs:generate` (exit code: 0)
- `git status` (clean working tree, exit code: 0)
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.

2 participants