-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #312 +/- ##
======================================
Coverage ? 84.95%
======================================
Files ? 55
Lines ? 2220
Branches ? 564
======================================
Hits ? 1886
Misses ? 334
Partials ? 0
Continue to review full report at Codecov.
|
Improve React Native. Fix tests. Fix tests more. Fix browser export. Add new package. Work on fetch-mitm. More work. Extract algorithm part. Rename package as unmock-fetch. Revert changes to unmock. More clean-up. Fix a bug in response body. Remove console.logs. More clean-up. Use types from unmock-core. Refactor types. Add tests, remove algorithm. Clean-up. Remove unused deps. Remove unnecessary test.
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.
Looks good;
Just out of curiosity - couldn't we have used cross-fetch
immediately instead of fetch
?
}, | ||
"dependencies": { | ||
"@types/debug": "^4.1.5", | ||
"@types/url-parse": "^1.4.3", |
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.
Should debug
and its @types
be part of the dependencies? (and not dev dependencies?)
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.
Yes, a library should include the types it uses.
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.
Of course, but debug
is not a dependency. The code doesn't need it to function properly, so shouldn't it be part of dev dependencies?
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.
But debug
is a dependency of unmock-fetch
:) It's true that user's type-checking probably would pass fine even if @types/debug
wasn't part of the dependencies, but I think it's generally just bad practice to leave out the types. We've had two breakages in releases already because of leaving out types for sinon
and node-fetch
, requiring users to manually add the types.
let fetch: Fetch; | ||
} | ||
|
||
let mitm: Mitm | undefined; |
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.
Is this the same mitm
we have in the backend?
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.
No, the Mitm
is a new class defined in the same file.
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 see that, but it seems you tried to maintain the same interface, hence the question. It's a bit misleading IMO to have two Mitm
classes with different purposes.
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.
Yeah I can rename it if it makes development simpler for us. But in general users of this would not know anything about node-mitm
and its API so I just picked a short name that makes it clear what it does. I can call it FetchInterceptor
or something.
Hmm, I don't see what you mean by "couldn't we have used |
Or if you mean the |
Yup, meant this :) |
unmock-fetch
package for intercepting calls toglobal.fetch
orwindow.fetch
buildFetch
that takes in a callback function of typeOnSerializedRequest
const fetch = buildFetch(onSerializedRequest)
or withUnmockFetch.on(onSerializedRequest); ... UnmockFetch.off();
. The latter patchesglobal.fetch
orwindow.fetch
.OnSerializedRequest
tointerfaces.ts
inunmock-core
so it can importedTODO:
unmock-core/dist/interfaces
. Importing fromunmock-core
is not possible at the moment as it imports a lot of Node.js related stuff and that would break in React Native