-
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: support snapshots of xhr/fetch and other logs generated from the…
… primary (#21552) * add special serialization rules for snapshot prefix * add failing regression tests * allow for snapshots to delegate to the active spec bridge if applicable * test against consoleProps URL which is more consistent than log url * clean up snapshot tests to set interactive mode in the spec bridge when XHR requests are made, as well as used aliases for requests over arbitrary waits * Update packages/driver/src/cypress/log.ts Co-authored-by: Matt Schile <mschile@cypress.io> * Update packages/driver/src/cypress/log.ts Co-authored-by: Matt Schile <mschile@cypress.io> * chore: fix trailing space Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com> Co-authored-by: Matt Schile <mschile@cypress.io>
- Loading branch information
1 parent
a05b2b6
commit 53f0a02
Showing
8 changed files
with
203 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// import to bind shouldWithTimeout into global cy commands | ||
import '../../../support/utils' | ||
|
||
describe('cy.origin - snapshots', () => { | ||
const findLog = (logMap: Map<string, any>, displayName: string, url: string) => { | ||
return Array.from(logMap.values()).find((log: any) => { | ||
const props = log.get() | ||
|
||
return props.displayName === displayName && (props?.consoleProps?.URL === url || props?.consoleProps()?.URL === url) | ||
}) | ||
} | ||
let logs: Map<string, any> | ||
|
||
beforeEach(() => { | ||
logs = new Map() | ||
|
||
cy.on('log:changed', (attrs, log) => { | ||
logs.set(attrs.id, log) | ||
}) | ||
|
||
cy.fixture('foo.bar.baz.json').then((fooBarBaz) => { | ||
cy.intercept('GET', '/foo.bar.baz.json', { body: fooBarBaz }).as('fooBarBaz') | ||
}) | ||
|
||
cy.visit('/fixtures/primary-origin.html') | ||
cy.get('a[data-cy="xhr-fetch-requests"]').click() | ||
}) | ||
|
||
it('verifies XHR requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { | ||
cy.origin('http://foobar.com:3500', () => { | ||
// need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js | ||
// @ts-ignore | ||
Cypress.config('isInteractive', true) | ||
cy.get(`[data-cy="assertion-header"]`).should('exist') | ||
cy.wait('@fooBarBaz') | ||
}) | ||
|
||
cy.shouldWithTimeout(() => { | ||
const xhrLogFromSecondaryOrigin = findLog(logs, 'xhr', 'http://localhost:3500/foo.bar.baz.json')?.get() | ||
|
||
expect(xhrLogFromSecondaryOrigin).to.not.be.undefined | ||
|
||
const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) | ||
|
||
snapshots.forEach((snapshot) => { | ||
expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes!') | ||
}) | ||
}) | ||
}) | ||
|
||
it('verifies fetch requests made while a secondary origin is active eventually update with snapshots of the secondary origin', () => { | ||
cy.origin('http://foobar.com:3500', () => { | ||
// need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js | ||
// @ts-ignore | ||
Cypress.config('isInteractive', true) | ||
cy.get(`[data-cy="assertion-header"]`).should('exist') | ||
cy.wait('@fooBarBaz') | ||
}) | ||
|
||
cy.shouldWithTimeout(() => { | ||
const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() | ||
|
||
expect(xhrLogFromSecondaryOrigin).to.not.be.undefined | ||
|
||
const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) | ||
|
||
snapshots.forEach((snapshot) => { | ||
expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.have.property('innerText').that.equals('Making XHR and Fetch Requests behind the scenes!') | ||
}) | ||
}) | ||
}) | ||
|
||
it('Does not take snapshots of XHR/fetch requests from secondary origin if the wrong origin is / origin mismatch, but instead the primary origin (existing behavior)', { | ||
pageLoadTimeout: 5000, | ||
}, | ||
(done) => { | ||
cy.on('fail', () => { | ||
const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() | ||
|
||
expect(xhrLogFromSecondaryOrigin).to.not.be.undefined | ||
|
||
const snapshots = xhrLogFromSecondaryOrigin.snapshots.map((snapshot) => snapshot.body.get()[0]) | ||
|
||
snapshots.forEach((snapshot) => { | ||
expect(snapshot.querySelector(`[data-cy="assertion-header"]`)).to.be.null | ||
}) | ||
|
||
done() | ||
}) | ||
|
||
cy.origin('http://barbaz.com:3500', () => { | ||
// need to set isInteractive in the spec bridge in order to take xhr snapshots in run mode, similar to how isInteractive is set within support/defaults.js | ||
// @ts-ignore | ||
Cypress.config('isInteractive', true) | ||
cy.get(`[data-cy="assertion-header"]`).should('exist') | ||
cy.wait('@fooBarBaz') | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<h1 data-cy="assertion-header">Making XHR and Fetch Requests behind the scenes!</h1> | ||
<script> | ||
function fireXHRAndFetchRequests() { | ||
|
||
xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "http://localhost:3500/foo.bar.baz.json"); | ||
xhr.responseType = "json"; | ||
xhr.send(); | ||
|
||
fetch("http://localhost:3500/foo.bar.baz.json") | ||
} | ||
fireXHRAndFetchRequests() | ||
</script> | ||
</body> | ||
</html> |
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
53f0a02
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
53f0a02
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
53f0a02
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
53f0a02
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally:
53f0a02
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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.
Run this command to install the pre-release locally: