-
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 log function to class #20382
chore: refactor log function to class #20382
Conversation
Thanks for taking the time to open a PR!
|
|
||
if (!(!_.isFunction(value) || !groupsOrTableRe.test(key))) { |
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 changed this part to _.isFunction(value) && groupsOrTableRe.test(key)
, because it's a bit hard to read with double negation.
|
||
this.fireChangeEvent() |
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 has been changed to this.logManager.fireChangeEvent(this)
.
@@ -613,25 +631,5 @@ function create (Cypress, cy, state, config) { | |||
return log | |||
} | |||
|
|||
logFn._logs = logs |
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 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.
Thanks for the clean up!
packages/driver/src/cypress/log.ts
Outdated
// as fast as every 4ms | ||
// @ts-ignore | ||
log.fireChangeEvent = _.debounce(triggerStateChanged, 4) | ||
const log = new Log(cy, state, config, logManager, 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.
Are we able to pass logManager.fireChangeEvent
instead of the entire class instance? Since the logManger stores all of the incoming logs, this feels heavy to each log instance.
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.
packages/driver/src/cypress/log.ts
Outdated
|
||
const triggerStateChanged = () => { | ||
return trigger(log, 'command:log:changed') | ||
export function create (Cypress, cy, state, 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.
any reason the logFn logic couldn't live in the LogManager ?
export function create (Cypress, cy, state, config) {
const logManager = new LogManager()
return logManager.createLog(cy, state, config, logManager, 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.
I left it there because it was there for years.
After your comment, I also thought about it and it's Manager's job to create logFn
. So, I moved it.
2d0358e
to
ce95894
Compare
User facing changelog
N/A. It's an internal refactoring
Additional details
Summary of changes.
As it's a refactoring, the code change is hard to read. So, I left this.
LogUtils
,LogManager
,Log
.LogUtils
are functions used in other files. They were exported withexport default
. I could remove them.LogManager
: Insidecreate
function,logs
variable exists and it manages logs created. But it makes us createfireChangeEvent
function insidecreate
function and attach it toLog
. So, I createdLogManager
class andLog
class reference it.Log
: It was a function that returns an object. I changed it to a class.How has the user experience changed?
N/A
PR Tasks
cypress-documentation
?type definitions
?cypress.schema.json
?