test(mock): make the delayed-abort test discriminate instead of asserting true - #5763
Open
pacocartones wants to merge 1 commit into
Open
test(mock): make the delayed-abort test discriminate instead of asserting true#5763pacocartones wants to merge 1 commit into
pacocartones wants to merge 1 commit into
Conversation
…ting true The first case in test/mock-delayed-abort.js ended with p.ok(true, 'No uncaught errors after delayed response'), a tautology: the bare MockAgent path throws no uncaught error when a delayed reply is delivered on top of an abort, so the assertion stayed green even against code that dropped the post-abort guards. Verified by reverting the aborted-guards in lib/mock/mock-utils.js — only the composed-interceptor and DecoratorHandler cases failed; this one still passed. Wrap the dispatch handler in a DecoratorHandler that records any onResponseStart/onResponseData/onResponseEnd delivered after onResponseError and assert none occur. It now fails against the reverted guards and passes against real code, covering the full response side of the contract for the bare-agent path (the sibling test asserts only onResponseStart).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5763 +/- ##
=======================================
Coverage 93.50% 93.50%
=======================================
Files 110 110
Lines 39072 39072
=======================================
+ Hits 36534 36535 +1
+ Misses 2538 2537 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
The first test in
test/mock-delayed-abort.jsended with:That assertion is a tautology — it stays green no matter what the code under test does. The bare
MockAgent.requestpath throws no uncaught error when a delayed reply is delivered after an abort, so the test passed even against a fully-broken guard. It documented an intent it never actually enforced: that a mocked reply delivered after the request was aborted must not still be pushed to the handler.What this hardens
The post-abort guards live in
lib/mock/mock-utils.js(the timer-clear on abort plus the twoif (aborted) returnguards inhandleReply). To prove the test now discriminates, I reverted those three guards and re-ran:Previously, test 1 passed in both variants.
The change
The delayed-abort test now wraps the dispatched handler in a
DecoratorHandlersubclass that records anyonResponseStart/onResponseData/onResponseEnddelivered afteronResponseError, and asserts none occur:This covers the full response side of the contract for the bare-agent path — the sibling
DecoratorHandlertest in the same file asserts onlyonResponseStart. Test-only change; no source touched.Verified with the repo runner:
borp -p "test/mock-*.js"→ 339 pass / 0 fail;npm run lint→ clean.