From 265617f3cc22efee3930339bf6ba200174ca8d57 Mon Sep 17 00:00:00 2001 From: Bill Glesias Date: Mon, 23 May 2022 09:37:54 -0400 Subject: [PATCH] opt for fixture to point to localhost server when testing xhr/fetch to prevent test dependency on 3rd party resources --- packages/driver/cypress/fixtures/xhr-fetch-onload.html | 4 ++-- .../cypress/integration/e2e/origin/snapshots.spec.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/driver/cypress/fixtures/xhr-fetch-onload.html b/packages/driver/cypress/fixtures/xhr-fetch-onload.html index 5e921de67091..65fa87ea0cc4 100644 --- a/packages/driver/cypress/fixtures/xhr-fetch-onload.html +++ b/packages/driver/cypress/fixtures/xhr-fetch-onload.html @@ -6,11 +6,11 @@

Making XHR and Fetch Requests behind the scenes!< function fireXHRAndFetchRequests() { xhr = new XMLHttpRequest(); - xhr.open("GET", "https://jsonplaceholder.cypress.io/todos/1"); + xhr.open("GET", "http://localhost:3500/foo.bar.baz.json"); xhr.responseType = "json"; xhr.send(); - fetch("https://jsonplaceholder.cypress.io/todos/1") + fetch("http://localhost:3500/foo.bar.baz.json") } fireXHRAndFetchRequests() diff --git a/packages/driver/cypress/integration/e2e/origin/snapshots.spec.ts b/packages/driver/cypress/integration/e2e/origin/snapshots.spec.ts index f1d56ccd2a77..d5ab7dd9fd67 100644 --- a/packages/driver/cypress/integration/e2e/origin/snapshots.spec.ts +++ b/packages/driver/cypress/integration/e2e/origin/snapshots.spec.ts @@ -18,6 +18,10 @@ describe('cy.origin - snapshots', () => { logs.set(attrs.id, log) }) + cy.fixture('foo.bar.baz.json').then((fooBarBaz) => { + cy.intercept('GET', '/foo.bar.baz.json', { body: fooBarBaz }) + }) + cy.visit('/fixtures/primary-origin.html') cy.get('a[data-cy="xhr-fetch-requests"]').click() }) @@ -30,7 +34,7 @@ describe('cy.origin - snapshots', () => { }) cy.shouldWithTimeout(() => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'xhr', 'https://jsonplaceholder.cypress.io/todos/1')?.get() + const xhrLogFromSecondaryOrigin = findLog(logs, 'xhr', 'http://localhost:3500/foo.bar.baz.json')?.get() expect(xhrLogFromSecondaryOrigin).to.not.be.undefined @@ -50,7 +54,7 @@ describe('cy.origin - snapshots', () => { }) cy.shouldWithTimeout(() => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'https://jsonplaceholder.cypress.io/todos/1')?.get() + const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() expect(xhrLogFromSecondaryOrigin).to.not.be.undefined @@ -67,7 +71,7 @@ describe('cy.origin - snapshots', () => { }, (done) => { cy.on('fail', () => { - const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'https://jsonplaceholder.cypress.io/todos/1')?.get() + const xhrLogFromSecondaryOrigin = findLog(logs, 'fetch', 'http://localhost:3500/foo.bar.baz.json')?.get() expect(xhrLogFromSecondaryOrigin).to.not.be.undefined