-
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.
Use websockets to stub large XHR response bodies instead of hea… (#5525)
* server: add test for XHR with body > 100kb via CLI * Use websockets to stub large XHR response bodies instead of headers * Properly cleanup outstanding XHRs on before:test:run * Add lil unit test for xhr_ws_server * Use reset:xhr:server to get around sending entire test:before:run:async payload * Responding to feedback * Implement feedback * move data obj wrapping into xhrs controller
- Loading branch information
1 parent
e405d8a
commit 249db45
Showing
11 changed files
with
245 additions
and
30 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import _ from 'lodash' | ||
import Bluebird from 'bluebird' | ||
import debugModule from 'debug' | ||
|
||
const debug = debugModule('cypress:server:xhr_ws_server') | ||
|
||
function trunc (str) { | ||
return _.truncate(str, { | ||
length: 100, | ||
omission: '... [truncated to 100 chars]', | ||
}) | ||
} | ||
|
||
type DeferredPromise<T> = { | ||
resolve: Function | ||
reject: Function | ||
promise: Bluebird<T> | ||
} | ||
|
||
export function create () { | ||
let incomingXhrResponses: { | ||
[key: string]: string | DeferredPromise<string> | ||
} = {} | ||
|
||
function onIncomingXhr (id: string, data: string) { | ||
debug('onIncomingXhr %o', { id, res: trunc(data) }) | ||
const deferred = incomingXhrResponses[id] | ||
|
||
if (deferred && typeof deferred !== 'string') { | ||
// request came before response, resolve with it | ||
return deferred.resolve(data) | ||
} | ||
|
||
// response came before request, cache the data | ||
incomingXhrResponses[id] = data | ||
} | ||
|
||
function getDeferredResponse (id) { | ||
debug('getDeferredResponse %o', { id }) | ||
// if we already have it, send it | ||
const res = incomingXhrResponses[id] | ||
|
||
if (res) { | ||
if (typeof res === 'object') { | ||
debug('returning existing deferred promise for %o', { id, res }) | ||
|
||
return res.promise | ||
} | ||
|
||
debug('already have deferred response %o', { id, res: trunc(res) }) | ||
delete incomingXhrResponses[id] | ||
|
||
return res | ||
} | ||
|
||
let deferred: Partial<DeferredPromise<string>> = {} | ||
|
||
deferred.promise = new Bluebird((resolve, reject) => { | ||
debug('do not have response, waiting %o', { id }) | ||
deferred.resolve = resolve | ||
deferred.reject = reject | ||
}) | ||
.tap((res) => { | ||
debug('deferred response found %o', { id, res: trunc(res) }) | ||
}) as Bluebird<string> | ||
|
||
incomingXhrResponses[id] = deferred as DeferredPromise<string> | ||
|
||
return deferred.promise | ||
} | ||
|
||
function reset () { | ||
debug('resetting incomingXhrs %o', { incomingXhrResponses }) | ||
|
||
_.forEach(incomingXhrResponses, (res) => { | ||
if (typeof res !== 'string') { | ||
const err: any = new Error('This stubbed XHR was pending on a stub response object from the driver, but the test ended before that happened.') | ||
|
||
err.testEndedBeforeResponseReceived = true | ||
|
||
res.reject(err) | ||
} | ||
}) | ||
|
||
incomingXhrResponses = {} | ||
} | ||
|
||
return { | ||
onIncomingXhr, | ||
getDeferredResponse, | ||
reset, | ||
} | ||
} |
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
Oops, something went wrong.
249db45
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.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.249db45
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.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.249db45
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.
AppVeyor has built the
win32 x64
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.249db45
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.
AppVeyor has built the
win32 ia32
version of the Test Runner.You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.
You will need to use custom
CYPRESS_INSTALL_BINARY
url and install Cypress using an url instead of the version.