Skip to content

Commit

Permalink
decaffeinate: Run post-processing cleanups on location.coffee and 10 …
Browse files Browse the repository at this point in the history
…other files
  • Loading branch information
sainthkh committed Apr 30, 2020
1 parent 8bd67a3 commit d08337c
Show file tree
Hide file tree
Showing 11 changed files with 2,440 additions and 2,249 deletions.
201 changes: 100 additions & 101 deletions packages/driver/src/cy/commands/location.js
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()
},
})
}
81 changes: 41 additions & 40 deletions packages/driver/src/cy/commands/misc.js
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()
},
})
}
Loading

0 comments on commit d08337c

Please sign in to comment.