-
Notifications
You must be signed in to change notification settings - Fork 42
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
Map k6 browser API to Goja #673
Conversation
b142322
to
4fa0f6b
Compare
4fa0f6b
to
f46a236
Compare
f46a236
to
995b4ed
Compare
21ad06b
to
2e2e9ba
Compare
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 have left some comments, but looks good in general.
I would not be able to guess if that is enough to not break anything, but I would argue (again) that you should have more JS code tests that use the API as users will do.
This will also help with making certain that this mapping are what you want - as it will exercise them ;)
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 feels like there are lot of things that could go wrong (i'm not saying they have) i.e. the mappings could be incorrect. Is there anyway we can test the objects that are now manually being created and mapped?
2e2e9ba
to
812479f
Compare
0c388d5
to
29f50b2
Compare
@ankur22, thanks for your review 🙇
I agree that the solution we have in place is not future-proof, but it's good enough for now. In the future, we should consider automating or generating this mapping code. I've added some tests to verify the behavior, which you can find in the following commits: On the bright side, users will receive an error message if something goes wrong and a method can't be found. With the tests in place, the likelihood of that happening should be low. Since the tests test whether all API methods ( Additionally, these manual mappings will allow us to move the goja layer from our domain logic code, making it more type-safe and easier to work with. I'll create an issue about that soon. Let me know if you have any questions or concerns. Related:
Also here:
|
@mstoykov, thank you for your review 🙇
We now have tests to check whether we map the entire API surface that have the wildcard methods. I agree we should have more JS tests, preferably in the I'm also thinking of changing the directory name to |
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.
LGTM. I've left some minor comments.
Having looked at the unit tests you've added in this, i'm not sure adding JS tests would add any more benefit to this, I could be wrong though.
Arguably having them "manually" written (and hopefully tested manually soon as well) makes it less likely that something will just break because the "magic" translation layer changes or someone unknowingly renames a method which was used. Additioanlly apart from |
So that `$` and `$$` won't register in the global Goja runtime. This means our code won't be able to automatically map `$` to `Query` and `$$` to `QueryAll`.
This was borrowed from k6-core to register wildcards like `$` and `$$` to the global Goja runtime. We won't support this mapping anymore.
This is the start of the mappings efforts from our browser types to Goja.
`$` and `$$` are mapped to `Query` and `QueryAll`, respectively. Users won't be able to use `Query` and `QueryAll`. Instead, they will use `$` and `$$` to access those querying methods.
With this, the browser module exposes api types to goja mappings to users.
4f23e29
to
a636fc0
Compare
a636fc0
to
49f2f86
Compare
49f2f86
to
033adcf
Compare
Thank you for the re-review @ankur22.
JS tests can ensure that we are mapping the methods correctly to the ones we mapped. For example, what would happen if we map Also, JStests are necessary for the rest of the extension too. So we can exercise them from the point of view of a user without setting up a testing suite from the Go side with all these goja translations. These tests can also allow us to refactor the extension more freely instead of changing the Go code. So we can extract goja out of the extension and let the goja translation layer do the job (see #271). |
…-query-method-mappings"" This reverts commit 3cee653.
As discussed in issue #661, we're now "manually" mapping the browser module methods to Goja. The global Goja field name mappers are removed from the code. This can be automated in the future as the mapping can be error-prone.
The current mappers are just forwarders to the inner methods, and we add
$
and$$
for theQuery
andQueryAll
methods.Let me know if I missed something while mapping the methods; and whether the way we solved it is good enough.
Closes #661.