Skip to content

Commit

Permalink
opt for fixture to point to localhost server when testing xhr/fetch t…
Browse files Browse the repository at this point in the history
…o prevent test dependency on 3rd party resources
  • Loading branch information
AtofStryker committed May 23, 2022
1 parent d0ca3b9 commit 265617f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/driver/cypress/fixtures/xhr-fetch-onload.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ <h1 data-cy="assertion-header">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()
</script>
Expand Down
10 changes: 7 additions & 3 deletions packages/driver/cypress/integration/e2e/origin/snapshots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 265617f

Please sign in to comment.