-
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
Android: Move expect.js to generated code #746
Android: Move expect.js to generated code #746
Conversation
getting multiple errors in CI
|
Will check that out 👍 worked on my machine TM |
8fba90e
to
32f10ed
Compare
ff07b22
to
e84901e
Compare
9d1a013
to
b89e24f
Compare
b89e24f
to
41f4724
Compare
E2E tests don't pass on Android, almost everything fails with the same error:
@DanielMSchmidt , could you take a look please? Try out locally and report what you're getting. |
And I confirm that still, I can see the
It was printed 3-4 times during the test run, is it okay? |
@noomorph Just checked to be sure and the E2E tests are green and fine 👍 |
41f4724
to
9db4bc7
Compare
@noomorph I added the logger to the generated code, please take a look and merge at will 👍 |
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.
@DanielMSchmidt, thanks much! In regards to the codebase, it looks mostly fine except for a few minutiae I listed in the review.
generation/__tests__/android.js
Outdated
@@ -2,6 +2,11 @@ const fs = require('fs'); | |||
const remove = require('remove'); | |||
const androidGenerator = require('../adapters/android'); | |||
|
|||
const mockErrorLog = jest.fn(); | |||
jest.mock("../../detox/src/utils/logger", () => ({ |
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.
No need to sophisticate an already sophisticated thing. The logger has already a mocked version __mocks__/logger.js
, so you can just use it as is.
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 removed my own mock and used the one defined in __mocks__/logger.js
Unfortunately we have two separate jest installations/contexts, this means I need to do a bit of glue code, but no biggie. I wonder what might happen if we would make more use of a central jest installation with multiple configs with the jest multi-project runners
Might give it a try if I have some spare time 🤔
generation/__tests__/android.js
Outdated
expect(() => { | ||
ExampleClass.matcherForAnd('I am a string', 'I am one too'); | ||
}).not.toThrow(); | ||
|
||
|
||
expect(spy).toHaveBeenCalled(); | ||
spy.mockRestore(); | ||
expect(mockErrorLog).toHaveBeenCalled(); |
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.
Correspondingly, you can use expect(logger.error).toHaveBeenCalledWith(expect.any(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.
🤷♂️ I don't really see a point in having the expect.any(String)
, but yeah it might sometime in the future catch something, so I'll add it :)
generation/__tests__/android.js
Outdated
class AnotherClass {} | ||
const x = new AnotherClass(); | ||
|
||
expect(() => { | ||
ExampleClass.matcherForAnd(x, x); | ||
}).not.toThrow(); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
spy.mockRestore(); | ||
expect(mockErrorLog).toHaveBeenCalled(); |
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.
Correspondingly, you can use expect(logger.error).toHaveBeenCalledWith(expect.any(String))
generation/core/generator.js
Outdated
const outputPath = pathFragments.join("/") | ||
const absoluteUtilsPath = path.resolve('../detox/src/utils'); | ||
const relativeUtilsPath = path.relative(outputPath, absoluteUtilsPath); | ||
const logImport = `const log = require('${relativeUtilsPath}/logger');`; |
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.
Change to const log = require('${relativeUtilsPath}/logger').child({ __filename });
, so we can track from which files the log messages come.
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.
Also, could you extract this logic to a separate function, similar to a function createTypeCheck(...)
above? I see that generator
function looks already loong enough, why make it even bigger? :-)
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, no problem 👍 I think there are some parts I would like to slim down a bit and structure better, will go on with this soonish. My first goal was to get it working,so that I can see every edge case I ran into and make a better layer of abstraction later on ;)
ac3b7bf
to
94adbd3
Compare
@noomorph Could you take another look 🙏 |
Looks good the way it is already. If builds pass, more or less, we can try to merge. P.S. Out of curiosity, why do you do log.error. mockRestore manually? |
@noomorph are the reset by default? |
@noomorph Fixed that (the is defined check had a bug so it didn't occur previously, but that is fixed now) and the tests run through 👍 |
@@ -40,6 +65,24 @@ class ViewActions { | |||
}; | |||
} | |||
|
|||
static click(rollbackAction) { | |||
if (!rollbackAction) { |
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.
@DanielMSchmidt , I see unit test failing on this (src/android/expect.js
). Is this a reason why you hesitated to add isThruthy
check?
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 will take another look at the unit tests 👍 No, I hesitated because I don't see so much 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.
I should have hesitated because of this. The problem is it is optional and not required and we have no way to check if an argument is required or not. So all checks we do should test if the thing that is passed is what it promises to be if something is passed. If null is passed we won't be able to guard us on this side of the fence. I will do a quick research if there is any hypothetical way for us to know if sth is optional and I will let you know.
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.
Unit tests are failing, we cannot merge.
@noomorph Unit should be fixed now, got weird android simulator issues locally, let |
Daniel, looks like it is still broken on Android. At least that's what CI tells. |
Will take a look 🙈 |
@noomorph Could not reproduce, ran it three times on android and one time on iOS and everything went fine. |
9cb6bc6
to
d9e9d00
Compare
d9e9d00
to
fa808bb
Compare
b9958f0
to
2f52327
Compare
So, this branch is now up to date 🎉 Locally it worked (before the massive rebasing I just did), so let's see what CI says 👍 |
Looks like the branch is not on par with master, there was an artifacts snapshot test we disabled but still runs here, can you make sure to merge current master to this branch? |
@rotemmiz That's strange, I rebased it from master before I pushed, so I am a bit confused. I can't see where I enabled it looking through the diff. |
I tried to see if sth is different on the JSON part send to the WS for the failing test, but they are identical (besides message id). So I think your hint into enabling a disabled functionality seems to be right. |
2cce220
to
f072bf2
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'm having trouble understanding the overload functions generation. Can you explain about that a bit?
value: metaState | ||
}] | ||
}; | ||
function pressKeyCode1(keyCode) { |
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.
What happened here?
I guess there's problem with Java overloads, did you handle it somewhere else in a different way?
Seems like the original code just has metaState=0
as default.
https://android.googlesource.com/platform/frameworks/testing/+/79693ed/uiautomator/library/src/com/android/uiautomator/core/UiDevice.java#285
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.
The easiest way to handle overloading is to just check for the number of arguments. There are for sure better, more reliable ways, but this was the fastest. (I have checks in place that make sure we get some console output if we mess up here)
}; | ||
} | ||
|
||
if (arguments.length === 1) { |
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.
is this generated code?
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
args: [] | ||
}; | ||
} | ||
|
||
static click() { | ||
function click0() { |
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.
Again here, why are there two clicks?
I see only one in UIDevice API
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 are two because the method is overloaded.
@@ -0,0 +1,11 @@ | |||
/** |
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.
We can probably throw this away, as this class is empty. Everything is in EarlGreyImpl
"../detox/src/ios/earlgreyapi/GREYConfiguration.js", | ||
"../detox/ios/EarlGrey/EarlGrey/Core/EarlGreyImpl.h": | ||
"../detox/src/ios/earlgreyapi/EarlGreyImpl.js" | ||
'../detox/ios/EarlGrey/EarlGrey/Action/GREYActions.h': '../detox/src/ios/earlgreyapi/GREYActions.js', |
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.
better!
Previously we had manually changed code in the generated sections.
f072bf2
to
7cd7704
Compare
Closes #726