From ed4b3d41a4a738d3945beaa9ccc4ea57dbe0c57a Mon Sep 17 00:00:00 2001 From: Steven Kitterman Date: Fri, 27 Oct 2023 14:06:20 -0700 Subject: [PATCH] Removed duplicate code --- src/cypress-api/index.ts | 59 ---------------------------------------- 1 file changed, 59 deletions(-) diff --git a/src/cypress-api/index.ts b/src/cypress-api/index.ts index 687f4487..8bb456c3 100644 --- a/src/cypress-api/index.ts +++ b/src/cypress-api/index.ts @@ -47,65 +47,6 @@ const doArchive = async ({ ); }; -export const setupNetworkListener = () => { - let pageUrl: URL | null = null; - cy.wrap({}).as('archive'); - cy.wrap([]).as('manualSnapshots'); - - // since we don't know where the user will navigate, we'll archive whatever domain they're on first. - 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) { - pageUrl = new URL(req.url); - return; - } - - const url = new URL(req.url); - if (url.origin !== pageUrl.origin) { - return; - } - - // cached (304) responses don't provide a body, so we need to make sure cache is blown away - // (https://glebbahmutov.com/blog/cypress-intercept-problems/#cached-response) - // https://github.com/cypress-io/cypress/issues/15680 - delete req.headers['if-none-match']; - // 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']; - req.continue((response) => { - cy.get('@archive').then((archive) => { - // eslint-disable-next-line no-param-reassign - archive[response.url] = { - statusCode: response.statusCode, - statusText: response.statusMessage, - body: response.body, - }; - }); - }); - }); -}; - -export const completeArchive = () => { - cy.get('@archive').then((archive) => { - // can we be sure this always fires after all the requests are back? - cy.document().then((doc) => { - const snap = snapshot(doc, { noAbsolute: true }); - cy.get('@manualSnapshots').then((manualSnapshots = []) => { - // pass the snapshot to the server to write to disk - cy.task('archiveCypress', { - testTitle: Cypress.currentTest.title, - domSnapshots: [...manualSnapshots, snap], - resourceArchive: archive, - chromaticStorybookParams: { - diffThreshold: Cypress.env('diffThreshold'), - }, - }); - }); - }); - }); -}; - export const archiveCypress = (stuff) => { doArchive(stuff);