Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove pkg/driver //@ts-nocheck part 2 #19483

Merged
merged 19 commits into from
Jan 11, 2022
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@cypress/request": "^2.88.10",
"@cypress/xvfb": "^1.2.4",
"@types/node": "^14.14.31",
"@types/sinonjs__fake-timers": "^6.0.2",
"@types/sinonjs__fake-timers": "8.1.1",
"@types/sizzle": "^2.3.2",
"arch": "^2.2.0",
"blob-util": "^2.0.2",
Expand Down Expand Up @@ -75,7 +75,7 @@
"@types/lodash": "4.14.168",
"@types/minimatch": "3.0.3",
"@types/mocha": "8.0.3",
"@types/sinon": "7.5.1",
"@types/sinon": "9.0.9",
"@types/sinon-chai": "3.2.5",
"chai": "3.5.0",
"chai-as-promised": "7.1.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"@packages/server": "0.0.0-development",
"@packages/ts": "0.0.0-development",
"@rollup/plugin-node-resolve": "^13.0.4",
"@sinonjs/fake-timers": "7.0.2",
"@sinonjs/fake-timers": "8.1.0",
"@types/chalk": "^2.2.0",
"@types/common-tags": "^1.8.0",
"@types/jquery.scrollto": "1.4.29",
"@types/mocha": "^8.0.3",
"@types/sinonjs__fake-timers": "8.1.1",
"@types/underscore.string": "0.0.38",
"angular": "1.8.0",
"basic-auth": "2.0.1",
Expand Down
20 changes: 11 additions & 9 deletions packages/driver/src/cy/actionability.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-nocheck
import _ from 'lodash'
import $ from 'jquery'
import Promise from 'bluebird'

import debugFn from 'debug'
import $dom from '../dom'
import type { ElWindowPostion, ElViewportPostion } from '../dom/coordinates'
import $elements from '../dom/elements'
import $errUtils from '../cypress/error_utils'
const debug = debugFn('cypress:driver:actionability')
Expand Down Expand Up @@ -54,7 +54,7 @@ const getPositionFromArguments = function (positionOrX, y, options) {
}

const ensureElIsNotCovered = function (cy, win, $el, fromElViewport, options, log, onScroll) {
let $elAtCoords = null
let $elAtCoords: JQuery<any> | null = null

const getElementAtPointFromViewport = function (fromElViewport) {
// get the element at point from the viewport based
Expand All @@ -64,8 +64,12 @@ const ensureElIsNotCovered = function (cy, win, $el, fromElViewport, options, lo
elAtCoords = $dom.getElementAtPointFromViewport(win.document, fromElViewport.x, fromElViewport.y)

if (elAtCoords) {
return $elAtCoords = $dom.wrap(elAtCoords)
$elAtCoords = $dom.wrap(elAtCoords)

return $elAtCoords
}

return null
AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
}

const ensureDescendents = function (fromElViewport) {
Expand Down Expand Up @@ -164,7 +168,7 @@ const ensureElIsNotCovered = function (cy, win, $el, fromElViewport, options, lo
const scrollContainers = function (scrollables) {
// hold onto all the elements we've scrolled
// past in this cycle
const elementsScrolledPast = []
const elementsScrolledPast: JQuery<any>[] = []

// pull off scrollables starting with the most outer
// container which is window
Expand All @@ -178,9 +182,7 @@ const ensureElIsNotCovered = function (cy, win, $el, fromElViewport, options, lo

const possiblyScrollMultipleTimes = function ($fixed) {
// if we got something AND
let needle

if ($fixed && ((needle = $fixed.get(0), !elementsScrolledPast.includes(needle)))) {
if ($fixed && !elementsScrolledPast.includes($fixed.get(0))) {
AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
elementsScrolledPast.push($fixed.get(0))

scrollContainerPastElement($scrollableContainer, $fixed)
Expand Down Expand Up @@ -229,7 +231,7 @@ const ensureElIsNotCovered = function (cy, win, $el, fromElViewport, options, lo

try {
ensureDescendentsAndScroll()
} catch (error) {
} catch (error: any) {
const err = error

if (log) {
Expand Down Expand Up @@ -352,7 +354,7 @@ const verify = function (cy, $el, config, options, callbacks) {
}

return Promise.try(() => {
const coordsHistory = []
const coordsHistory: (ElViewportPostion | ElWindowPostion)[] = []

const runAllChecks = function () {
let $elAtCoords
Expand Down
4 changes: 1 addition & 3 deletions packages/driver/src/cy/chai/inspect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

// Changes made: added 'formatValueHook' to process value before being formatted.
// For example the hook can be used to turn `window` objects into the string '[window]'
// to avoid deep recursion.
Expand Down Expand Up @@ -272,7 +270,7 @@ export function create (chai) {
}

function formatArray (ctx, value, recurseTimes, visibleKeys, keys) {
let output = []
let output: string[] = []

for (let i = 0, l = value.length; i < l; ++i) {
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
Expand Down
31 changes: 19 additions & 12 deletions packages/driver/src/cy/commands/agents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import _ from 'lodash'
import sinon from 'sinon'

Expand All @@ -8,7 +6,13 @@ import Promise from 'bluebird'
import $utils from '../../cypress/utils'
import $errUtils from '../../cypress/error_utils'

let counts = null
type Counts = {
spy: number
stub: number
children: Record<string, number>
}

let counts: Counts | null = null

sinon.setFormatter($utils.stringifyArg.bind($utils))

Expand All @@ -24,6 +28,8 @@ const display = (name) => {
if (name === 'stub') {
return 'Stubbed Obj'
}

return ''
AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
}

const formatArgs = (args) => {
Expand Down Expand Up @@ -59,7 +65,7 @@ const onInvoke = function (Cypress, obj, args) {
return
}

const logProps = {
const logProps: Record<string, any> = {
name: agentName,
message: obj.message,
error: obj.error,
Expand All @@ -68,7 +74,7 @@ const onInvoke = function (Cypress, obj, args) {
snapshot: !agent._noSnapshot,
event: true,
consoleProps () {
const consoleObj = {}
const consoleObj: Record<string, any> = {}

consoleObj.Command = null
consoleObj.Error = null
Expand Down Expand Up @@ -147,15 +153,15 @@ export default function (Commands, Cypress, cy, state) {
// to reset the counts + the sandbox
Cypress.on('test:before:run', resetAndSetSandbox)

const wrap = function (ctx, type, agent, obj, method, count) {
const wrap = function (ctx, type, agent, obj, method, count?) {
if (!count) {
count = (counts[type] += 1)
count = (counts![type] += 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other TS newbies curious what this ! is doing: Non-null assertion operator

}

const name = `${type}-${count}`

if (!agent.parent) {
counts.children[name] = 0
counts!.children[name] = 0
}

const log = Cypress.log({
Expand Down Expand Up @@ -184,7 +190,7 @@ export default function (Commands, Cypress, cy, state) {
// and the user can easily find the error
try {
returned = invoke.call(this, func, thisValue, args)
} catch (e) {
} catch (e: any) {
error = e
}

Expand Down Expand Up @@ -249,7 +255,7 @@ export default function (Commands, Cypress, cy, state) {
const { withArgs } = agent

agent.withArgs = function (...args) {
const childCount = (counts.children[name] += 1)
const childCount = (counts!.children[name] += 1)

return wrap(ctx, type, withArgs.apply(this, args), obj, method, `${count}.${childCount}`)
}
Expand All @@ -263,8 +269,9 @@ export default function (Commands, Cypress, cy, state) {
return wrap(this, 'spy', theSpy, obj, method)
}

const stub = function (obj, method, replacerFnOrValue) {
let theStub = sandbox.stub.call(sandbox, obj, method)
const stub = function (obj, method: string, replacerFnOrValue) {
// TODO: make the code below work with `packages/runner` type check without casting to `never`.
let theStub = sandbox.stub.call(sandbox, obj, method as never)

// sinon 2 changed the stub signature
// this maintains the 3-argument signature so it's not breaking
Expand Down
5 changes: 2 additions & 3 deletions packages/driver/src/cy/commands/aliasing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import _ from 'lodash'
import $dom from '../../dom'

Expand All @@ -22,9 +20,10 @@ export default function (Commands, Cypress, cy, state) {
})
}

// TODO: change the log type from `any` to `Log`.
// we also need to set the alias on the last command log
// that matches our chainerId
const log = _.last(cy.queue.logs({
const log: any = _.last(cy.queue.logs({
instrument: 'command',
event: false,
chainerId: state('chainerId'),
Expand Down
9 changes: 4 additions & 5 deletions packages/driver/src/cy/commands/angular.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import _ from 'lodash'
import $ from 'jquery'
import Promise from 'bluebird'
Expand Down Expand Up @@ -34,7 +32,7 @@ export default (Commands, Cypress, cy, state) => {
}

// else return null element
return $(null)
return $(null as any) // cast to any to satisfy typescript
}

const resolveElements = () => {
Expand All @@ -52,7 +50,7 @@ export default (Commands, Cypress, cy, state) => {
}

const findByNgAttr = (name, attr, el, options) => {
const selectors = []
const selectors: string[] = []
let error = `Could not find element for ${name}: '${el}'. Searched `

_.extend(options, { verify: false, log: false })
Expand Down Expand Up @@ -91,7 +89,8 @@ export default (Commands, Cypress, cy, state) => {
}

Commands.addAll({
ng (type, selector, options = {}) {
// TODO: Change the options type from `any` to `Partial<Cypress.Loggable & Cypress.Timeoutable>`.
ng (type, selector, options: any = {}) {
Copy link
Contributor

@tbiethman tbiethman Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth adding an explicit type for options if we are reading properties off of it. Or is this represented in the types already?

Edit: Based on your other changes, might need a TODO here.

AtofStryker marked this conversation as resolved.
Show resolved Hide resolved
const userOptions = options

// what about requirejs / browserify?
Expand Down
14 changes: 7 additions & 7 deletions packages/driver/src/cy/commands/asserting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import _ from 'lodash'
import Promise from 'bluebird'

Expand Down Expand Up @@ -27,7 +25,7 @@ export default function (Commands, Cypress, cy, state) {

const shouldFn = function (subject, chainers, ...args) {
if (_.isFunction(chainers)) {
return shouldFnWithCallback.apply(this, [subject, chainers, ...args]) // eslint-disable-line prefer-rest-params
return shouldFnWithCallback.apply(this, [subject, chainers])
}

let exp = cy.expect(subject).to
Expand All @@ -40,7 +38,7 @@ export default function (Commands, Cypress, cy, state) {
const log = Cypress.log({
name: 'should',
type: 'child',
message: [].concat(originalChainers, args),
message: ([] as any[]).concat(originalChainers, args),
end: true,
snapshot: true,
error: err,
Expand Down Expand Up @@ -69,7 +67,7 @@ export default function (Commands, Cypress, cy, state) {
if (_.isFunction(cmd)) {
try {
return cmd.apply(memo, args)
} catch (err) {
} catch (err: any) {
// if we made it all the way to the actual
// assertion but its set to retry false then
// we need to log out this .should since there
Expand Down Expand Up @@ -134,13 +132,15 @@ export default function (Commands, Cypress, cy, state) {

Commands.addAll({ type: 'assertion', prevSubject: true }, {
should () {
// Cast to `any` to pass all arguments
// eslint-disable-next-line prefer-rest-params
return shouldFn.apply(this, arguments)
return shouldFn.apply(this, arguments as any)
},

and () {
// Cast to `any` to pass all arguments
// eslint-disable-next-line prefer-rest-params
return shouldFn.apply(this, arguments)
return shouldFn.apply(this, arguments as any)
},
})
}
Loading