-
Notifications
You must be signed in to change notification settings - Fork 1.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
fix setting js options on the wrong object #1430
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not very familiar with Goja's API, but shouldn't we also conversely do
s/rt/exports/
on line 231 below?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 ... and I looked for other instances 🤦
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.
Of course, this will now fail 😭 ... because #722 made the test to expect that if you didn't define
options
it will be overwritten ... which might not be the worst idea ... I dunno, but we will probably need to discuss this. Also, I remember that there were some problems around this in the cloud which even more leads me to believe @na-- will need to say something on the matter ;)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.
hmm I first started rebasing this without reading the comments, but looking at the test that's failing, how sure are we that this fix isn't a breaking change?
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 long as people use
and babel, which is ... I would go with the majority - they won't notice a thing ...
the same code with ES5.1 is
If someone decided that if you just don't make a variable
options
at all or that variable is then not set toexports.options
and then they expect thatoptions
(notexports.options
) will exist - then yes they will find out that this won't work.for the record I don't think this has ever happened apart from this test you wrote.
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.
Hm, when it failed for me it was only the first three "variants" which are :
https://github.com/loadimpact/k6/blob/35784c2498a14a06565b5d1e87ef05f721820675/js/runner_test.go#L138-L140
so.. no options or one that is defined as null or undefined ...
I have no idea why you decided that this should work in the first place, hence the mention above for you to look at it. IMO this shouldn't have worked like that and I would be surprised if someone depended on this behavior... and if so I would argue they need to the corresponding changes :D
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 think it should work, since I think a valid use case would be to run a k6 script with absolutely no exported script
options
, but to instead specify the options via environment variables or CLI flags or a JSON config or a mix of those. In that scenario, you should still be able to know with what actual options your script is being executed, from inside of the script...That said, if I had considered the issue carefully when I implemented it, I might have required an exported empty
options
to exist for that feature to work... But I didn't, so now this is a breaking change that will probably break some people's scripts, especially those running k6 unsupervised 😞 So, I'd have to give it a 👎, unless there is some bigger issue with the current implementation that I'm missing? What are the problems caused by just settingoptions
in the global script scope, regardless of if it's exported or not? This is sort of how we do__ENV
,__VU
and__ITER
, right?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 would mostly argue that given that we read from (and only)
exports.options
, when we set options we should be setting them onexports.options
.I highly doubt that this makes much of a difference for anyone writing a script, but if you believe so, I can agree to have
options
be special variable just like__ENV
,__VU
and__ITER
but I would argue this will need to be also documented. And then just have it copy it fromexports.options
... although I have to say I don't like it ...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.
Yeah, I don't like it very much either... I'd be fine to make the
jsOptions := exports.Get("options")
change, but the setting of the final consolidatedoptions
back seems like it should be either like it currently is, or to bothexports
and a global variable.In any case, unless I'm missing some fundamental issue here, this can keep. We've had this issue for a while and nobody has complained AFAIK, so I'm tagging this for 0.28.0
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 definitely can wait ... I just found it doing the js optimizations PR :D