-
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: refactor cy funcs #19080
chore: refactor cy funcs #19080
Conversation
Thanks for taking the time to open a PR!
|
a9905ac
to
7bd9315
Compare
@@ -14,7 +14,7 @@ import browserInfo from './cypress/browser' | |||
import $scriptUtils from './cypress/script_utils' | |||
|
|||
import $Commands from './cypress/commands' | |||
import $Cy from './cypress/cy' | |||
import { $Cy } from './cypress/cy' |
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.
import { $Cy } from './cypress/cy' | |
import { Cy } from './cypress/cy' |
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 name of the internal class is $Cy
, not Cy
.
const add = (command) => { | ||
queue.add(command) | ||
} |
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.
Did this get dropped on accident?
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.
This can be deleted because we are using inheritance in the new code.
timeout: any | ||
whenStable: any | ||
cleanup: any | ||
fail: 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.
Shouldn't timeout
, cleanup
, fail
, be of type func?
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.
Precisely, they are $Cy['timeout']
, $Cy['cleanup']
, $Cy['fail']
. But the problem is that it creates a circular reference problem because command_queue
is required in cy.ts
.
The goal of this PR is migrating functions inside _.extend(cy, {})
to $Cy
class. So, I left them out for the later PR.
whenStable: any | ||
cleanup: any | ||
fail: any | ||
isCy: 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.
Should the types match what is documented?
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.
You're right. I'll handle this in the part 3 of this PR series.
export class CommandQueue extends Queue<Command> { | ||
state: any | ||
timeout: any | ||
whenStable: 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.
Isn't this a promise type?
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.
Yes, it's a function that returns a Promise
(code here).
As I said above, it's left out for the part 3.
I decided to do this later because this PR is big enough for now(+1000/-1000) and there are some hard things like state
below and other problems hidden by //@ts-nocheck
.
const logs = (filter) => { | ||
let logs = _.flatten(_.invokeMap(queue.get(), 'get', 'logs')) | ||
export class CommandQueue extends Queue<Command> { | ||
state: 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.
Should this be the GetterSetter type? https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/setter_getter.d.ts
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 type of state
function isn't that easy. To make it useful for our development, we need to create a new definition like:
interface StateFunc {
(param: 'document') => Document
(param: 'done') => boolean
// etc..
}
I left it as any
to do this work in the next PR.
// push these onto the beginning of the commands array | ||
memo.unshift(command) | ||
const wrap = function (firstCall) { | ||
fn = cy.commandFns[name] |
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.
fn = cy.commandFns[name] | |
fn = this.commandFns[name] |
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.
It should be cy
because wrap
function is not an arrow function. When we use this
, this
tries to find the value connected with wrap
, not the instance of class $Cy
.
26dbd3e
to
7ed0d70
Compare
// create cy and expose globally | ||
this.cy = $Cy.create(specWindow, this, this.Cookies, this.state, this.config, logFn) | ||
this.cy = new $Cy(specWindow, this, this.Cookies, this.state, this.config) |
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.
For curious reviewers, logFn isn't used by the constructor (or even the create function at this point) so it's safe to omit.
export default { | ||
create: <T>(queueables: T[] = []) => { | ||
let stopped = false | ||
export class Queue<T> { |
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 we continue to have this be the default export?
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.
There is no written or public guideline for Cypress project. But default
is usually removed, because it's a translation of module.exports = {}
.
Can I ask you why we should use default
for this?
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.
It was previously the default export, so I was just curious why it changed. For files that have a single export that is sufficiently described by the file name, I have preferred a default export over an individual one.
But without an active lint rule or other guidelines to enforce it, this is fine if it's consistent with other files in the package.
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 took the changes for a test drive and saw no issues locally 👍
* develop: chore(deps): update dependency ssri to 6.0.2 [security] (#19351) chore: Fix server unit tests running on mac by using actual tmp dir (#19350) fix: Add more precise types to Cypress.Commands (#19003) fix: Do not screenshot or trigger the failed event when tests are skipped (#19331) fix (#19262) fix: throw when writing to 'read only' properties of `config` (#18896) fix: close chrome when closing electron (#19322) fix: disable automatic request retries (#19161) chore: refactor cy funcs (#19080) chore(deps): update dependency @ffmpeg-installer/ffmpeg to v1.1.0 🌟 (#19300)
…cycle * 10.0-release: build: remove syncRemoteGraphQL from codegen chore: fix incorrect type from merge build: allow work with local dashboard (#19376) chore: Test example recipes against chrome (#19362) test(unify): Settings e2e tests (#19324) chore(deps): update dependency ssri to 6.0.2 [security] (#19351) fix: spec from story generation, add deps for install (#19352) chore: Fix server unit tests running on mac by using actual tmp dir (#19350) fix: Add more precise types to Cypress.Commands (#19003) fix: Do not screenshot or trigger the failed event when tests are skipped (#19331) fix (#19262) fix: throw when writing to 'read only' properties of `config` (#18896) fix: close chrome when closing electron (#19322) fix: disable automatic request retries (#19161) chore: refactor cy funcs (#19080) chore(deps): update dependency @ffmpeg-installer/ffmpeg to v1.1.0 🌟 (#19300)
create
into class$Cy
#18715User facing changelog
N/A. It's a refactoring.
Additional details
_.extend()
.cy
functions toclass $Cy
.How has the user experience changed?
N/A
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?