-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: draft: adds a onMissedRequest hook for seeing missed mocks #2682
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2682 +/- ##
==========================================
- Coverage 85.54% 85.39% -0.16%
==========================================
Files 76 84 +8
Lines 6858 7544 +686
==========================================
+ Hits 5867 6442 +575
- Misses 991 1102 +111 ☔ View full report in Codecov by Sentry. |
```js | ||
import { MockAgent } from 'undici' | ||
|
||
const mockAgent = new MockAgent({ onMissedRequest: (error) => console.log(`A request wasn't handled: ${error.message}`) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea pretty much, but not sure if it should be applied to the Agent
. Have you considered the interceptor instead?
In that way, I imagine a usage like:
mockPool.intercept({
path: '/justatest?hello=there&see=ya',
method: 'GET'
}).reply(200, { wont: 'match' }, {
headers: { 'content-type': 'application/json' }
// being response the object passed through the intercept
}).onNotMatched((request, response) => console.log(request, response))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like this usage instead as well. Any potential downsides to this syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you pass the request that was missed to the callback?
@mcollina Good idea. We'd want both the request and the error, right? My argument for the error is that the reasoning is baked into the Also - How do you feel about @metcoder95's alternative syntax? |
SGTM, feel free to add it 🚀 |
@James1x0 sorry for the delay. I prefer @metcoder95 syntax. |
This relates to...
#2681
Rationale
To enable easier debugging of the mockagent, as discussed in #1600
Changes
Features
Bug Fixes
No bugs fixed
Breaking Changes and Deprecations
No breaking changes or deprecations
Status