-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Clone command options before passing into commands #3171
Comments
I don't think this is a good idea, because cloning every single argument sent to every single command unnecessarily is pretty wasteful and will add some slowdown to Cypress, especially if people are using large objects in commands. I think that commands that use the identity of the object, or modify the object passed in, should clone options themselves as needed. We should probably do some kind of audit/add new tests to catch others like |
We could at least freeze a command object to avoid messing with it
…Sent from my iPhone
On Nov 7, 2019, at 16:05, Zach Bloomquist ***@***.***> wrote:
I don't think this is a good idea, because cloning every single argument sent to every single command unnecessarily is pretty wasteful and will add some slowdown to Cypress, especially if people are using large objects in commands.
I think that commands that use the identity of the object, or modify the object passed in, should clone options themselves as needed. We should probably do some kind of audit/add new tests to catch others like cy.setCookie that don't act right.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I tried a little thing with function callCommand(cmdFn, args) {
'use strict'
Object.freeze(args)
try {
cmdFn(args)
} catch (e) {
console.log('The options passed in were modified')
console.log(e)
}
}
callCommand(
(args) => { args.b = 'foo' },
{ b: 'bar' }
) ...but since the callback is defined outside the I think if we just freeze random objects without visibility, it's likely to cause more bugs than it would solve. Maybe we could use |
The cause of this problem is the line like this in each command: _.defaults options,
$el: subject
log: true
force: false (This line is from check.coffee) As you know, _.default() mutates the object (in our case, Because of this, freezing will just make problem bigger. (You cannot add default values to the To solve this problem, we need to open every command file and fix all those lines like this (fix 1). opts = _.default {}, options,
$el: subject
log: true
force: false And change Or we can write like this (fix 2): options = _.defaults {}, options,
$el: subject
log: true
force: false In this case, you don't have to change Personally, I prefer the first solution because it doesn't override given argument value. As a matter of fact, I have a related PR (#5762). I had to open every command to show user-defined When I was writing it, I didn't know about this issue and thought If you let me, I will revisit that PR and fix those |
@sainthkh A PR to get rid of the |
The code for this is done in cypress-io/cypress#6459, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
When commands receive options, it is the original object and not a clone. This has resulted in a few bugs (#2707, #365), and probably some more I couldn't quickly track down.
Desired behavior:
This should be done before options are passed into commands so all commands receive options in the same frozen state.
The text was updated successfully, but these errors were encountered: