Skip to content

Commit

Permalink
fix: do not throw if location is an empty string (#16772)
Browse files Browse the repository at this point in the history
* do not throw if location is an empty string

* add a test
  • Loading branch information
bahmutov committed Jun 4, 2021
1 parent 3ad72ba commit 03e2197
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/driver/cypress/integration/commands/location_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ describe('src/cy/commands/location', () => {
cy.location().should('have.property', 'pathname').and('match', /users/)
})

// https://github.com/cypress-io/cypress/issues/16463
it('eventually returns a given key', function () {
cy.stub(cy, 'getRemoteLocation')
.onFirstCall().returns('')
.onSecondCall().returns({
pathname: '/my/path',
})

cy.location('pathname').should('equal', '/my/path')
.then(() => {
expect(cy.getRemoteLocation).to.have.been.calledTwice
})
})

describe('assertion verification', () => {
beforeEach(function () {
cy.on('log:added', (attrs, log) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/driver/src/cy/commands/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ module.exports = (Commands, Cypress, cy) => {
const getLocation = () => {
const location = cy.getRemoteLocation()

if (location === '') {
// maybe the page's domain is "invisible" to us
// and we cannot get the location. Return null
// so the command keeps retrying, maybe there is
// a redirect that puts us on the domain we can access
return null
}

return _.isString(key)
// use existential here because we only want to throw
// on null or undefined values (and not empty strings)
Expand Down
2 changes: 2 additions & 0 deletions packages/driver/src/cy/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const create = (state) => {

return location
} catch (e) {
// it is possible we do not have access to the location
// for example, if the app has redirected to a 2nd domain
return ''
}
},
Expand Down

3 comments on commit 03e2197

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 03e2197 Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.5.0/circle-develop-03e2197d9f386e7ec70e7f9a5f15d2e287098cbd/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 03e2197 Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.5.0/appveyor-develop-03e2197d9f386e7ec70e7f9a5f15d2e287098cbd/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 03e2197 Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.5.0/appveyor-develop-03e2197d9f386e7ec70e7f9a5f15d2e287098cbd/cypress.tgz

Please sign in to comment.