Skip to content

Commit 01f0261

Browse files
sainthkhmjhenkesryanthemanuel
authored
chore: Remove pkg/driver @ts-nocheck part 1 (#19353)
Co-authored-by: Matt Henkes <[email protected]> Co-authored-by: Ryan Manuel <[email protected]>
1 parent b3d114e commit 01f0261

File tree

9 files changed

+188
-119
lines changed

9 files changed

+188
-119
lines changed

packages/driver/patches/unfetch+4.1.0.dev.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ index 57a2761..0000000
6464
@@ -1 +0,0 @@
6565
-{"version":3,"file":"unfetch.umd.js","sources":["../src/index.mjs"],"sourcesContent":["export default function(url, options) {\n\toptions = options || {};\n\treturn new Promise( (resolve, reject) => {\n\t\tconst request = new XMLHttpRequest();\n\t\tconst keys = [];\n\t\tconst all = [];\n\t\tconst headers = {};\n\n\t\tconst response = () => ({\n\t\t\tok: (request.status/100|0) == 2,\t\t// 200-299\n\t\t\tstatusText: request.statusText,\n\t\t\tstatus: request.status,\n\t\t\turl: request.responseURL,\n\t\t\ttext: () => Promise.resolve(request.responseText),\n\t\t\tjson: () => Promise.resolve(JSON.parse(request.responseText)),\n\t\t\tblob: () => Promise.resolve(new Blob([request.response])),\n\t\t\tclone: response,\n\t\t\theaders: {\n\t\t\t\tkeys: () => keys,\n\t\t\t\tentries: () => all,\n\t\t\t\tget: n => headers[n.toLowerCase()],\n\t\t\t\thas: n => n.toLowerCase() in headers\n\t\t\t}\n\t\t});\n\n\t\trequest.open(options.method || 'get', url, true);\n\n\t\trequest.onload = () => {\n\t\t\trequest.getAllResponseHeaders().replace(/^(.*?):[^\\S\\n]*([\\s\\S]*?)$/gm, (m, key, value) => {\n\t\t\t\tkeys.push(key = key.toLowerCase());\n\t\t\t\tall.push([key, value]);\n\t\t\t\theaders[key] = headers[key] ? `${headers[key]},${value}` : value;\n\t\t\t});\n\t\t\tresolve(response());\n\t\t};\n\n\t\trequest.onerror = reject;\n\n\t\trequest.withCredentials = options.credentials=='include';\n\n\t\tfor (const i in options.headers) {\n\t\t\trequest.setRequestHeader(i, options.headers[i]);\n\t\t}\n\n\t\trequest.send(options.body || null);\n\t});\n}\n"],"names":["url","options","Promise","resolve","reject","request","XMLHttpRequest","keys","all","headers","response","ok","status","statusText","responseURL","text","responseText","json","JSON","parse","blob","Blob","clone","entries","get","n","toLowerCase","has","const","i","open","method","onload","getAllResponseHeaders","replace","m","key","value","push","onerror","withCredentials","credentials","setRequestHeader","send","body"],"mappings":"6KAAe,SAASA,EAAKC,UAC5BA,EAAUA,GAAW,GACd,IAAIC,iBAAUC,EAASC,OACvBC,EAAU,IAAIC,eACdC,EAAO,GACPC,EAAM,GACNC,EAAU,GAEVC,oBACLC,GAA8B,IAAzBN,EAAQO,OAAO,IAAI,GACxBC,WAAYR,EAAQQ,WACpBD,OAAQP,EAAQO,OAChBZ,IAAKK,EAAQS,YACbC,uBAAYb,QAAQC,QAAQE,EAAQW,eACpCC,uBAAYf,QAAQC,QAAQe,KAAKC,MAAMd,EAAQW,gBAC/CI,uBAAYlB,QAAQC,QAAQ,IAAIkB,KAAK,CAAChB,EAAQK,aAC9CY,MAAOZ,EACPD,QAAS,CACRF,uBAAYA,GACZgB,0BAAef,GACfgB,aAAKC,UAAKhB,EAAQgB,EAAEC,gBACpBC,aAAKF,UAAKA,EAAEC,gBAAiBjB,UAmB1BmB,IAAMC,KAfXxB,EAAQyB,KAAK7B,EAAQ8B,QAAU,MAAO/B,GAAK,GAE3CK,EAAQ2B,kBACP3B,EAAQ4B,wBAAwBC,QAAQ,wCAAiCC,EAAGC,EAAKC,GAChF9B,EAAK+B,KAAKF,EAAMA,EAAIV,eACpBlB,EAAI8B,KAAK,CAACF,EAAKC,IACf5B,EAAQ2B,GAAO3B,EAAQ2B,GAAU3B,EAAQ2B,OAAQC,EAAUA,IAE5DlC,EAAQO,MAGTL,EAAQkC,QAAUnC,EAElBC,EAAQmC,gBAAuC,WAArBvC,EAAQwC,YAElBxC,EAAQQ,QACvBJ,EAAQqC,iBAAiBb,EAAG5B,EAAQQ,QAAQoB,IAG7CxB,EAAQsC,KAAK1C,EAAQ2C,MAAQ"}
6666
\ No newline at end of file
67+
diff --git a/node_modules/unfetch/src/index.d.ts b/node_modules/unfetch/src/index.d.ts
68+
index 0c53ad9..8dd2d54 100644
69+
--- a/node_modules/unfetch/src/index.d.ts
70+
+++ b/node_modules/unfetch/src/index.d.ts
71+
@@ -14,4 +14,6 @@ declare namespace unfetch {
72+
73+
declare const unfetch: typeof fetch;
74+
75+
+export function registerFetch(window: Window): unfetch;
76+
+
77+
export default unfetch;
6778
diff --git a/node_modules/unfetch/src/index.mjs b/node_modules/unfetch/src/index.mjs
6879
deleted file mode 100644
6980
index 783ad42..0000000

packages/driver/src/cy/assertions.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

@@ -54,12 +52,18 @@ const isDomSubjectAndMatchesValue = (value, subject) => {
5452
return false
5553
}
5654

55+
type Parsed = {
56+
subject?: JQuery<any>
57+
actual?: any
58+
expected?: any
59+
}
60+
5761
// Rules:
5862
// 1. always remove value
5963
// 2. if value is a jquery object set a subject
6064
// 3. if actual is undefined or its not expected remove both actual + expected
6165
const parseValueActualAndExpected = (value, actual, expected) => {
62-
const obj = { actual, expected }
66+
const obj: Parsed = { actual, expected }
6367

6468
if ($dom.isJquery(value)) {
6569
obj.subject = value
@@ -77,7 +81,7 @@ export const create = (Cypress, cy) => {
7781
const getUpcomingAssertions = () => {
7882
const index = cy.state('index') + 1
7983

80-
const assertions = []
84+
const assertions: any[] = []
8185

8286
// grab the rest of the queue'd commands
8387
for (let cmd of cy.queue.slice(index)) {
@@ -137,7 +141,11 @@ export const create = (Cypress, cy) => {
137141
message = message.replace(stackTracesRe, '\n')
138142
}
139143

140-
let obj = parseValueActualAndExpected(value, actual, expected)
144+
let parsed = parseValueActualAndExpected(value, actual, expected)
145+
// TODO: make it more specific after defining the type for Cypress.log().
146+
let obj: Record<string, any> = {
147+
...parsed,
148+
}
141149

142150
if ($dom.isElement(value)) {
143151
obj.$el = $dom.wrap(value)
@@ -216,10 +224,18 @@ export const create = (Cypress, cy) => {
216224
})
217225
}
218226

227+
type VerifyUpcomingAssertionsCallbacks = {
228+
ensureExistenceFor?: 'subject' | 'dom' | boolean
229+
onPass?: Function
230+
onFail?: (err?, isDefaultAssertionErr?: boolean, cmds?: any[]) => void
231+
onRetry?: () => any
232+
}
233+
219234
return {
220235
finishAssertions,
221236

222-
verifyUpcomingAssertions (subject, options = {}, callbacks = {}) {
237+
// TODO: define the specific type of options
238+
verifyUpcomingAssertions (subject, options: Record<string, any> = {}, callbacks: VerifyUpcomingAssertionsCallbacks = {}) {
223239
const cmds = getUpcomingAssertions()
224240

225241
cy.state('upcomingAssertions', cmds)
@@ -433,12 +449,13 @@ export const create = (Cypress, cy) => {
433449
cy.state('onBeforeLog', setCommandLog)
434450

435451
// send verify=true as the last arg
436-
return assertFn.apply(this, args.concat(true))
452+
return assertFn.apply(this, args.concat(true) as any)
437453
}
438454

439455
const fns = injectAssertionFns(cmds)
440456

441-
const subjects = []
457+
// TODO: remove any when the type of subject, the first argument of this function is specified.
458+
const subjects: any[] = []
442459

443460
// iterate through each subject
444461
// and force the assertion to return

packages/driver/src/cy/chai.ts

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
/* eslint-disable prefer-rest-params */
32
// tests in driver/cypress/integration/commands/assertions_spec.js
43

@@ -31,20 +30,6 @@ const whitespace = /\s/g
3130
const valueHasLeadingOrTrailingWhitespaces = /\*\*'\s+|\s+'\*\*/g
3231
const imageMarkdown = /!\[.*?\]\(.*?\)/g
3332

34-
let assertProto = null
35-
let matchProto = null
36-
let lengthProto = null
37-
let containProto = null
38-
let existProto = null
39-
let getMessage = null
40-
let chaiUtils = null
41-
let replaceArgMessages = null
42-
let removeOrKeepSingleQuotesBetweenStars = null
43-
let setSpecWindowGlobals = null
44-
let restoreAsserts = null
45-
let overrideExpect = null
46-
let overrideChaiAsserts = null
47-
4833
type CreateFunc = ((specWindow, state, assertFn) => ({
4934
chai: Chai.ChaiStatic
5035
expect: (val: any, message?: string) => Chai.Assertion
@@ -55,7 +40,7 @@ export let create: CreateFunc | null = null
5540
chai.use(sinonChai)
5641

5742
chai.use((chai, u) => {
58-
chaiUtils = u
43+
const chaiUtils = u
5944

6045
$chaiJquery(chai, chaiUtils, {
6146
onInvalid (method, obj) {
@@ -87,14 +72,14 @@ chai.use((chai, u) => {
8772
},
8873
})
8974

90-
assertProto = chai.Assertion.prototype.assert
91-
matchProto = chai.Assertion.prototype.match
92-
lengthProto = chai.Assertion.prototype.__methods.length.method
93-
containProto = chai.Assertion.prototype.__methods.contain.method
94-
existProto = Object.getOwnPropertyDescriptor(chai.Assertion.prototype, 'exist').get
95-
const { objDisplay } = chai.util;
75+
const assertProto = chai.Assertion.prototype.assert
76+
const matchProto = (chai.Assertion.prototype as any).match
77+
const lengthProto = (chai.Assertion.prototype as any).__methods.length.method
78+
const containProto = (chai.Assertion.prototype as any).__methods.contain.method
79+
const existProto = Object.getOwnPropertyDescriptor(chai.Assertion.prototype, 'exist')!.get
80+
const { objDisplay } = chai.util
9681

97-
({ getMessage } = chai.util)
82+
const getMessage = chai.util.getMessage
9883
const _inspect = chai.util.inspect
9984

10085
const { inspect, setFormatValueHook } = chaiInspect.create(chai)
@@ -108,17 +93,19 @@ chai.use((chai, u) => {
10893
try {
10994
val && val.document
11095
val && val.inspect
111-
} catch (e) {
96+
} catch (e: any) {
11297
if (e.stack.indexOf('cross-origin') !== -1 || // chrome
11398
e.message.indexOf('cross-origin') !== -1) { // firefox
11499
return `[window]`
115100
}
116101
}
102+
103+
return
117104
})
118105

119106
// remove any single quotes between our **,
120107
// except escaped quotes, empty strings and number strings.
121-
removeOrKeepSingleQuotesBetweenStars = (message) => {
108+
const removeOrKeepSingleQuotesBetweenStars = (message) => {
122109
// remove any single quotes between our **, preserving escaped quotes
123110
// and if an empty string, put the quotes back
124111
return message.replace(allBetweenFourStars, (match) => {
@@ -149,8 +136,8 @@ chai.use((chai, u) => {
149136
return message.replace(imageMarkdown, '``$&``')
150137
}
151138

152-
replaceArgMessages = (args, str) => {
153-
return _.reduce(args, (memo, value, index) => {
139+
const replaceArgMessages = (args, str) => {
140+
return _.reduce(args, (memo: string[], value, index) => {
154141
if (_.isString(value)) {
155142
value = value
156143
.replace(allWordsBetweenCurlyBraces, '**$1**')
@@ -166,18 +153,17 @@ chai.use((chai, u) => {
166153
}
167154

168155
return memo
169-
}
170-
, [])
156+
}, [])
171157
}
172158

173-
restoreAsserts = function () {
159+
const restoreAsserts = function () {
174160
chai.util.inspect = _inspect
175161
chai.util.getMessage = getMessage
176162
chai.util.objDisplay = objDisplay
177-
chai.Assertion.prototype.assert = assertProto
178-
chai.Assertion.prototype.match = matchProto
179-
chai.Assertion.prototype.__methods.length.method = lengthProto
180-
chai.Assertion.prototype.__methods.contain.method = containProto
163+
chai.Assertion.prototype.assert = assertProto;
164+
(chai.Assertion.prototype as any).match = matchProto;
165+
(chai.Assertion.prototype as any).__methods.length.method = lengthProto;
166+
(chai.Assertion.prototype as any).__methods.contain.method = containProto
181167

182168
return Object.defineProperty(chai.Assertion.prototype, 'exist', { get: existProto })
183169
}
@@ -218,7 +204,7 @@ chai.use((chai, u) => {
218204
}
219205
}
220206

221-
overrideChaiAsserts = function (specWindow, state, assertFn) {
207+
const overrideChaiAsserts = function (specWindow, state, assertFn) {
222208
chai.Assertion.prototype.assert = createPatchedAssert(specWindow, state, assertFn)
223209

224210
const _origGetmessage = function (obj, args) {
@@ -248,6 +234,9 @@ chai.use((chai, u) => {
248234
return (flagMsg ? `${flagMsg}: ${msg}` : msg)
249235
}
250236

237+
// There are 2 types of getMessage. And we're overriding the second one.
238+
// But TypeScript wants us to do both. So we're ignoring this.
239+
// @ts-ignore
251240
chaiUtils.getMessage = function (assert, args) {
252241
const obj = assert._obj
253242

@@ -307,13 +296,16 @@ chai.use((chai, u) => {
307296
})
308297
}
309298

310-
const containFn2 = (_super) => {
299+
const makeMethodChainable = (_super) => {
311300
return (function () {
312301
return _super.apply(this, arguments)
313302
})
314303
}
315304

316-
chai.Assertion.overwriteChainableMethod('contain', containFn1, containFn2)
305+
// `makeMethodChainable` doesn't match any type definition,
306+
// but it is necessary to make the method chainable.
307+
// @ts-ignore
308+
chai.Assertion.overwriteChainableMethod('contain', containFn1, makeMethodChainable)
317309

318310
chai.Assertion.overwriteChainableMethod('length',
319311
(_super) => {
@@ -346,7 +338,7 @@ chai.use((chai, u) => {
346338
length,
347339
obj.length,
348340
)
349-
} catch (e1) {
341+
} catch (e1: any) {
350342
e1.node = node
351343
e1.negated = chaiUtils.flag(this, 'negate')
352344
e1.type = 'length'
@@ -377,21 +369,21 @@ chai.use((chai, u) => {
377369
}
378370
})
379371
},
380-
381-
(_super) => {
382-
return (function () {
383-
return _super.apply(this, arguments)
384-
})
385-
})
386-
387-
return chai.Assertion.overwriteProperty('exist', (_super) => {
372+
// `makeMethodChainable` doesn't match any type definition,
373+
// but it is necessary to make the method chainable.
374+
// @ts-ignore
375+
makeMethodChainable)
376+
377+
// _super is not documented.
378+
// @ts-ignore
379+
chai.Assertion.overwriteProperty('exist', (_super) => {
388380
return (function () {
389381
const obj = this._obj
390382

391383
if (!($dom.isJquery(obj) || $dom.isElement(obj))) {
392384
try {
393385
return _super.apply(this, arguments)
394-
} catch (e) {
386+
} catch (e: any) {
395387
e.type = 'existence'
396388
throw e
397389
}
@@ -412,7 +404,7 @@ chai.use((chai, u) => {
412404
node,
413405
node,
414406
)
415-
} catch (e1) {
407+
} catch (e1: any) {
416408
e1.node = node
417409
e1.negated = chaiUtils.flag(this, 'negate')
418410
e1.type = 'existence'
@@ -456,20 +448,20 @@ chai.use((chai, u) => {
456448
const createPatchedAssert = (specWindow, state, assertFn) => {
457449
return (function (...args) {
458450
let err
459-
const passed = chaiUtils.test(this, args)
451+
const passed = chaiUtils.test(this, args as Chai.AssertionArgs)
460452
const value = chaiUtils.flag(this, 'object')
461453
const expected = args[3]
462454

463455
const customArgs = replaceArgMessages(args, this._obj)
464456

465-
let message = chaiUtils.getMessage(this, customArgs)
466-
const actual = chaiUtils.getActual(this, customArgs)
457+
let message = chaiUtils.getMessage(this, customArgs as Chai.AssertionArgs)
458+
const actual = chaiUtils.getActual(this, customArgs as Chai.AssertionArgs)
467459

468460
message = removeOrKeepSingleQuotesBetweenStars(message)
469461
message = escapeMarkdown(message)
470462

471463
try {
472-
assertProto.apply(this, args)
464+
assertProto.apply(this, args as Chai.AssertionArgs)
473465
} catch (e) {
474466
err = e
475467
}
@@ -489,7 +481,7 @@ chai.use((chai, u) => {
489481
})
490482
}
491483

492-
overrideExpect = (specWindow, state) => {
484+
const overrideExpect = (specWindow, state) => {
493485
// only override assertions for this specific
494486
// expect function instance so we do not affect
495487
// the outside world
@@ -523,7 +515,7 @@ chai.use((chai, u) => {
523515
return fn
524516
}
525517

526-
setSpecWindowGlobals = function (specWindow, state) {
518+
const setSpecWindowGlobals = function (specWindow, state) {
527519
const expect = overrideExpect(specWindow, state)
528520
const assert = overrideAssert(specWindow, state)
529521

@@ -552,12 +544,3 @@ chai.use((chai, u) => {
552544
export interface IChai {
553545
expect: ReturnType<CreateFunc>['expect']
554546
}
555-
556-
export default {
557-
replaceArgMessages,
558-
removeOrKeepSingleQuotesBetweenStars,
559-
setSpecWindowGlobals,
560-
restoreAsserts,
561-
overrideExpect,
562-
overrideChaiAsserts,
563-
}

packages/driver/src/cy/keyboard.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export type KeyEventType =
114114
| 'textInput'
115115
| 'beforeinput'
116116

117+
export type ModifiersEventOptions = {
118+
altKey: boolean
119+
ctrlKey: boolean
120+
metaKey: boolean
121+
shiftKey: boolean
122+
}
123+
117124
const toModifiersEventOptions = (modifiers: KeyboardModifiers) => {
118125
return {
119126
altKey: modifiers.alt,

0 commit comments

Comments
 (0)