-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 3 #19837
chore: Remove pkg/driver //@ts-nocheck part 3 #19837
Conversation
Thanks for taking the time to open a PR!
|
@@ -673,6 +679,8 @@ export default (Commands, Cypress, cy, state, config) => { | |||
onFail: options._log, | |||
args: { str }, | |||
}) | |||
|
|||
return // Error is thrown above, it exists to satisfy typescript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make this cleaner to just return what is on line 678?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type of throwErrByPath
is void
, and 678 always throws. So, line 683 is never called. If we remove this line, TypeScript shows all path doesn't return value
error. That's why I left this comment.
In other languages like Java, there is throws
keyword that handles this situation, but TypeScript isn't. The link above is the request to that feature. It seems that it's forgotten or given low priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this comment, if you update error_utils.throwsErrorByPath to return type never, this should be fine without the extra return type.
@@ -685,9 +693,12 @@ export default (Commands, Cypress, cy, state, config) => { | |||
} | |||
|
|||
$errUtils.throwErrByPath('go.invalid_argument', { onFail: options._log }) | |||
|
|||
return // Error is thrown above, it exists to satisfy typescript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -15,7 +14,8 @@ const debug = debugFn('cypress:driver:command:type') | |||
export default function (Commands, Cypress, cy, state, config) { | |||
const { keyboard } = cy.devices | |||
|
|||
function type (subject, chars, options = {}) { | |||
// TODO: change the type of `any` to `Partial<Cypress.TypeOptions>` | |||
function type (subject, chars, options: any = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is preventing you from making this change now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cypress often extends then user-given options
with some internal values like in line 24-34.
cypress/packages/driver/src/cy/commands/actions/type.ts
Lines 24 to 34 in bc87d6e
options = _.defaults({}, userOptions, { | |
$el: subject, | |
log: true, | |
verify: true, | |
force: false, | |
delay: config('keystrokeDelay') || $Keyboard.getConfig().keystrokeDelay, | |
release: true, | |
parseSpecialCharSequences: true, | |
waitForAnimations: config('waitForAnimations'), | |
animationDistanceThreshold: config('animationDistanceThreshold'), | |
}) |
And TypeScript treats it as a type error. That's why it's commented.
By the way, I tried to rename user-given options
and internal options as opts
in #6459. But it was rejected and refactored in the current style. Maybe we need to find a way to name our internal option objects to solve this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a small notes summarizing what you explained here? It makes sense to me but might not be obvious to others without doing a deeper drive into the code base on the work required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that this comment exists on almost every command. So it's a bit hard to find the right place.
And I'll remove all of them after removing // @ts-nocheck
comments. (I believe the part 4 will be the final.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I estimated when removing TODO
s will be done. And it might take 1-2 months in current speed. So, I decided to add a note above.
I guess we need this somewhere in our code.
import _ from 'lodash' | ||
import Promise from 'bluebird' | ||
|
||
import $dom from '../../dom' | ||
import $utils from '../../cypress/utils' | ||
import $errUtils from '../../cypress/error_utils' | ||
import $errUtils, { CypressError } from '../../cypress/error_utils' | ||
|
||
const returnFalseIfThenable = (key, ...args) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const returnFalseIfThenable = (key, ...args) => { | |
const returnFalseIfThenable = (key, ...args): boolean => { |
@@ -110,7 +108,7 @@ export default function (Commands, Cypress, cy, state, config) { | |||
}) | |||
} | |||
|
|||
const getAndClear = (log, timeout, options = {}) => { | |||
const getAndClear = (log?, timeout?, options = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is log optional here? it's not optional for automateCookies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's called without them at line 164.
return getAndClear() |
let previousDomainVisited: boolean | null = null | ||
let hasVisitedAboutBlank: boolean | null = null | ||
let currentlyVisitingAboutBlank: boolean | null = null | ||
let knownCommandCausedInstability: boolean | null = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the defaults should be updated to false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -17,9 +15,9 @@ const crossOriginScriptRe = /^script error/i | |||
|
|||
if (!Error.captureStackTrace) { | |||
Error.captureStackTrace = (err, fn) => { | |||
const stack = (new Error()).stack | |||
const stack = (new Error()).stack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const stack = (new Error()).stack; | |
const stack = (new Error()).stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;
is necessary here because JavaScript tries to translate .stack\n\n(err as Error)
as a function call.
return _.startsWith(err.message, 'Invalid Chai property') | ||
} | ||
|
||
const isCypressErr = (err = {}) => { | ||
const isCypressErr = (err: Error) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isCypressErr = (err: Error) => { | |
const isCypressErr = (err: Error): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -197,20 +195,20 @@ const makeErrFromObj = (obj) => { | |||
return err2 | |||
} | |||
|
|||
const throwErr = (err, options = {}) => { | |||
const throwErr = (err, options: any = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const throwErr = (err, options: any = {}) => { | |
const throwErr = (err, options: any = {}): never => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As never
means a function never reaches its end, I had to create makeErrFromErr
function.
@@ -227,7 +225,7 @@ const throwErr = (err, options = {}) => { | |||
throw err | |||
} | |||
|
|||
const throwErrByPath = (errPath, options = {}) => { | |||
const throwErrByPath = (errPath, options: any = {}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const throwErrByPath = (errPath, options: any = {}) => { | |
const throwErrByPath = (errPath, options: any = {}): never => { |
07d37f0
to
f3fe6cd
Compare
import _ from 'lodash' | ||
|
||
import { scrollTo } from './jquery.scrollto' | ||
import $dom from '../dom' | ||
|
||
// Add missing types. | ||
interface ExtendedJQueryStatic extends JQueryStatic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this caused typescript errors for individuals using JQuery methods other than find and expr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm. this isn't the types provided via the cli! sorry aboutt that
@sainthkh can you take a look at the failing tests? |
8a25a22
to
6844eae
Compare
|
6844eae
to
4c9b618
Compare
4c9b618
to
b47480f
Compare
* develop: feat: gray out the path to system node in cypress run header (#20121) feat: redesign server errors (#20072) test: fix awesome-typescript-loader test and remove test-binary job (#20131) fix: Fix issues with stack traces and command log in Chrome 99 (#20049) fix: `cy.type(' ')` fires click event on button-like elements. (#20067) fix: `change`, `input` events are not fired when the same option is selected again. (#19623) build: publish vue3 on latest (#20099) chore: release @cypress/webpack-preprocessor-v5.11.1 chore: release @cypress/webpack-dev-server-v1.8.1 fix: detect newly added specs in dev-server compilation (#17950) chore: Remove pkg/driver //@ts-nocheck part 3 (#19837) chore: set up semantic-pull-request GitHub Action (#20091) chore: release @cypress/react-v5.12.2 fix: remove nullish coalescing in js files to support node 12 (#20094) docs: update @cypress/webpack-preprocessor links (#19902) refactor: use aliases instead of meta (#19566)
create
into class$Cy
#18715User facing changelog
N/A. It's just removing
// @ts-nocheck
comments and defining types to avoid type errors.Additional details
How has the user experience changed?
N/A
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?