-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Translate EarlGrey headers to Javascript calls #178
Conversation
You may want to consider passing your code through something like https://github.com/prettier/prettier to make the formatting nicer. Babel's toolchain by default does basic formatting, but making it super nicely readable isn't really one of our goals since most people don't read our output at all, and formatting the output nicely take longer. |
Great idea, that might make it much nicer 👍 |
@loganfsmyth I tried the on the output, but It seems to ignore the comments completely. I will file an issue (prettier/prettier#2340) and maybe do a PR for that. |
I found a good first throw for the type checking and I will try to mimic the current behavior in terms of the return statement. |
For testing I would execute the transformation on a bunch of files and import the js file to then test their functionality, I think this is the easiest way |
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.
Ho my, this is super neat!
demo.js
Outdated
@return A GREYAction that performs a long press on an element. | ||
*/static actionForLongPressAtPointduration(point, duration) { | ||
if (typeof point === "object") throw new Error("point should be a object, but got " + point); | ||
if (typeof duration === "number") throw new Error("duration should be a number, but got " + duration); |
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.
Maybe print typeof params instead of value
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.
Great Idea, why don't we have both "duration should be a number, but got '42'(string)". Will add it to the todos
Re "exclude functions with unsupported argument types", we currently don't support passing Booleans in the objC invocation implementation. |
@rotemmiz Is there a reason that we don't support it? I thought about these |
It's a bug in the implementation, and it will be hard to fix since the code there is a bit messy. We need to refactor/rewrite it some day. It does work on the Java implementation though ;) |
@rotemmiz If you want, let's have a look at refactoring after I finish a milestone in the profiler / Instruments. |
d4d7444
to
39b2598
Compare
0e46849
to
9fadf88
Compare
generation/package.json
Outdated
"test": "jest" | ||
}, | ||
"author": "DanielMSchmidt <danielmschmidt92@gmail.com>", | ||
"license": "ISC", |
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.
MIT please
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.
sure 👍
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.
Asides from some clarity in documentation and code structure this is really awesome. These opinions are just my own as well, take them or leave them 🙇 🙏
generation/earl-grey.js
Outdated
); | ||
} | ||
|
||
function capitalizeFirstLetter(string) { |
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 might be a good time to move capitalizeFirstLetter
and methodNameToSnakeCase
and sanitizeArgument
either to another file that specifically is for helper methods, or at least organise them together so that the main functions in this file (createMethod
, createClass
, ...) are logically sorted for future reading of this file.
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.
Good idea, the are all based around making the input more sane... Will do so 👍
generation/earl-grey.js
Outdated
isOneOf, | ||
} = require('./type-checks'); | ||
|
||
function createClass(json) { |
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.
Would love to see some comment code on what these json structures look like, or at least references to them somewhere. It helps when visualising things moving through the functions 👍
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.
Will add comments like this 👍
generation/earl-grey.js
Outdated
function capitalizeFirstLetter(string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
function methodNameToSnakeCase(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.
isThisSnakeCase?
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.
YesItIs 😂
generation/type-checks.js
Outdated
t.identifier(name) | ||
); | ||
|
||
const isNumber = generateTypeCheck("number"); |
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 am really stoked about this and would love to see this typecheck generator be a separate package I could use 👍 <3
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 can extract that out, what would you search for if you would like to find it?
c362a85
to
3dbc01e
Compare
@awitherow Extracted the guard clause generation into the babel-generate-guard-clauses. @rotemmiz The build seems to be failing on master and the error looks the same as here, can this be merged? |
9913fee
to
e5e96c1
Compare
e5e96c1
to
5bcd23f
Compare
Nice @DanielMSchmidt the guard class generators are looking nice 👍 |
🎉 🎊 🎉 🎊🎉 |
Plan
As migrating functionality from EarlGrey to detox is manual and therefore time consuming and error-prone process @rotemmiz came up with the idea of generating Javascript calls from EarlGrey itself.
The idea is to have EarlGrey as input, parse its header files to define the possible functions and result in a JS EarlGrey client that you may call that will then execute the equivalent Objective-C functions through the bridge.
This way we might be able to focus on real functionality and enable new contributors to not have to worry about the detox internals from the beginning.
Current State
typeof ===
) the arguments of the functionsGreyActions.h
is transformed todetox/src/ios/EarlGrey/GreyActions.js
Update 1: @loganfsmyth hinted me in the right direction with the comments, so I got that one working. Still need to figure out how to add a space behind them, but if I can't find a babel option there still is good ol'
str.replace(/\*\//g, '*/\n')
;)