Repository navigation
test: migrate pages handler validation tests to mocks - #2758
dhananjaypai08 wants to merge 1 commit into
Conversation
d137a5e to
1e9a508
Compare
1e9a508 to
aac76f8
Compare
OrKoN
left a comment
There was a problem hiding this comment.
Thanks, let's make the following changes:
-
In
tests/tools/pages.test.ts(the--no-javascript-evaluationtests fornewPageandnavigatePage), rebase onmainand pass{javascriptEvaluation: false}directly tocreateHandlerMocks({javascriptEvaluation: false})instead of parsing CLI flags. Commit #2861 replacedparseArgumentswithConfigParseronmain, causing a rebase conflict, and passing the option directly tocreateHandlerMocksavoids manual argument parsing altogether. -
In
tests/tools/pages.test.ts, destructureargsdirectly fromcreateHandlerMocks()across the migratedlist_pages,newPage, andnavigatePagetests instead of repeatedly callingcreateMockParsedArguments().createHandlerMocks()already initializes and returnsargswith default mock options, making the extracreateMockParsedArguments()invocations redundant.
|
Closing as stale. |
Part of ChromeDevTools#2639. Picks up ChromeDevTools#2758 (closed as stale) and applies the review feedback from it. The `list_pages` handler test and the URL validation tests for `new_page` and `navigate_page` only check that the handler validates its input and stops early, so they don't need a real browser. This migrates them in place to `createHandlerMocks`, following `AGENTS.md`: - `list_pages` › list pages: asserts `setIncludePages(true)`, `setListThirdPartyDeveloperTools()` and `setListWebMcpTools()`. - `new_page` › javascript/data/vbscript URLs, `file:` URLs, unparsable URL, `chrome:`/`chrome-untrusted:` URLs, `chrome-extension:` URLs: assert the exact error and that `context.newPage` is never called, so no tab is opened for a rejected URL. - `navigate_page` › the same five cases: assert the exact error and that `page.pptrPage.goto` is never called. As requested in ChromeDevTools#2758, the flag-dependent cases pass the option directly (`createHandlerMocks({javascriptEvaluation: false})`, `createHandlerMocks({fileNavigations: false})`) instead of parsing CLI flags, and every migrated test destructures `args` from `createHandlerMocks()` instead of calling `createMockParsedArguments()`. The rest of the file still uses the real browser and is unchanged: closed-page recovery, extension pages and service workers, side panels, dialogs, `chrome://newtab/`, background/focus, isolated contexts, history navigation, `beforeunload`, `initScript`, resize and `get_tab_id`. `validateUrl` itself stays covered by `tests/utils/url.test.ts`. **Testing** - `npm run build && NODE_TEST_REPORTER=spec node scripts/test.js tests/tools/pages.test.ts`: 63/63 pass (63 before as well). `list pages` goes from about 650 ms to about 35 ms; the URL validation tests from 35–100 ms to 20–40 ms. - The 11 migrated tests also pass with `PUPPETEER_EXECUTABLE_PATH` pointing at a nonexistent binary, so none of them starts Chrome. - Sanity check that they still catch regressions (each change made all the targeted tests fail, then reverted): - removing `setListWebMcpTools()` from `list_pages` fails `list pages`; - moving `validateUrl` after `context.newPage` in `new_page` fails all five `new_page` cases on `notCalled(context.newPage)`; - passing `javascriptEvaluation`/`fileNavigations` as `undefined` and `categoryExtensions: true` to `validateUrl` fails the javascript, file and chrome-extension cases in both tools; - removing the `validateUrl` call from `navigate_page` fails all five `navigate_page` cases. - `eslint` and `prettier` are clean; only `tests/tools/pages.test.ts` changes.
Refs #2639
Summary
list_pageshandler test and thenew_page/navigate_pageURL validation tests intests/tools/pages.test.tsontocreateHandlerMocks().list_pagesresponse flags (setIncludePages,setListThirdPartyDeveloperTools,setListWebMcpTools) and that rejected URLs never callcontext.newPageorpage.pptrPage.goto.chrome://newtab/, focus, isolated contexts).Test plan
npm run test tests/tools/pages.test.ts -- --test-name-pattern='list pages$|javascript URL|javascript, data, or vbscript|does not parse|chrome: and chrome-untrusted|chrome-extension: URLs unless'PUPPETEER_EXECUTABLE_PATHpointed at a nonexistent binarynpm run test tests/tools/pages.test.tsnpm run format