Skip to content

Commit

Permalink
feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Feb 3, 2022
1 parent 4b9b7aa commit 4c9b618
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import $dom from '../../dom'
import $utils from '../../cypress/utils'
import $errUtils, { CypressError } from '../../cypress/error_utils'

const returnFalseIfThenable = (key, ...args) => {
const returnFalseIfThenable = (key, ...args): boolean => {
if ((key === 'then') && _.isFunction(args[0]) && _.isFunction(args[1])) {
// https://github.com/cypress-io/cypress/issues/111
// if we're inside of a promise then the promise lib will naturally
Expand Down
16 changes: 6 additions & 10 deletions packages/driver/src/cy/commands/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import debugFn from 'debug'
const debug = debugFn('cypress:driver:navigation')

let id = null
let previousDomainVisited: boolean | null = null
let hasVisitedAboutBlank: boolean | null = null
let currentlyVisitingAboutBlank: boolean | null = null
let knownCommandCausedInstability: boolean | null = null
let previousDomainVisited: boolean = false
let hasVisitedAboutBlank: boolean = false
let currentlyVisitingAboutBlank: boolean = false
let knownCommandCausedInstability: boolean = false

const REQUEST_URL_OPTS = 'auth failOnStatusCode retryOnNetworkFailure retryOnStatusCodeFailure retryIntervals method body headers'
.split(' ')
Expand Down Expand Up @@ -675,12 +675,10 @@ export default (Commands, Cypress, cy, state, config) => {
case 'forward': return goNumber(1)
case 'back': return goNumber(-1)
default:
$errUtils.throwErrByPath('go.invalid_direction', {
return $errUtils.throwErrByPath('go.invalid_direction', {
onFail: options._log,
args: { str },
})

return // Error is thrown above, it exists to satisfy typescript
}
}

Expand All @@ -692,9 +690,7 @@ export default (Commands, Cypress, cy, state, config) => {
return goString(numberOrString)
}

$errUtils.throwErrByPath('go.invalid_argument', { onFail: options._log })

return // Error is thrown above, it exists to satisfy typescript
return $errUtils.throwErrByPath('go.invalid_argument', { onFail: options._log })
},

// TODO: Change the type of `any` to `Partial<Cypress.VisitOptions>`.
Expand Down
7 changes: 5 additions & 2 deletions packages/driver/src/cypress/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ const _isBrowser = (browser, matcher, errPrefix) => {
}

// TODO: change the type of `any` to `IsBrowserMatcher`
const isBrowser = (config, obj: any = '', errPrefix = '`Cypress.isBrowser()`') => {
const isBrowser = (config, obj: any = '', errPrefix: string = '`Cypress.isBrowser()`') => {
return _
.chain(obj)
.concat([])
.map((matcher) => _isBrowser(config.browser, matcher, errPrefix))
.reduce((a: null | { isMatch: boolean, exclusive: boolean }, b) => {
.reduce((
a: null | { isMatch: boolean, exclusive: boolean },
b: { isMatch: boolean, exclusive: boolean },
) => {
if (!a) return b

if (a.exclusive && b.exclusive) {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const defaults: any = {

const warnOnWhitelistRenamed = (obj, type) => {
if (obj.whitelist) {
return $errUtils.throwErrByPath('cookies.whitelist_renamed', { args: { type } })
$errUtils.throwErrByPath('cookies.whitelist_renamed', { args: { type } })
}
}

Expand Down
14 changes: 9 additions & 5 deletions packages/driver/src/cypress/error_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const isChaiValidationErr = (err: Error) => {
return _.startsWith(err.message, 'Invalid Chai property')
}

const isCypressErr = (err: Error) => {
const isCypressErr = (err: Error): boolean => {
return err.name === 'CypressError'
}

Expand Down Expand Up @@ -195,7 +195,7 @@ const makeErrFromObj = (obj) => {
return err2
}

const throwErr = (err, options: any = {}) => {
const makeErrFromErr = (err, options: any = {}) => {
if (_.isString(err)) {
err = cypressErr({ message: err })
}
Expand All @@ -222,10 +222,14 @@ const throwErr = (err, options: any = {}) => {
_.extend(err, errProps)
}

throw err
return err
}

const throwErr = (err, options: any = {}): never => {
throw makeErrFromErr(err, options)
}

const throwErrByPath = (errPath, options: any = {}) => {
const throwErrByPath = (errPath, options: any = {}): never => {
const err = errByPath(errPath, options.args)

if (options.stack) {
Expand All @@ -235,7 +239,7 @@ const throwErrByPath = (errPath, options: any = {}) => {
Error.captureStackTrace(err, throwErrByPath)
}

throwErr(err, options)
throw makeErrFromErr(err, options)
}

const warnByPath = (errPath, options: any = {}) => {
Expand Down

0 comments on commit 4c9b618

Please sign in to comment.