Skip to content

Commit

Permalink
Merge branch 'develop' into issue-1859-part-1
Browse files Browse the repository at this point in the history
  • Loading branch information
CypressJoseph authored Apr 10, 2020
2 parents d3ebe11 + 5c022b2 commit 28e5a12
Show file tree
Hide file tree
Showing 38 changed files with 829 additions and 194 deletions.
15 changes: 8 additions & 7 deletions packages/driver/src/cy/commands/actions/check.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ $utils = require("../../../cypress/utils")
$errUtils = require("../../../cypress/error_utils")
$elements = require("../../../dom/elements")

checkOrUncheck = (type, subject, values = [], options = {}) ->
checkOrUncheck = (type, subject, values = [], userOptions = {}) ->
## we're not handling conversion of values to strings
## in case we've received numbers

## if we're not an array but we are an object
## reassign options to values
## reassign userOptions to values
if not _.isArray(values) and _.isObject(values)
options = values
userOptions = values
values = []
else
## make sure we're an array of values
Expand All @@ -24,10 +24,11 @@ checkOrUncheck = (type, subject, values = [], options = {}) ->
## to new filtered subjects
matchingElements = []

_.defaults options,
options = _.defaults {}, userOptions, {
$el: subject
log: true
force: false
}

isNoop = ($el) ->
switch type
Expand Down Expand Up @@ -75,17 +76,17 @@ checkOrUncheck = (type, subject, values = [], options = {}) ->
}

if options.log and isElActionable

## figure out the options which actually change the behavior of clicks
## figure out the userOptions which actually change the behavior of clicks
deltaOptions = $utils.filterOutOptions(options)

options._log = Cypress.log
options._log = Cypress.log {
message: deltaOptions
$el: $el
consoleProps: ->
_.extend consoleProps, {
Options: deltaOptions
}
}

options._log.snapshot("before", {next: "after"})

Expand Down
12 changes: 6 additions & 6 deletions packages/driver/src/cy/commands/actions/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const formatMouseEvents = (events) => {
module.exports = (Commands, Cypress, cy, state, config) => {
const { mouse } = cy.devices

const mouseAction = (eventName, { subject, positionOrX, y, options, onReady, onTable, defaultOptions }) => {
const mouseAction = (eventName, { subject, positionOrX, y, userOptions, onReady, onTable, defaultOptions }) => {
let position
let x

({ options, position, x, y } = $actionability.getPositionFromArguments(positionOrX, y, options))
({ options: userOptions, position, x, y } = $actionability.getPositionFromArguments(positionOrX, y, userOptions))

_.defaults(options, {
const options = _.defaults({}, userOptions, {
$el: subject,
log: true,
verify: true,
Expand Down Expand Up @@ -203,7 +203,7 @@ module.exports = (Commands, Cypress, cy, state, config) => {
return mouseAction('click', {
y,
subject,
options,
userOptions: options,
positionOrX,
onReady (fromElViewport, forceEl) {
const clickEvents = mouse.click(fromElViewport, forceEl)
Expand Down Expand Up @@ -232,7 +232,7 @@ module.exports = (Commands, Cypress, cy, state, config) => {
return mouseAction('dblclick', {
y,
subject,
options,
userOptions: options,
// TODO: 4.0 make this false by default
defaultOptions: { multiple: true },
positionOrX,
Expand Down Expand Up @@ -268,7 +268,7 @@ module.exports = (Commands, Cypress, cy, state, config) => {
return mouseAction('rightclick', {
y,
subject,
options,
userOptions: options,
positionOrX,
onReady (fromElViewport, forceEl) {
const { clickEvents, contextmenuEvent } = mouse.rightclick(fromElViewport, forceEl)
Expand Down
8 changes: 4 additions & 4 deletions packages/driver/src/cy/commands/actions/focus.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ $actionability = require("../../actionability")
module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: ["element", "window"] }, {
focus: (subject, options = {}) ->
userOptions = options
## we should throw errors by default!
## but allow them to be silenced
_.defaults(options, {
options = _.defaults({}, userOptions, {
$el: subject
error: true
log: true
Expand Down Expand Up @@ -62,17 +63,16 @@ module.exports = (Commands, Cypress, cy, state, config) ->

cy.fireFocus(el)

# return options.$el if options.verify is false

do verifyAssertions = ->
cy.verifyUpcomingAssertions(options.$el, options, {
onRetry: verifyAssertions
})

blur: (subject, options = {}) ->
userOptions = options
## we should throw errors by default!
## but allow them to be silenced
_.defaults(options, {
options = _.defaults({}, userOptions, {
$el: subject
$focused: cy.getFocused()
error: true
Expand Down
14 changes: 9 additions & 5 deletions packages/driver/src/cy/commands/actions/scroll.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ isNaNOrInfinity = (item) ->
module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: "element" }, {
scrollIntoView: (subject, options = {}) ->
if !_.isObject(options)
$errUtils.throwErrByPath("scrollIntoView.invalid_argument", {args: { arg: options }})
userOptions = options

if !_.isObject(userOptions)
$errUtils.throwErrByPath("scrollIntoView.invalid_argument", {args: { arg: userOptions }})

## ensure the subject is not window itself
## cause how are you gonna scroll the window into view...
Expand All @@ -38,7 +40,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
if subject.length > 1
$errUtils.throwErrByPath("scrollIntoView.multiple_elements", {args: { num: subject.length }})

_.defaults(options, {
options = _.defaults({}, userOptions, {
$el: subject
$parent: state("window")
log: true
Expand Down Expand Up @@ -123,13 +125,15 @@ module.exports = (Commands, Cypress, cy, state, config) ->

Commands.addAll({ prevSubject: ["optional", "element", "window"] }, {
scrollTo: (subject, xOrPosition, yOrOptions, options = {}) ->
userOptions = options

## check for undefined or null values
if not xOrPosition?
$errUtils.throwErrByPath "scrollTo.invalid_target", {args: { x }}

switch
when _.isObject(yOrOptions)
options = yOrOptions
userOptions = yOrOptions
else
y = yOrOptions

Expand Down Expand Up @@ -197,7 +201,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
if (!isWin && $container.length > 1)
$errUtils.throwErrByPath("scrollTo.multiple_containers", {args: { num: $container.length }})

_.defaults(options, {
options = _.defaults({}, userOptions, {
$el: $container
log: true
duration: 0
Expand Down
4 changes: 3 additions & 1 deletion packages/driver/src/cy/commands/actions/select.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ newLineRe = /\n/g
module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: "element" }, {
select: (subject, valueOrText, options = {}) ->
_.defaults options,
userOptions = options

options = _.defaults {}, userOptions,
$el: subject
log: true
force: false
Expand Down
4 changes: 3 additions & 1 deletion packages/driver/src/cy/commands/actions/submit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ $actionability = require("../../actionability")
module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: "element" }, {
submit: (subject, options = {}) ->
_.defaults options,
userOptions = options
options = _.defaults({}, userOptions, {
log: true
$el: subject
})

## changing this to a promise .map() causes submit events
## to break when they need to be triggered synchronously
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/cy/commands/actions/trigger.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dispatch = (target, eventName, options) ->

module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: ["element", "window", "document"] }, {
trigger: (subject, eventName, positionOrX, y, options = {}) ->
{options, position, x, y} = $actionability.getPositionFromArguments(positionOrX, y, options)
trigger: (subject, eventName, positionOrX, y, userOptions = {}) ->
{options: userOptions, position, x, y} = $actionability.getPositionFromArguments(positionOrX, y, userOptions)

_.defaults(options, {
options = _.defaults({}, userOptions, {
log: true
$el: subject
bubbles: true
Expand Down
8 changes: 5 additions & 3 deletions packages/driver/src/cy/commands/actions/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = function (Commands, Cypress, cy, state, config) {
const { keyboard } = cy.devices

function type (subject, chars, options = {}) {
const userOptions = options
let updateTable

options = _.clone(options)
// allow the el we're typing into to be
// changed by options -- used by cy.clear()
_.defaults(options, {
options = _.defaults({}, userOptions, {
$el: subject,
log: true,
verify: true,
Expand Down Expand Up @@ -457,7 +457,9 @@ module.exports = function (Commands, Cypress, cy, state, config) {
}

function clear (subject, options = {}) {
_.defaults(options, {
const userOptions = options

options = _.defaults({}, userOptions, {
log: true,
force: false,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/driver/src/cy/commands/angular.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ module.exports = (Commands, Cypress, cy, state, config) ->

Commands.addAll({
ng: (type, selector, options = {}) ->
userOptions = options
## what about requirejs / browserify?
## we need to intelligently check to see if we're using those
## and if angular is available through them. throw a very specific
## error message here that's different depending on what module
## system you're using
$errUtils.throwErrByPath "ng.no_global" if not state("window").angular

_.defaults options, {log: true}
options = _.defaults {}, userOptions, {log: true}

if options.log
options._log = Cypress.log()
Expand Down
7 changes: 4 additions & 3 deletions packages/driver/src/cy/commands/clock.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ module.exports = (Commands, Cypress, cy, state, config) ->

Commands.addAll({ type: "utility" }, {
clock: (subject, now, methods, options = {}) ->
userOptions = options
ctx = @

if clock
return clock

if _.isObject(now)
options = now
userOptions = now
now = undefined

if _.isObject(methods) and !_.isArray(methods)
options = methods
userOptions = methods
methods = undefined

if now? and !_.isNumber(now)
Expand All @@ -51,7 +52,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
if methods? and not (_.isArray(methods) and _.every(methods, _.isString))
$errUtils.throwErrByPath("clock.invalid_2nd_arg", {args: {arg: JSON.stringify(methods)}})

_.defaults options, {
options = _.defaults {}, userOptions, {
log: true
}

Expand Down
46 changes: 25 additions & 21 deletions packages/driver/src/cy/commands/connectors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## thens can return more "thenables" which are not resolved
## until they're 'really' resolved, so naturally this API
## supports nesting promises
thenFn = (subject, options, fn) ->
thenFn = (subject, userOptions, fn) ->
ctx = @

if _.isFunction(options)
fn = options
options = {}
if _.isFunction(userOptions)
fn = userOptions
userOptions = {}

_.defaults options,
options = _.defaults({}, userOptions, {
timeout: cy.timeout()
})

## clear the timeout since we are handling
## it ourselves
Expand Down Expand Up @@ -139,27 +140,26 @@ module.exports = (Commands, Cypress, cy, state, config) ->
}
.finally(cleanup)

invokeItsFn = (subject, str, options, args...) ->
return invokeBaseFn(options or { log: true }, subject, str, args...)
invokeItsFn = (subject, str, userOptions, args...) ->
return invokeBaseFn(userOptions or { log: true }, subject, str, args...)

invokeFn = (subject, optionsOrStr, args...) ->
optionsPassed = _.isObject(optionsOrStr) and !_.isFunction(optionsOrStr)
options = null
invokeFn = (subject, userOptionsOrStr, args...) ->
userOptionsPassed = _.isObject(userOptionsOrStr) and !_.isFunction(userOptionsOrStr)
userOptions = null
str = null

if not optionsPassed
str = optionsOrStr
options = { log: true }
if not userOptionsPassed
str = userOptionsOrStr
userOptions = { log: true }
else
options = optionsOrStr
userOptions = userOptionsOrStr
if args.length > 0
str = args[0]
args = args.slice(1)

return invokeBaseFn(options, subject, str, args...)

invokeBaseFn = (options, subject, str, args...) ->
return invokeBaseFn(userOptions, subject, str, args...)

invokeBaseFn = (userOptions, subject, str, args...) ->
## name could be invoke or its!
name = state("current").get("name")

Expand All @@ -179,6 +179,9 @@ module.exports = (Commands, Cypress, cy, state, config) ->

traversalErr = null

## copy userOptions because _log is added below.
options = _.extend({}, userOptions)

if options.log
options._log = Cypress.log
message: message
Expand All @@ -199,7 +202,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->
args: { cmd: name, identifier: if isCmdIts then "property" else "function" }
})

if not _.isObject(options) or _.isFunction(options)
if not _.isObject(userOptions) or _.isFunction(userOptions)
$errUtils.throwErrByPath("invoke_its.invalid_options_arg", {
onFail: options._log
args: { cmd: name }
Expand Down Expand Up @@ -402,11 +405,12 @@ module.exports = (Commands, Cypress, cy, state, config) ->
thenFn(subject, options, fn)

each: (subject, options, fn) ->
userOptions = options
ctx = @

if _.isUndefined(fn)
fn = options
options = {}
fn = userOptions
userOptions = {}

if not _.isFunction(fn)
$errUtils.throwErrByPath("each.invalid_argument")
Expand Down Expand Up @@ -460,7 +464,7 @@ module.exports = (Commands, Cypress, cy, state, config) ->

return ret

thenFn(el, options, callback, state)
thenFn(el, userOptions, callback, state)

## generate a real array since bluebird is finicky and
## doesnt want an 'array-like' structure like jquery instances
Expand Down
Loading

0 comments on commit 28e5a12

Please sign in to comment.