Repository navigation
test: migrate snapshot tests to unit tests and move waitForTextOnPage tests to McpPage - #2698
Conversation
|
I think we should move existing waitFor tests to McpPage tests covering the waitForTextOnPage method, and on the tool level just test with mocks. |
3d0aca4 to
10a907b
Compare
|
Hi @OrKoN, updated as suggested!
|
… tests to McpPage
e3ba696 to
df7376b
Compare
|
Hi @OrKoN |
|
Hi @OrKoN, I've updated the describe blocks to 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 ( |
7a46acf
|
Hi @OrKoN, snapshot is done now. What would you like tackled next? |
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 in
tests/tools/snapshot.test.tsto mock-based unit tests using the established Sinon mock infrastructure and relocates the real-browser integration tests totests/McpPage.test.ts.Summary
waitForintegration tests to a dedicatedwaitForTextOnPage()suite intests/McpPage.test.tsto directly cover themcpPage.waitForTextOnPagemethod.tests/tools/snapshot.test.ts(take_snapshotandwait_for) to mock unit tests usingcreateHandlerMocks(), completely removingwithMcpContextfrom the file.responseandpageusingsinon.assert.calledOnceWithExactly().afterEach(() => sinon.restore())cleanup perAGENTS.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)