Skip to content

Commit

Permalink
Merge branch 'develop' into v5.0-release
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann authored Jun 29, 2020
2 parents 5da2493 + 715d07c commit 8c998f1
Show file tree
Hide file tree
Showing 42 changed files with 1,417 additions and 2,562 deletions.
24 changes: 24 additions & 0 deletions packages/driver/cypress/fixtures/isolated-runner-inner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Isolated Runner Fixture</title>
</head>
<body>
<div>
<button class="trigger-sync-error">Trigger Sync Error</button>
<button class="trigger-async-error">Trigger Async Error</button>
</div>

<script>
document.querySelector(".trigger-sync-error").addEventListener('click', function () {
syncReference.error()
})

document.querySelector(".trigger-async-error").addEventListener('click', function () {
setTimeout(function () {
asyncReference.error()
})
})
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -3711,7 +3711,8 @@ describe('shadow dom', () => {
it('does not hang when experimentalShadowDomSupport is false and clicking on custom element', () => {
Cypress.config('experimentalShadowDomSupport', false)
// needs some size or it's considered invisible and click will fail its prerequisites
cy.$$('#shadow-element-1').css({ padding: 2 })
// so we make it display: block so its getClientRects() contains only a single
cy.$$('#shadow-element-1').css({ display: 'block' })

cy.get('#shadow-element-1').click()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3051,7 +3051,7 @@ describe('src/cy/commands/actions/type - #type', () => {
const spyTableName = cy.spy(top.console, 'groupCollapsed')
const spyTableData = cy.spy(top.console, 'table')

const commandLogEl = getCommandLogWithText('foo')
const commandLogEl = getCommandLogWithText('foo', 'message-text')

const reactCommandInstance = findReactInstance(commandLogEl[0])

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/cypress/integration/e2e/dom_hitbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const ensureCorrectHighlightPositions = (sel) => {
const getAndPin = (sel) => {
cy.get(sel)

clickCommandLog(sel)
clickCommandLog(sel, 'message-text')
}

const clickAndPin = (sel, ...args) => {
Expand Down
13 changes: 5 additions & 8 deletions packages/driver/cypress/support/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const { $, _, Promise } = Cypress

export const getCommandLogWithText = (text) => {
export const getCommandLogWithText = (command, type = 'method') => {
// Open current test if not already open, so we can find the command log
cy.$$('.runnable-active .runnable-wrapper:not(.is-open)', top.document).click()

return cy
.$$(`.runnable-active .command-wrapper:contains(${text})`, top.document)
.parentsUntil('li')
.last()
.parent()
.$$(`.runnable-active .command-${type}:contains(${command})`, top.document)
.closest('.command')
}

export const findReactInstance = function (dom) {
Expand All @@ -22,12 +20,11 @@ export const findReactInstance = function (dom) {
: internalInstance.return.stateNode
}

export const clickCommandLog = (sel) => {
export const clickCommandLog = (sel, type) => {
return cy.wait(10)
.then(() => {
return withMutableReporterState(() => {
const commandLogEl = getCommandLogWithText(sel)

const commandLogEl = getCommandLogWithText(sel, type)
const reactCommandInstance = findReactInstance(commandLogEl[0])

if (!reactCommandInstance) {
Expand Down
2 changes: 2 additions & 0 deletions packages/driver/src/cy/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const create = (state, config, log) => {
snapshot: true,
error: err,
consoleProps () {
if (!current) return

const obj = {}
const prev = current.get('prev')

Expand Down
10 changes: 9 additions & 1 deletion packages/driver/src/dom/coordinates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash')
const $window = require('./window')
const $elements = require('./elements')

Expand All @@ -7,6 +8,13 @@ const getElementAtPointFromViewport = (doc, x, y) => {

const isAutIframe = (win) => !$elements.getNativeProp(win.parent, 'frameElement')

const getFirstValidSizedRect = (el) => {
return _.find(el.getClientRects(), (rect) => {
// use the first rect that has a nonzero width and height
return rect.width && rect.height
}) || el.getBoundingClientRect() // otherwise fall back to the parent client rect
}

/**
* @param {JQuery<HTMLElement>} $el
*/
Expand All @@ -32,7 +40,7 @@ const getElementPositioning = ($el) => {
// returns a zero length DOMRectList in that case, which becomes undefined.
// so we fallback to getBoundingClientRect() so that we get an actual DOMRect
// with all properties 0'd out
const rect = [...el.getClientRects()].find((e) => e.width && e.height) || el.getBoundingClientRect()
const rect = getFirstValidSizedRect(el)

// we want to return the coordinates from the autWindow to the element
// which handles a situation in which the element is inside of a nested
Expand Down
15 changes: 15 additions & 0 deletions packages/runner/cypress/fixtures/errors/assertions_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './setup'

describe('assertion failures', () => {
it('with expect().<foo>', () => {
expect('actual').to.equal('expected')
})

it('with assert()', () => {
assert(false, 'should be true')
})

it('with assert.<foo>()', () => {
assert.equal('actual', 'expected')
})
})
11 changes: 11 additions & 0 deletions packages/runner/cypress/fixtures/errors/commands_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './setup'

describe('commands', { defaultCommandTimeout: 0 }, () => {
it('failure', () => {
cy.get('#does-not-exist')
})

it('chained failure', () => {
cy.get('body').find('#does-not-exist')
})
})
27 changes: 27 additions & 0 deletions packages/runner/cypress/fixtures/errors/custom_commands_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import './setup'

Cypress.Commands.add('failAssertion', () => {
expect('actual').to.equal('expected')
})

Cypress.Commands.add('failException', () => {
({}).bar()
})

Cypress.Commands.add('failCommand', () => {
cy.get('#does-not-exist')
})

describe('custom commands', { defaultCommandTimeout: 0 }, () => {
it('assertion failure', () => {
cy.failAssertion()
})

it('exception', () => {
cy.failException()
})

it('command failure', () => {
cy.failCommand()
})
})
13 changes: 13 additions & 0 deletions packages/runner/cypress/fixtures/errors/docs_url_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './setup'

describe('docs url', () => {
it('displays as button in interactive mode', () => {
Cypress.config('isInteractive', true)
cy.viewport()
})

it('is text in error message in run mode', () => {
Cypress.config('isInteractive', false)
cy.viewport()
})
})
21 changes: 21 additions & 0 deletions packages/runner/cypress/fixtures/errors/each_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import './setup'

describe('cy.each', { defaultCommandTimeout: 0 }, () => {
it('assertion failure', () => {
cy.wrap([1]).each(() => {
expect('actual').to.equal('expected')
})
})

it('exception', () => {
cy.wrap([1]).each(() => {
({}).bar()
})
})

it('command failure', () => {
cy.wrap([1]).each(() => {
cy.get('#does-not-exist')
})
})
})
35 changes: 35 additions & 0 deletions packages/runner/cypress/fixtures/errors/events_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import './setup'

describe('event handlers', { defaultCommandTimeout: 0 }, () => {
it('event assertion failure', () => {
cy.on('window:load', () => {
expect('actual').to.equal('expected')
})

cy.visit('http://localhost:1919')
})

it('event exception', () => {
cy.on('window:load', () => {
({}).bar()
})

cy.visit('http://localhost:1919')
})

it('fail handler assertion failure', () => {
cy.on('fail', () => {
expect('actual').to.equal('expected')
})

cy.get('#does-not-exist')
})

it('fail handler exception', () => {
cy.on('fail', () => {
({}).bar()
})

cy.get('#does-not-exist')
})
})
13 changes: 13 additions & 0 deletions packages/runner/cypress/fixtures/errors/exceptions_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './setup'

const outsideError = require('../../../../server/test/support/fixtures/projects/todos/throws-error')

describe('exception failures', () => {
it('in spec file', () => {
({}).bar()
})

it('in file outside project', () => {
outsideError()
})
})
7 changes: 7 additions & 0 deletions packages/runner/cypress/fixtures/errors/readfile_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import './setup'

describe('cy.readFile', () => {
it('existence failure', () => {
cy.readFile('does-not-exist', { timeout: 0 })
})
})
85 changes: 85 additions & 0 deletions packages/runner/cypress/fixtures/errors/route_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { abortXhr, sendXhr } from './setup'

describe('cy.route', { defaultCommandTimeout: 0 }, () => {
it('callback assertion failure', () => {
cy.server().route(() => {
expect('actual').to.equal('expected')
})
})

it('callback exception', () => {
cy.server().route(() => {
({}).bar()
})
})

it('command failure', () => {
cy.server().route(() => {
cy.get('#does-not-exist')

return '/foo'
})
})

it('onAbort assertion failure', () => {
cy.server().route({
url: '/foo',
onAbort () {
expect('actual').to.equal('expected')
},
})
.window().then(abortXhr('/foo'))
})

it('onAbort exception', () => {
cy.server().route({
url: '/foo',
onAbort () {
({}).bar()
},
})
.window().then(abortXhr('/foo'))
})

it('onRequest assertion failure', () => {
cy.server().route({
url: '/foo',
onRequest () {
expect('actual').to.equal('expected')
},
})
.window().then(sendXhr('/foo'))
})

it('onRequest exception', () => {
cy.server().route({
url: '/foo',
onRequest () {
({}).bar()
},
})
.window().then(sendXhr('/foo'))
})

it('onResponse assertion failure', () => {
cy.server().route({
url: '/json-content-type',
onResponse () {
expect('actual').to.equal('expected')
},
})
.window().then(sendXhr('/json-content-type'))
.wait(10000)
})

it('onResponse exception', () => {
cy.server().route({
url: '/json-content-type',
onResponse () {
({}).bar()
},
})
.window().then(sendXhr('/json-content-type'))
.wait(10000)
})
})
Loading

0 comments on commit 8c998f1

Please sign in to comment.