Repository navigation
test: migrate screencast tests off withMcpContext to unit tests - #2683
Conversation
|
Hi @OrKoN, opened #2683 to convert tests/tools/screencast.test.ts off withMcpContext, following the same pattern from #2641/#2665. All 12 tests migrated to createHandlerMocks(), plus a createMockScreenRecorder() helper added to mocks.ts. Full npm test, build, and check-format all passing locally. Ready for your review whenever you get a chance. |
|
Hi @OrKoN |
|
Hi @OrKoN
All 12 tests passing, build/format/docs clean. Pushed as |
|
Hi @OrKoN, thanks for the thorough review on this one - that second round of feedback tightened things up nicely. screencast.test.ts is now fully migrated. Let me know what's next on the list for item (1) whenever you're ready. |
Hi @OrKoN, following up on #2683 and continuing #2639 (item 1), I have opened #2698 to migrate
All verification steps ( |
… tests to McpPage (ChromeDevTools#2698) 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 - References ChromeDevTools#2639 (item 1). - Follow-up building on ChromeDevTools#2641, ChromeDevTools#2665, and ChromeDevTools#2683. - Relocated the 6 real-browser `waitFor` integration tests to a dedicated `waitForTextOnPage()` suite in `tests/McpPage.test.ts` to directly cover the `mcpPage.waitForTextOnPage` method. - Converted all tool handler tests in `tests/tools/snapshot.test.ts` (`take_snapshot` and `wait_for`) to mock unit tests using `createHandlerMocks()`, completely removing `withMcpContext` from the file. - Asserted exact method calls on `response` and `page` using `sinon.assert.calledOnceWithExactly()`. - Maintained `afterEach(() => sinon.restore())` cleanup per `AGENTS.md`. ### 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)
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)
This PR migrates
tests/tools/screencast.test.tsfrom real-browser tests (withMcpContext) to mock-based unit tests using the established Sinon mock infrastructure.Summary
tests/tools/screencast.test.tsto usecreateHandlerMocks()instead ofwithMcpContext(), eliminating real browser launches.createMockScreenRecorder()helper and wiresgetScreenRecorder/setScreenRecorderandensureExtensionintests/mocks.ts.ScreenRecorderfromsrc/third_party/index.tsto comply with internal import boundaries.