Repository navigation
fix(url): pass url().should() when a retry passes - #400
Merged
Merged
Conversation
…aced rules waitForRequest polled the rules every 100ms, so each call waited ~50ms on average after the request had already happened. It now resolves from the worker's EXECUTED message, with the same timeout and error message. A 100ms backstop check stays for rules marked executed any other way (HMR reloads, tests that set the flag), so it is never slower than before. Re-mocking an alias while the first request was still in flight let that late hit mark the new rule as executed, and the next waitForRequest resolved at once with the old request. Each mockRequest call now gives its rule an id, the worker sends it back as ruleId, and the page ignores hits on a replaced rule. Workers without the id keep the old behaviour.
should() kept the error from the first failed attempt and threw it even when a later retry passed, so the retries never helped: any URL assertion that needed one failed. It now returns as soon as an attempt passes. The existing retry test did not await the assertion, which hid the bug. It now awaits it, with a navigation that lands after the first attempt fails.
Base automatically changed from
feat/wait-for-request-events
to
feat/mock-rule-ack
October 18, 2026 18:14
kevinccbsg
added a commit
that referenced
this pull request
Oct 19, 2026
…ms (#398) * feat(mocking): wait for the service worker ack instead of a fixed 100ms mockRequest used to sleep 100ms after posting ADD_RULE, on every call, as a guess at how long the service worker needs to store the rule. It now sends a MessageChannel port with the message and resolves as soon as the worker answers on it: about 1ms per mock, and safe under a slow CPU because it waits for the real confirmation instead of guessing. Workers from before this change never answer. For them mockRequest resolves after 100ms, exactly as before, and warns once per page load to run `npx twd-js init public`. A version mismatch reported by the ack is also warned once, now in the page console, where twd-cli can surface it. mock-sw.js is now built unminified with a header naming the version and how to regenerate it, since users commit and debug this file. The example apps get the regenerated worker. * feat(mocking): resolve waitForRequest on the hit, ignore hits on replaced rules (#399) waitForRequest polled the rules every 100ms, so each call waited ~50ms on average after the request had already happened. It now resolves from the worker's EXECUTED message, with the same timeout and error message. A 100ms backstop check stays for rules marked executed any other way (HMR reloads, tests that set the flag), so it is never slower than before. Re-mocking an alias while the first request was still in flight let that late hit mark the new rule as executed, and the next waitForRequest resolved at once with the old request. Each mockRequest call now gives its rule an id, the worker sends it back as ruleId, and the page ignores hits on a replaced rule. Workers without the id keep the old behaviour. * fix(url): pass url().should() when a retry passes (#400) * feat(mocking): resolve waitForRequest on the hit, ignore hits on replaced rules waitForRequest polled the rules every 100ms, so each call waited ~50ms on average after the request had already happened. It now resolves from the worker's EXECUTED message, with the same timeout and error message. A 100ms backstop check stays for rules marked executed any other way (HMR reloads, tests that set the flag), so it is never slower than before. Re-mocking an alias while the first request was still in flight let that late hit mark the new rule as executed, and the next waitForRequest resolved at once with the old request. Each mockRequest call now gives its rule an id, the worker sends it back as ruleId, and the page ignores hits on a replaced rule. Workers without the id keep the old behaviour. * fix(url): pass url().should() when a retry passes should() kept the error from the first failed attempt and threw it even when a later retry passed, so the retries never helped: any URL assertion that needed one failed. It now returns as soon as an attempt passes. The existing retry test did not await the assertion, which hid the bug. It now awaits it, with a navigation that lands after the first attempt fails. * fix(mocking): wait for a busy worker, let the response render after waitForRequest (#401) Two problems found by running the example apps against the beta. mockRequest gave up on the ack after 100ms and treated the worker as outdated. An up-to-date worker that is busy for a moment can take longer, so the app's request reached it before the rule did and went to the network. Once the worker has acked in this page load, mockRequest now waits up to 2s for it. Until then the 100ms fallback for outdated workers stays. waitForRequest resolved on the worker's EXECUTED message, which the worker sends before it returns the mocked response, so a synchronous query right after it ran before the response had rendered. It now waits two animation frames after the hit (a 16ms timer per frame in a hidden tab). * chore: release 1.12.0-beta.0 * docs: note un-awaited async code in tests as the likely cause of flakiness with 1.12.0-beta.0 * fix: 3s defaults for waitForRequest and url().should(), a throwing afterEach no longer ends the run (#402) Feedback from running the beta on real apps with a throttled CPU. waitForRequest waited 1000ms by default and twd.url().should() 500ms, while findBy* already waits 3000ms. Both were too short for a 2-vCPU CI runner, so both now default to 3000ms (30 attempts 100ms apart). Passing tests are not slower, and explicit retries/retryDelay are respected. An afterEach that threw escaped the test loop and ended the whole run. It now fails that test (retried like any failure) and the run continues. The result is reported after the hooks, so a passing test whose afterEach throws is no longer reported as passed. Docs: waitForRequest guarantees the request happened, not that the UI has updated; put the expected state in findBy* queries; getRequestCount can lag one hit behind the UI. * chore: release 1.12.0-beta.1 * chore: release 1.12.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #399 (
feat/wait-for-request-events), so it ships in the same beta as #398.Bug
twd.url().should()retries up to 5 times, but it kept the error from the first failed attempt and threw it even when a later attempt passed:So the retry only worked when the first attempt already passed, which means it never helped. A URL assertion right after a click that navigates (the case the retry exists for) failed whenever the navigation landed a moment later.
Fix
should()now returns as soon as an attempt passes. When none pass, it throws the last failure as before.Tests
The existing "should retry" test called
should()without awaiting it, which is how the bug went unnoticed. It now awaits it, with a navigation that lands after the first attempt has failed. That test fails on the old code and passes now. Another test covers throwing when no retry passes.Background:
specs/2026-10-18-wait-for-request-polling-design.md(committed in #399), section "Bug:twd.url().should()throws even when a retry passes".