Skip to content
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(ClientRequest): spread object args to support "follow-redirects" #541

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ it('handles [RequestOptions, callback] input', () => {
expect(url.href).toEqual('https://mswjs.io/resource')

// Request options must be preserved.
expect(options).toEqual(initialOptions)
expect(options).toMatchObject(initialOptions)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the fix, the actual options object will contain more things, like _defaultAgent. I suppose I good thing!


// Callback must be preserved.
expect(callback).toBeTypeOf('function')
Expand Down Expand Up @@ -320,7 +320,7 @@ it('handles [PartialRequestOptions, callback] input', () => {
)

// Request options must be preserved.
expect(options).toEqual(initialOptions)
expect(options).toMatchObject(initialOptions)

// Options protocol must be inferred from the request issuing module.
expect(options.protocol).toEqual('https:')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function normalizeClientRequestArgs(
// Handle a given "RequestOptions" object as-is
// and derive the URL instance from it.
else if (isObject(args[0])) {
options = args[0] as any
options = { ... args[0] as any }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix.

logger.info('first argument is RequestOptions:', options)

// When handling a "RequestOptions" object without an explicit "protocol",
Expand Down
2 changes: 1 addition & 1 deletion test/third-party/follow-redirect-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ afterAll(async () => {
await server.close()
})

it.skip('intercepts a POST request issued by "follow-redirects"', async () => {
it('intercepts a POST request issued by "follow-redirects"', async () => {
const { address } = server.https
const payload = JSON.stringify({ todo: 'Buy the milk' })

Expand Down
Loading