-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only update content-length header if one was present in spy (#25920
) Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com> Co-authored-by: Bill Glesias <bglesias@gmail.com>
- Loading branch information
1 parent
5f48d3c
commit 2452dee
Showing
5 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
80 changes: 80 additions & 0 deletions
80
packages/net-stubbing/test/unit/middleware-request-spec.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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { InterceptRequest } from '../../lib/server/middleware/request' | ||
import { state as NetStubbingState } from '../../lib/server/state' | ||
|
||
describe('request', () => { | ||
context('InterceptedRequest', () => { | ||
// @see https://github.com/cypress-io/cypress/issues/24407 | ||
it('does not set the content-length header if the header was not there to begin with on the original request', async () => { | ||
const socket = { | ||
toDriver: sinon.stub(), | ||
} | ||
const state = NetStubbingState() | ||
|
||
const beforeRequestData = { | ||
body: 'stubbed_body', | ||
proxiedUrl: 'https://foobar.com', | ||
url: 'https://foobar.com', | ||
} | ||
|
||
const afterRequestData = { | ||
...beforeRequestData, | ||
body: '', | ||
headers: {}, | ||
} | ||
|
||
// using a ES6 proxy to intercept the promise assignment on pendingEventHandlers. | ||
// this way, we can resolve the event immediately | ||
const pendingEventProxy = new Proxy(state.pendingEventHandlers, { | ||
get (target, prop, receiver) { | ||
// @ts-expect-error | ||
return Reflect.get(...arguments) | ||
}, | ||
set (obj, prop, value) { | ||
// @ts-expect-error | ||
const setProp = Reflect.set(...arguments) | ||
|
||
// invoke the promise function immediately | ||
if (typeof value === 'function') { | ||
value({ | ||
changedData: afterRequestData, | ||
stopPropagation: false, | ||
}) | ||
} | ||
|
||
return setProp | ||
}, | ||
}) | ||
|
||
state.pendingEventHandlers = pendingEventProxy | ||
|
||
const request = { | ||
req: { | ||
...beforeRequestData, | ||
headers: {}, | ||
matchingRoutes: [ | ||
{ | ||
id: '1', | ||
hasInterceptor: true, | ||
routeMatcher: {}, | ||
}, | ||
], | ||
pipe: sinon.stub(), | ||
}, | ||
res: { | ||
once: sinon.stub(), | ||
}, | ||
socket, | ||
debug: sinon.stub(), | ||
netStubbingState: state, | ||
next: sinon.stub(), | ||
onError: sinon.stub(), | ||
onResponse: sinon.stub(), | ||
} | ||
|
||
await InterceptRequest.call(request) | ||
expect(request.req.headers['content-length']).to.be.undefined | ||
}) | ||
}) | ||
}) |
2452dee
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.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2452dee
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.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2452dee
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.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2452dee
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.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
2452dee
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.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: