-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
fix(cloneIncomingMessage): inherit prototype properties #214
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8dde721
fix: improve cloning codes
hrsh7th a8257ef
fix: the ClonedIncomingMessage should be instanceof IncomingMessage
hrsh7th b07a810
fix: remove unneeded generics
hrsh7th 2194fdc
chore(cloneIncomingMessage): check nullable descriptors, add prototyp…
kettanaito e542ff3
chore(cloneIncomingMessage): add jsdoc blocks
kettanaito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 12 additions & 7 deletions
19
src/interceptors/ClientRequest/utils/cloneIncomingMessage.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { Socket } from 'net' | ||
import { IncomingMessage } from 'http' | ||
import { Stream, Readable, EventEmitter } from 'stream' | ||
import { cloneIncomingMessage, IS_CLONE } from './cloneIncomingMessage' | ||
|
||
test('clones a given IncomingMessage', () => { | ||
const source = new IncomingMessage(new Socket()) | ||
source.statusCode = 200 | ||
source.statusMessage = 'OK' | ||
source.headers = { 'x-powered-by': 'msw' } | ||
const clone = cloneIncomingMessage(source) | ||
const message = new IncomingMessage(new Socket()) | ||
message.statusCode = 200 | ||
message.statusMessage = 'OK' | ||
message.headers = { 'x-powered-by': 'msw' } | ||
const clone = cloneIncomingMessage(message) | ||
|
||
// Prototypes must be preserved. | ||
expect(clone).toBeInstanceOf(IncomingMessage) | ||
expect(clone).toBeInstanceOf(EventEmitter) | ||
expect(clone).toBeInstanceOf(Stream) | ||
expect(clone).toBeInstanceOf(Readable) | ||
|
||
expect(clone.statusCode).toEqual(200) | ||
expect(clone.statusMessage).toEqual('OK') | ||
expect(clone.headers).toHaveProperty('x-powered-by', 'msw') | ||
|
||
// Cloned IncomingMessage must be marked respectively. | ||
expect(clone[IS_CLONE]).toEqual(true) | ||
|
||
expect(clone).toHaveProperty('_events') | ||
}) |
This file contains 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
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.
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'm adding assertions to check that the cloned message indeed extends all the prototypes of the original message.