-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decaffeinate: Run post-processing cleanups on location.coffee and 10 …
…other files
- Loading branch information
Showing
11 changed files
with
2,440 additions
and
2,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,100 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const _ = require("lodash"); | ||
const Promise = require("bluebird"); | ||
|
||
const $errUtils = require("../../cypress/error_utils"); | ||
const $Location = require("../../cypress/location"); | ||
|
||
module.exports = (Commands, Cypress, cy, state, config) => Commands.addAll({ | ||
url(options = {}) { | ||
let resolveHref; | ||
const userOptions = options; | ||
options = _.defaults({}, userOptions, { log: true }); | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: "" | ||
}); | ||
} | ||
|
||
const getHref = () => { | ||
return cy.getRemoteLocation("href"); | ||
}; | ||
|
||
return (resolveHref = () => { | ||
return Promise.try(getHref).then(href => { | ||
return cy.verifyUpcomingAssertions(href, options, { | ||
onRetry: resolveHref | ||
}); | ||
}); | ||
})(); | ||
}, | ||
|
||
hash(options = {}) { | ||
let resolveHash; | ||
const userOptions = options; | ||
options = _.defaults({}, userOptions, { log: true }); | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: "" | ||
}); | ||
} | ||
|
||
const getHash = () => { | ||
return cy.getRemoteLocation("hash"); | ||
}; | ||
|
||
return (resolveHash = () => { | ||
return Promise.try(getHash).then(hash => { | ||
return cy.verifyUpcomingAssertions(hash, options, { | ||
onRetry: resolveHash | ||
}); | ||
}); | ||
})(); | ||
}, | ||
|
||
location(key, options) { | ||
let resolveLocation; | ||
let userOptions = options; | ||
//# normalize arguments allowing key + options to be undefined | ||
//# key can represent the options | ||
if (_.isObject(key) && _.isUndefined(userOptions)) { | ||
userOptions = key; | ||
} | ||
|
||
if (userOptions == null) { userOptions = {}; } | ||
|
||
options = _.defaults({}, userOptions, { log: true }); | ||
|
||
const getLocation = () => { | ||
let ret; | ||
const location = cy.getRemoteLocation(); | ||
|
||
return ret = _.isString(key) ? | ||
//# use existential here because we only want to throw | ||
//# on null or undefined values (and not empty strings) | ||
location[key] != null ? location[key] : $errUtils.throwErrByPath("location.invalid_key", { args: { key } }) | ||
: | ||
location; | ||
}; | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: key != null ? key : "" | ||
}); | ||
} | ||
|
||
return (resolveLocation = () => { | ||
return Promise.try(getLocation).then(ret => { | ||
return cy.verifyUpcomingAssertions(ret, options, { | ||
onRetry: resolveLocation | ||
}); | ||
}); | ||
})(); | ||
} | ||
}); | ||
const _ = require('lodash') | ||
const Promise = require('bluebird') | ||
|
||
const $errUtils = require('../../cypress/error_utils') | ||
|
||
module.exports = (Commands, Cypress, cy) => { | ||
Commands.addAll({ | ||
url (options = {}) { | ||
const userOptions = options | ||
|
||
options = _.defaults({}, userOptions, { log: true }) | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: '', | ||
}) | ||
} | ||
|
||
const getHref = () => { | ||
return cy.getRemoteLocation('href') | ||
} | ||
|
||
const resolveHref = () => { | ||
return Promise.try(getHref).then((href) => { | ||
return cy.verifyUpcomingAssertions(href, options, { | ||
onRetry: resolveHref, | ||
}) | ||
}) | ||
} | ||
|
||
return resolveHref() | ||
}, | ||
|
||
hash (options = {}) { | ||
const userOptions = options | ||
|
||
options = _.defaults({}, userOptions, { log: true }) | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: '', | ||
}) | ||
} | ||
|
||
const getHash = () => { | ||
return cy.getRemoteLocation('hash') | ||
} | ||
|
||
const resolveHash = () => { | ||
return Promise.try(getHash).then((hash) => { | ||
return cy.verifyUpcomingAssertions(hash, options, { | ||
onRetry: resolveHash, | ||
}) | ||
}) | ||
} | ||
|
||
return resolveHash() | ||
}, | ||
|
||
location (key, options) { | ||
let userOptions = options | ||
|
||
// normalize arguments allowing key + options to be undefined | ||
// key can represent the options | ||
if (_.isObject(key) && _.isUndefined(userOptions)) { | ||
userOptions = key | ||
} | ||
|
||
userOptions = userOptions || {} | ||
|
||
options = _.defaults({}, userOptions, { log: true }) | ||
|
||
const getLocation = () => { | ||
const location = cy.getRemoteLocation() | ||
|
||
return _.isString(key) | ||
// use existential here because we only want to throw | ||
// on null or undefined values (and not empty strings) | ||
? location[key] ?? $errUtils.throwErrByPath('location.invalid_key', { args: { key } }) | ||
: location | ||
} | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: key != null ? key : '', | ||
}) | ||
} | ||
|
||
const resolveLocation = () => { | ||
return Promise.try(getLocation).then((ret) => { | ||
return cy.verifyUpcomingAssertions(ret, options, { | ||
onRetry: resolveLocation, | ||
}) | ||
}) | ||
} | ||
|
||
return resolveLocation() | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const _ = require("lodash"); | ||
|
||
const $dom = require("../../dom"); | ||
|
||
module.exports = function(Commands, Cypress, cy, state, config) { | ||
Commands.addAll({ prevSubject: "optional" }, { | ||
end() { | ||
return null; | ||
} | ||
}); | ||
|
||
return Commands.addAll({ | ||
noop(arg) { return arg; }, | ||
|
||
log(msg, args) { | ||
const _ = require('lodash') | ||
|
||
const $dom = require('../../dom') | ||
|
||
module.exports = (Commands, Cypress, cy) => { | ||
Commands.addAll({ prevSubject: 'optional' }, { | ||
end () { | ||
return null | ||
}, | ||
}) | ||
|
||
Commands.addAll({ | ||
noop (arg) { | ||
return arg | ||
}, | ||
|
||
log (msg, args) { | ||
Cypress.log({ | ||
end: true, | ||
snapshot: true, | ||
message: [msg, args], | ||
consoleProps() { | ||
consoleProps () { | ||
return { | ||
message: msg, | ||
args | ||
}; | ||
} | ||
}); | ||
args, | ||
} | ||
}, | ||
}) | ||
|
||
return null; | ||
return null | ||
}, | ||
|
||
wrap(arg, options = {}) { | ||
let resolveWrap; | ||
const userOptions = options; | ||
options = _.defaults({}, userOptions, { log: true }); | ||
wrap (arg, options = {}) { | ||
const userOptions = options | ||
|
||
options = _.defaults({}, userOptions, { log: true }) | ||
|
||
if (options.log !== false) { | ||
options._log = Cypress.log({ | ||
message: arg | ||
}); | ||
message: arg, | ||
}) | ||
|
||
if ($dom.isElement(arg)) { | ||
options._log.set({$el: arg}); | ||
options._log.set({ $el: arg }) | ||
} | ||
} | ||
|
||
return (resolveWrap = () => cy.verifyUpcomingAssertions(arg, options, { | ||
onRetry: resolveWrap | ||
}) | ||
.return(arg))(); | ||
} | ||
}); | ||
}; | ||
const resolveWrap = () => { | ||
return cy.verifyUpcomingAssertions(arg, options, { | ||
onRetry: resolveWrap, | ||
}) | ||
.return(arg) | ||
} | ||
|
||
return resolveWrap() | ||
}, | ||
}) | ||
} |
Oops, something went wrong.