Skip to content

Commit

Permalink
Removed duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
skitterm committed Oct 27, 2023
1 parent 019c478 commit ed4b3d4
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions src/cypress-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ed4b3d4

Please sign in to comment.