-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { snapshot } from '@chromaui/rrweb-snapshot'; | ||
|
||
// @ts-ignore | ||
Check failure on line 2 in src/cypress-api/commands.ts GitHub Actions / test
|
||
Cypress.Commands.add('takeChromaticArchive', () => { | ||
// @ts-ignore | ||
Check failure on line 4 in src/cypress-api/commands.ts GitHub Actions / test
|
||
cy.document().then((doc) => { | ||
// here, handle the source map | ||
const manualSnapshot = snapshot(doc, { noAbsolute: true }); | ||
// reassign manualSnapshots so it includes this new snapshot | ||
// @ts-ignore | ||
Check failure on line 9 in src/cypress-api/commands.ts GitHub Actions / test
|
||
cy.get('@manualSnapshots') | ||
// @ts-ignore | ||
Check failure on line 11 in src/cypress-api/commands.ts GitHub Actions / test
|
||
.then((snapshots) => { | ||
return [...snapshots, manualSnapshot]; | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,24 @@ const setupNetworkListener = () => { | |
// these "archive" and "manualSnapshots" variables will be available before, during, and after the test, | ||
// then cleaned up before the next test is run | ||
// (see https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Aliases) | ||
// @ts-ignore | ||
Check failure on line 9 in src/cypress-api/support.ts GitHub Actions / test
|
||
cy.wrap({}).as('archive'); | ||
// @ts-ignore | ||
Check failure on line 11 in src/cypress-api/support.ts GitHub Actions / test
|
||
cy.wrap([]).as('manualSnapshots'); | ||
|
||
// since we don't know where the user will navigate, we'll archive whatever domain they're on first. | ||
// @ts-ignore | ||
Check failure on line 15 in src/cypress-api/support.ts GitHub Actions / test
|
||
cy.intercept(`**/*`, (req) => { | ||
// don't archive the page itself -- we'll do that with rrweb | ||
// TODO: See if this will work for both slash and not slash endings or if we have to do same "first URL visited" stuff | ||
if (!pageUrl) { | ||
// @ts-ignore | ||
Check failure on line 20 in src/cypress-api/support.ts GitHub Actions / test
|
||
pageUrl = new URL(req.url); | ||
return; | ||
} | ||
|
||
const url = new URL(req.url); | ||
// @ts-ignore | ||
Check failure on line 26 in src/cypress-api/support.ts GitHub Actions / test
|
||
if (url.origin !== pageUrl.origin) { | ||
return; | ||
} | ||
|
@@ -30,7 +35,9 @@ const setupNetworkListener = () => { | |
// I added this since some css files still are cached... not sure if this is great | ||
// (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304) | ||
delete req.headers['if-modified-since']; | ||
// @ts-ignore | ||
Check failure on line 38 in src/cypress-api/support.ts GitHub Actions / test
|
||
req.continue((response) => { | ||
// @ts-ignore | ||
cy.get('@archive').then((archive) => { | ||
archive[response.url] = { | ||
statusCode: response.statusCode, | ||
|
@@ -43,17 +50,23 @@ const setupNetworkListener = () => { | |
}; | ||
|
||
const completeArchive = () => { | ||
// @ts-ignore | ||
cy.get('@archive').then((archive) => { | ||
// can we be sure this always fires after all the requests are back? | ||
// @ts-ignore | ||
cy.document().then((doc) => { | ||
const snap = snapshot(doc, { noAbsolute: true }); | ||
// @ts-ignore | ||
cy.get('@manualSnapshots').then((manualSnapshots = []) => { | ||
// pass the snapshot to the server to write to disk | ||
// @ts-ignore | ||
cy.task('archiveCypress', { | ||
// @ts-ignore | ||
testTitle: Cypress.currentTest.title, | ||
domSnapshots: [...manualSnapshots, snap], | ||
resourceArchive: archive, | ||
chromaticStorybookParams: { | ||
// @ts-ignore | ||
diffThreshold: Cypress.env('diffThreshold'), | ||
}, | ||
}); | ||
|