fix(browser-playwright): clear stale mock routes for duplicate URLs#10040
fix(browser-playwright): clear stale mock routes for duplicate URLs#10040teee32 wants to merge 1 commit intovitest-dev:mainfrom
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Looks like CI is failing with new tests. Can you look into it? |
|
I checked the failed jobs. They all timed out on the new browser mocking regression test, but I couldn't reproduce that timeout locally on the current HEAD. I reran the closest commands serially with the full Playwright browser matrix and they passed:\n\n- \n- \n- \n- \ (the new mocking test passed there as well)\n\nI don't have permission to rerun the upstream Actions jobs from the fork, so the next useful step is probably to rerun the failed browser jobs once to see if the timeout reproduces on CI. |
|
I checked the failed jobs. They all timed out on the new browser mocking regression test, but I couldn't reproduce that timeout locally on the current HEAD. I reran the closest commands serially with the full Playwright browser matrix and they passed:
I don't have permission to rerun the upstream Actions jobs from the fork, so the next useful step is probably to rerun the failed browser jobs once to see if the timeout reproduces on CI. |
Description
Problem
When two mocked ids resolve to the same module URL in Browser Mode, the Playwright provider registers two routes for the same logical module but only keeps the latest predicate reference. Cleanup then removes only the last route, so an older manual mock can leak into the next spec file.
Reproduction / Observation
Resolves #9957.
The new
test/browser/fixtures/manual-mock-alias-leakfixture reproduces this with two spec files:probe.spec.tsregisters manual mocks for~/modaland./modal, which both resolve to the same file.target.spec.tsimports~/modalwithout mocking it.Before this change, the second spec could hit a stale route from the first spec and fail with
[birpc] rpc is closed, cannot call "resolveManualMock".Root cause
packages/browser-playwright/src/playwright.tstracks predicates bysessionId:url, but duplicate registrations for the same resolved URL overwrite the stored predicate while leaving the previous Playwright route installed.delete()andclear()can then only unroute the latest handler, so the earlier manual mock survives into the next file.Change
Setinstead of an arrayWhy this fix
The provider already treats
sessionId + resolved URLas the identity for a mock route. Replacing any existing route for that identity is the smallest change that makes cleanup reliable without changing mock resolution semantics.Risk
The change is limited to Playwright Browser Mode route bookkeeping. It only affects duplicate registrations for the same resolved URL within one session; other providers and non-duplicate routes are unchanged.
Validation
pnpm --filter @vitest/browser-playwright run buildBROWSER=chromium pnpm -C test/browser run test-fixtures --root ./fixtures/manual-mock-alias-leakBROWSER=chromium pnpm -C test/browser exec vitest --no-watch --config=vitest.config.unit.mts specs/mocking.test.ts -t "manual mocks do not leak across browser spec files when the same module is mocked via different ids"BROWSER=chromium pnpm -C test/browser exec vitest --no-watch --config=vitest.config.unit.mts specs/mocking.test.tspnpm exec eslint --no-warn-ignored packages/browser-playwright/src/playwright.ts test/browser/specs/mocking.test.tsPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
Changesets
feat:,fix:,perf:,docs:, orchore:.