Skip to content

Commit

Permalink
chore: Verify cy.request() works in multi-domain callback (#20747)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Henkes <mjhenkes@gmail.com>
  • Loading branch information
chrisbreiding and mjhenkes committed Mar 24, 2022
1 parent 90d1eb7 commit ad176be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
// @ts-ignore / session support is needed for visiting about:blank between tests
// FIXME: received cross-origin errors
context.skip('multi-domain network requests', { experimentalSessionSupport: true }, () => {
context('multi-domain network requests', { experimentalSessionSupport: true }, () => {
beforeEach(() => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="request-link"]').click()
})

it('.request()', () => {
it('.request() to secondary domain', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.request('http://www.foobar.com:3500/fixtures/example.json').should((response) => {
expect(response.status).to.equal(200)
expect(response.allRequestResponses[0]['Request URL']).to.equal('http://www.foobar.com:3500/fixtures/example.json')
})
})
})

it('.request() to secondary domain with relative path', () => {
cy.switchToDomain('http://www.foobar.com:3500', () => {
cy.request('/fixtures/example.json').should((response) => {
expect(response.status).to.equal(200)
expect(response.allRequestResponses[0]['Request URL']).to.equal('http://www.foobar.com:3500/fixtures/example.json')
})
})
})

it('.request() to primary domain', () => {
cy.switchToDomain('http://foobar.com:3500', () => {
cy.request('http://localhost:3500/fixtures/example.json').should((response) => {
expect(response.status).to.equal(200)
expect(response.allRequestResponses[0]['Request URL']).to.equal('http://localhost:3500/fixtures/example.json')
})
})
})
Expand Down
7 changes: 6 additions & 1 deletion packages/driver/src/cy/commands/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ export default (Commands, Cypress, cy, state, config) => {
// origin may return an empty string if we haven't visited anything yet
options.url = $Location.normalize(options.url)

const originOrBase = config('baseUrl') || cy.getRemoteLocation('origin')
// If passed a relative url, determine the fully qualified URL to use.
// In the multi-domain version of the driver, we use multiDomainBaseUrl,
// which is set to the origin that is associated with it.
// In the primary driver (where multiDomainBaseUrl is undefined), we
// use the baseUrl or remote origin.
const originOrBase = Cypress.state('multiDomainBaseUrl') || config('baseUrl') || cy.getRemoteLocation('origin')

if (originOrBase) {
options.url = $Location.qualifyWithBaseUrl(originOrBase, options.url)
Expand Down

0 comments on commit ad176be

Please sign in to comment.