Skip to content

Commit

Permalink
Merge branch 'develop' into issue-7638
Browse files Browse the repository at this point in the history
  • Loading branch information
panzarino authored Jun 19, 2020
2 parents 1f17afe + 869bcec commit 6f44bce
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"lodash": "4.17.15",
"log-symbols": "3.0.0",
"minimist": "1.2.5",
"moment": "2.24.0",
"moment": "2.26.0",
"ospath": "1.2.2",
"pretty-bytes": "5.3.0",
"ramda": "0.26.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"mobx": "5.15.4",
"mobx-react": "6.1.8",
"mobx-react-devtools": "6.1.1",
"moment": "2.24.0",
"moment": "2.26.0",
"prop-types": "15.7.2",
"rc-collapse": "1.11.8",
"react": "16.8.6",
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/cypress/fixtures/shadow-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
}
})
}

if (window.location.search.includes('wrap-qsa')) {
const realQuerySelectorAll = document.querySelectorAll;
document.querySelectorAll = function (...args) {
return realQuerySelectorAll.apply(document, args);
};
}
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions packages/driver/cypress/integration/commands/querying_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,12 @@ describe('src/cy/commands/querying', () => {
cy.get('.in-and-out', { includeShadowDom: true })
.should('have.length', 2)
})

// https://github.com/cypress-io/cypress/issues/7676
it('does not error when querySelectorAll is wrapped and snapshots are off', () => {
cy.visit('/fixtures/shadow-dom.html?wrap-qsa=true')
cy.get('.shadow-1', { includeShadowDom: true })
})
})

describe('.log', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ describe('src/cy/commands/traversals', () => {
expect($element[0]).to.eq(el)
})
})

// https://github.com/cypress-io/cypress/issues/7676
it('does not error when querySelectorAll is wrapped and snapshots are off', () => {
cy.visit('/fixtures/shadow-dom.html?wrap-qsa=true')
cy.get('#shadow-element-1').find('.shadow-1', { includeShadowDom: true })
})
})

describe('closest', () => {
Expand Down
28 changes: 28 additions & 0 deletions packages/driver/cypress/integration/commands/xhr_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,34 @@ describe('src/cy/commands/xhr', () => {
expect(resp).to.eq('{ \'bar\' }\n')
})
})

// https://github.com/cypress-io/cypress/issues/7280
it('ignores query params when whitelisting routes', () => {
cy.server()
cy.route(/url-with-query-param/, { foo: 'bar' }).as('getQueryParam')
cy.window().then((win) => {
win.$.get('/url-with-query-param?resource=foo.js')

return null
})

cy.wait('@getQueryParam').its('response.body')
.should('deep.equal', { foo: 'bar' })
})

// https://github.com/cypress-io/cypress/issues/7280
it('ignores hashes when whitelisting routes', () => {
cy.server()
cy.route(/url-with-hash/, { foo: 'bar' }).as('getHash')
cy.window().then((win) => {
win.$.get('/url-with-hash#foo.js')

return null
})

cy.wait('@getHash').its('response.body')
.should('deep.equal', { foo: 'bar' })
})
})

describe('route setup', () => {
Expand Down
21 changes: 21 additions & 0 deletions packages/driver/cypress/integration/cypress/cy_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ describe('driver/src/cypress/cy', () => {
$(doc.body).empty().html(body)
})

// https://github.com/cypress-io/cypress/issues/7731
// NOTE: this must remain the first test in the file
// or it will not properly check for the described issue
context('closing commands', () => {
beforeEach(function () {
this.logs = []

cy.on('log:added', (attrs, log) => {
this.logs.push(log)
})

return null
})

it('properly closes commands', function () {
expect(true).to.be.true
expect(this.logs.length).to.be.equal(1)
expect(this.logs[0].toJSON()).to.have.property('type', 'parent')
})
})

context('hard deprecated private props', () => {
it('throws on accessing props', () => {
const fn = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"minimatch": "3.0.4",
"minimist": "1.2.5",
"mocha": "7.0.1",
"moment": "2.24.0",
"moment": "2.26.0",
"morgan": "1.9.1",
"ordinal": "1.0.3",
"react-15.6.1": "npm:[email protected]",
Expand Down
17 changes: 17 additions & 0 deletions packages/driver/src/cy/commands/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,23 @@ module.exports = (Commands, Cypress, cy, state, config) => {
return
}

// if a user-loaded script redefines document.querySelectorAll and
// numTestsKeptInMemory is 0 (no snapshotting), jQuery thinks
// that document.querySelectorAll is not available (it tests to see that
// it's the native definition for some reason) and doesn't use it,
// which can fail with a weird error if querying shadow dom.
// this ensures that jQuery determines support for document.querySelectorAll
// before user scripts are executed.
// (when snapshotting is enabled, it can achieve the same thing if an XHR
// causes it to snapshot before the user script is executed, but that's
// not guaranteed to happen.)
// https://github.com/cypress-io/cypress/issues/7676
// this shouldn't error, but we wrap it to ignore potential errors
// out of an abundance of caution
try {
cy.$$('body', contentWindow.document)
} catch (e) {} // eslint-disable-line no-empty

const options = _.last(current.get('args'))

return options?.onBeforeLoad?.call(runnable.ctx, contentWindow)
Expand Down
28 changes: 12 additions & 16 deletions packages/driver/src/cy/commands/querying.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,42 +276,38 @@ module.exports = (Commands, Cypress, cy, state) => {
}

const getElements = () => {
// attempt to query for the elements by withinSubject context
// and catch any sizzle errors!
let $el

try {
// only support shadow traversal if we're not searching
// within a subject and have been explicitly told to ignore
// boundaries.
if (!options.includeShadowDom) {
$el = cy.$$(selector, options.withinSubject)
} else {
let scope = options.withinSubject

if (options.includeShadowDom) {
const root = options.withinSubject || cy.state('document')
const elementsWithShadow = $dom.findAllShadowRoots(root)

elementsWithShadow.push(root)

$el = cy.$$(selector, elementsWithShadow)
scope = elementsWithShadow.concat(root)
}

$el = cy.$$(selector, scope)

// jQuery v3 has removed its deprecated properties like ".selector"
// https://jquery.com/upgrade-guide/3.0/breaking-change-deprecated-context-and-selector-properties-removed
// but our error messages use this property to actually show the missing element
// so let's put it back
if ($el.selector == null) {
$el.selector = selector
}
} catch (e) {
e.onFail = () => {
} catch (err) {
// this is usually a sizzle error (invalid selector)
err.onFail = () => {
if (options.log === false) {
return e
return err
}

options._log.error(e)
options._log.error(err)
}

throw e
throw err
}

// if that didnt find anything and we have a within subject
Expand Down
4 changes: 4 additions & 0 deletions packages/driver/src/cypress/cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ const create = function (specWindow, Cypress, Cookies, state, config, log) {
// also reset recentlyReady back to null
state('recentlyReady', null)

// we're finished with the current command
// so set it back to null
state('current', null)

state('subject', subject)

return subject
Expand Down
10 changes: 9 additions & 1 deletion packages/driver/src/cypress/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ const warnOnForce404Default = (obj) => {
}

const whitelist = (xhr) => {
const url = new URL(xhr.url)

// https://github.com/cypress-io/cypress/issues/7280
// we want to strip the xhr's URL of any hash and query params before
// checking the REGEX for matching file extensions
url.search = ''
url.hash = ''

// whitelist if we're GET + looks like we're fetching regular resources
return xhr.method === 'GET' && regularResourcesRe.test(xhr.url)
return xhr.method === 'GET' && regularResourcesRe.test(url.href)
}

const serverDefaults = {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"mocha-7.0.1": "npm:[email protected]",
"mocha-junit-reporter": "1.23.1",
"mocha-teamcity-reporter": "3.0.0",
"moment": "2.24.0",
"moment": "2.26.0",
"morgan": "1.9.1",
"node-machine-id": "1.1.12",
"node-webkit-updater": "cypress-io/node-webkit-updater#e74623726f381487f543e373e71515177a32daeb",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17851,10 +17851,10 @@ module-not-found-error@^1.0.0:
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"
integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=

moment@2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==
moment@2.26.0:
version "2.26.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.26.0.tgz#5e1f82c6bafca6e83e808b30c8705eed0dcbd39a"
integrity sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw==

moment@^2.18.1, moment@^2.19.1, moment@^2.9.0:
version "2.25.3"
Expand Down

0 comments on commit 6f44bce

Please sign in to comment.