Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into issue-4313
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 12, 2019
2 parents 47860ca + 4bd3cf2 commit 8e63476
Show file tree
Hide file tree
Showing 55 changed files with 1,210 additions and 480 deletions.
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"execa": "0.10.0",
"executable": "4.1.1",
"extract-zip": "1.6.7",
"fs-extra": "4.0.1",
"fs-extra": "4.0.3",
"getos": "3.1.1",
"glob": "7.1.3",
"is-ci": "1.2.1",
Expand Down Expand Up @@ -108,4 +108,4 @@
"index.js",
"types/**/*.d.ts"
]
}
}
20 changes: 10 additions & 10 deletions cli/scripts/post-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ shell.sed(
'<reference path="../jquery/index.d.ts" />',
join('types', 'chai-jquery', 'index.d.ts')
)

const sinonChaiFilename = join('types', 'sinon-chai', 'index.d.ts')

shell.sed(
'-i',
'<reference types="chai" />',
'<reference path="../chai/index.d.ts" />',
join('types', 'sinon-chai', 'index.d.ts')
sinonChaiFilename
)
// also use relative import via path for sinon-chai
// there is reference comment line we need to fix to be relative
shell.sed(
'-i',
'<reference types="sinon" />',
'<reference types="../sinon" />',
join('types', 'sinon-chai', 'index.d.ts')
)
// also use relative import for sinon-chai
shell.sed(
'-i',
'from \'sinon\';',
'from \'../sinon\';',
join('types', 'sinon-chai', 'index.d.ts')
'<reference path="../sinon/index.d.ts" />',
sinonChaiFilename
)
// and an import sinon line to be changed to relative path
shell.sed('-i', 'from \'sinon\';', 'from \'../sinon\';', sinonChaiFilename)
7 changes: 5 additions & 2 deletions cli/test/lib/logger_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('../spec_helper')

const la = require('lazy-ass')
const {stripIndent, stripIndents} = require('common-tags')
const { stripIndent, stripIndents } = require('common-tags')
const snapshot = require('../support/snapshot')

describe('stripIndent', () => {
Expand All @@ -12,6 +12,7 @@ describe('stripIndent', () => {
third line
last line
`

// should preserve the structure of the text
snapshot(removed)
})
Expand All @@ -21,7 +22,8 @@ describe('stripIndent', () => {
const removed = stripIndent(text)
// removed 1 level of indentation and trimmed the string
const expected = 'foo\n bar'
la(removed === expected, 'removed indent is\n' + removed)

la(removed === expected, `removed indent is\n${removed}`)
})

it('can be used with nested message', () => {
Expand All @@ -33,6 +35,7 @@ describe('stripIndent', () => {
last line
`

// should have NO indents
// first line
//
Expand Down
9 changes: 9 additions & 0 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,15 @@ declare namespace Cypress {
* @see https://on.cypress.io/writefile
*/
writeFile<C extends FileContents>(filePath: string, contents: C, encoding: Encodings, options?: Partial<Loggable>): Chainable<C>

/**
* jQuery library bound to the AUT
*
* @see https://on.cypress.io/$
* @example
* cy.$$('p')
*/
$$: JQueryStatic
}

interface SinonSpyAgent<A extends sinon.SinonSpy> {
Expand Down
7 changes: 7 additions & 0 deletions cli/types/tests/kitchen-sink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ cy.on('window:alert', () => { })
cy.on('window:alert', cy.spy())
cy.on('window:alert', cy.stub())

// sinon-chai example
const stub = cy.stub()
expect(stub).to.not.have.been.called
stub()
expect(stub).to.have.been.calledOnce
cy.wrap(stub).should('have.been.calledOnce')

// window:confirm stubbing
Cypress.on('window:confirm', () => { })
Cypress.on('window:confirm', cy.spy())
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@
"make-empty-github-commit": "1.2.0",
"mocha": "3.5.3",
"mocha-banner": "1.1.2",
"mocha-junit-reporter": "1.18.0",
"mocha-junit-reporter": "1.23.0",
"mocha-multi-reporters": "1.1.7",
"obfuscator": "0.5.4",
"parse-github-repo-url": "1.4.1",
"plist": "2.1.0",
"pluralize": "7.0.0",
"pluralize": "8.0.0",
"prefixed-list": "1.0.1",
"pretty-ms": "5.0.0",
"print-arch": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/coffee/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("coffee-script")
module.exports = require('coffeescript')
2 changes: 1 addition & 1 deletion packages/coffee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "index.js",
"private": true,
"dependencies": {
"coffee-script": "1.12.7"
"coffeescript": "1.12.7"
},
"files": [
"register.js"
Expand Down
5 changes: 3 additions & 2 deletions packages/coffee/register.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
if (process.env.CYPRESS_ENV !== 'production') {
require('coffee-script/register')
require('coffeescript/register')

// using hack found here to prevent problems with
// cypress coffee script being replaced by modules which
// use coffee-script/register
// use coffeescript/register
// https://github.com/abresas/register-coffee-coverage/blob/master/index.js
// remove when https://github.com/benbria/coffee-coverage/issues/69 is resolved
const loader = require.extensions['.coffee']

Object.defineProperty(require.extensions, '.coffee', {
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 @@ -45,7 +45,7 @@
"mobx-react-devtools": "6.1.1",
"moment": "2.24.0",
"prop-types": "15.7.2",
"rc-collapse": "1.11.2",
"rc-collapse": "1.11.3",
"react": "16.8.6",
"rebuild-node-sass": "1.1.0",
"react-bootstrap-modal": "4.2.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"bytes": "3.1.0",
"chai": "3.5.0",
"chai-as-promised": "6.0.0",
"chai-subset": "1.6.0",
"chokidar-cli": "1.2.2",
"clone": "2.1.2",
"compression": "1.7.4",
Expand All @@ -44,7 +45,7 @@
"js-cookie": "2.2.0",
"jsdom": "13.2.0",
"lodash": "4.17.11",
"lolex": "3.1.0",
"lolex": "4.1.0",
"methods": "1.1.2",
"method-override": "3.0.0",
"minimatch": "3.0.4",
Expand Down
26 changes: 9 additions & 17 deletions packages/driver/src/cy/commands/actions/click.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports = (Commands, Cypress, cy, state, config) ->
$el = $dom.wrap(el)

domEvents = {}
$previouslyFocusedEl = null

if options.log
## figure out the options which actually change the behavior of clicks
Expand Down Expand Up @@ -149,9 +148,6 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## without firing the focus event
$previouslyFocused = cy.getFocused()

if el = cy.needsForceFocus()
cy.fireFocus(el)

el = $elToClick.get(0)

domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport)
Expand All @@ -169,21 +165,17 @@ module.exports = (Commands, Cypress, cy, state, config) ->

## retrieve the first focusable $el in our parent chain
$elToFocus = $elements.getFirstFocusableEl($elToClick)

if cy.needsFocus($elToFocus, $previouslyFocused)
cy.fireFocus($elToFocus.get(0))

## if we are currently trying to focus
## the body then calling body.focus()
## is a noop, and it will not blur the
## current element, which is all so wrong
if $elToFocus.is("body")
if $dom.isWindow($elToFocus)
# if the first focusable element from the click
# is the window, then we can skip the focus event
# since the user has clicked a non-focusable element
$focused = cy.getFocused()

## if the current focused element hasn't changed
## then blur manually
if $elements.isSame($focused, $previouslyFocused)
cy.fireBlur($focused.get(0))
if $focused
cy.fireBlur $focused.get(0)
else
# the user clicked inside a focusable element
cy.fireFocus $elToFocus.get(0)

afterMouseDown($elToClick, coords)
})
Expand Down
15 changes: 12 additions & 3 deletions packages/driver/src/cy/commands/actions/focus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ module.exports = (Commands, Cypress, cy, state, config) ->
consoleProps: ->
"Applied To": $dom.getElements(options.$el)

## http://www.w3.org/TR/html5/editing.html#specially-focusable
el = options.$el.get(0)

## the body is not really focusable, but it
## can have focus on initial page load.
## this is instead a noop.
## TODO: throw on body instead (breaking change)
isBody = $dom.isJquery(options.$el) &&
$elements.isElement(options.$el.get(0)) &&
$elements.isBody(options.$el.get(0))

## http://www.w3.org/$R/html5/editing.html#specially-focusable
## ensure there is only 1 dom element in the subject
## make sure its allowed to be focusable
if not (isWin or $dom.isFocusable(options.$el))
if not (isWin or isBody or $dom.isFocusable(options.$el))
return if options.error is false

node = $dom.stringify(options.$el)
Expand All @@ -48,7 +58,6 @@ module.exports = (Commands, Cypress, cy, state, config) ->
args: { num }
})

el = options.$el.get(0)

cy.fireFocus(el)

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/actions/scroll.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
$container.contentWindow = $container

## throw if we're trying to scroll multiple containers
if $container.length > 1
if (!isWin && $container.length > 1)
$utils.throwErrByPath("scrollTo.multiple_containers", {args: { num: $container.length }})

_.defaults(options, {
Expand Down
5 changes: 5 additions & 0 deletions packages/driver/src/cy/commands/actions/trigger.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ module.exports = (Commands, Cypress, cy, state, config) ->
animationDistanceThreshold: config("animationDistanceThreshold")
})

if $dom.isWindow(options.$el)
## get this into a jquery object
options.$el = $dom.wrap(options.$el)


## omit entries we know aren't part of an event, but pass anything
## else through so user can specify what the event object needs
eventOptions = _.omit(options, "log", "$el", "position", "x", "y", "waitForAnimations", "animationDistanceThreshold")
Expand Down
22 changes: 18 additions & 4 deletions packages/driver/src/cy/commands/actions/type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
form.find("input, button").filter (__, el) ->
$el = $dom.wrap(el)
($dom.isSelector($el, "input") and $dom.isType($el, "submit")) or
($dom.isSelector($el, "button") and not $dom.isType($el, "button"))
($dom.isSelector($el, "button") and not $dom.isType($el, "button") and not $dom.isType($el, "reset") )

type = ->
simulateSubmitHandler = ->
Expand Down Expand Up @@ -328,16 +328,30 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## if it's the body, don't need to worry about focus
return type() if isBody

## if the subject is already the focused element, start typing
## we handle contenteditable children by getting the host contenteditable,
## and seeing if that is focused
## Checking first if element is focusable accounts for focusable els inside
## of contenteditables
$focused = cy.getFocused()
$focused = $focused && $focused[0]

if $elements.isFocusable(options.$el)
elToCheckCurrentlyFocused = options.$el[0]
else if $elements.isContentEditable(options.$el[0])
elToCheckCurrentlyFocused = $selection.getHostContenteditable(options.$el[0])

if elToCheckCurrentlyFocused && elToCheckCurrentlyFocused is $focused
## TODO: not scrolling here, but revisit when scroll algorithm changes
return type()

$actionability.verify(cy, options.$el, options, {
onScroll: ($el, type) ->
Cypress.action("cy:scrolled", $el, type)

onReady: ($elToClick) ->
$focused = cy.getFocused()

if el = cy.needsForceFocus()
cy.fireFocus(el)

## if we dont have a focused element
## or if we do and its not ourselves
## then issue the click
Expand Down
4 changes: 3 additions & 1 deletion packages/driver/src/cy/commands/screenshot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ module.exports = (Commands, Cypress, cy, state, config) ->
timeout: config("responseTimeout")
}

isWin = $dom.isWindow(subject)

screenshotConfig = _.pick(options, "capture", "scale", "disableTimersAndAnimations", "blackout", "waitForCommandSynchronization", "clip", "onBeforeScreenshot", "onAfterScreenshot")
screenshotConfig = $Screenshot.validate(screenshotConfig, "cy.screenshot", options._log)
screenshotConfig = _.extend($Screenshot.getConfig(), screenshotConfig)
Expand All @@ -333,7 +335,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
consoleProps
})

if subject and subject.length > 1
if not isWin and subject and subject.length > 1
$utils.throwErrByPath("screenshot.multiple_elements", {
log: options._log
args: { numElements: subject.length }
Expand Down

0 comments on commit 8e63476

Please sign in to comment.