-
-
Notifications
You must be signed in to change notification settings - Fork 597
chore(e2e): detox config general cleanup and ios management #3412
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
base: main
Are you sure you want to change the base?
chore(e2e): detox config general cleanup and ios management #3412
Conversation
kkafar
left a comment
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.
Hey! Nice job. I have few remarks & questions. Please answer them.
According to https://github.com/software-mansion/react-native-screens-labs/discussions/572 should I expect support for E2E_ANDROID_API_LEVEL in this PR or what are plans for that?
If you want to structure the code this way, i. e. extract the "device" detecting code to separate module, then we should do analogous thing with Android related code. It can be done in separate PR, I don't mind, but let's create ticket for this, so that we do not forget.
scripts/e2e/detox-utils.cjs
Outdated
| const { iosDevice } = require('./ios-devices'); | ||
|
|
||
| const CI_AVD_NAME = 'e2e_emulator'; | ||
| const CI_ADB_NAME = 'e2e_emulator'; |
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.
Writing from top of my head but:
ADB ~= Android Debug Bridge,
AVD ~= Android Virtual Device.
I believe this variable describes the name of the emulator (avd) we want to use -> avd makes more sense here. What do you think?
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, you are right
when I was doing the cleanup I was sure that we assign it to "adbName" in detox-utils, but we assign it to "avdName" in this case, I'm going to correct that
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.
Oh, no,
This specific variable seems to be used in two places and it looks to me that one case is wrong:
We used it as a devices.attached.device.adbName in line 104->102 and it may be assigned to devices.emulator.device.avdName because of line 46->47
I suspect one of these entries was a dead 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.
The name we specify is clearly an AVD name, not ADB name. Therefore let's name it appropriately, please.
I took a look into Detox docs and it seems that two fields are allowed:
avdName- for emulator name as listed byemulators -list-avdadbName- for emulator device hash (? not sure what that hash-like id is) that can be used with ADB to identify the device.
Seems that for the wole time we've been just using the wrong field, unless the e2e CI workflow specifies e2e_emulator as the adb name of the device it creates.
PS: I've just checked and it seems that we specify avd-name field there. Not sure of it exact semantics, but it seems that our detox setup worked so far only by accident. Let's fix that.
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.
ok, I'll replace CI_AVD_NAME and DETOX_AVD_NAME with RNS_E2E_AVD_NAME (from https://github.com/software-mansion/react-native-screens-labs/discussions/572#discussioncomment-15031761)
scripts/e2e/ios-devices.js
Outdated
| @@ -0,0 +1,37 @@ | |||
| const DEFEAULT_APPLE_MODEL = 'iPhone 17'; | |||
| const DEVICE_MODEL = process.env.E2E_APPLE_DEVICE || DEFEAULT_APPLE_MODEL | |||
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.
DEVICE_MODEL is not really a constant here. I'd prefer it being extracted to a function and computed there.
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.
Similarly to detectLocalAndroidEmulator function defined in the "main" util module.
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.
For me, it makes no difference (okay, now that you've pointed it out, I'd write it camelCase).
Anyway, turned into a function
3797cfe to
89208a9
Compare
kkafar
left a comment
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.
Answered
scripts/e2e/detox-utils.cjs
Outdated
| const { iosDevice } = require('./ios-devices'); | ||
|
|
||
| const CI_AVD_NAME = 'e2e_emulator'; | ||
| const CI_ADB_NAME = 'e2e_emulator'; |
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 name we specify is clearly an AVD name, not ADB name. Therefore let's name it appropriately, please.
I took a look into Detox docs and it seems that two fields are allowed:
avdName- for emulator name as listed byemulators -list-avdadbName- for emulator device hash (? not sure what that hash-like id is) that can be used with ADB to identify the device.
Seems that for the wole time we've been just using the wrong field, unless the e2e CI workflow specifies e2e_emulator as the adb name of the device it creates.
PS: I've just checked and it seems that we specify avd-name field there. Not sure of it exact semantics, but it seems that our detox setup worked so far only by accident. Let's fix that.
d8762fc to
d3d5c5b
Compare
8192e77 to
c5fa206
Compare
Co-authored-by: Kacper Kafara <[email protected]>
kkafar
left a comment
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 still have some more remarks. I feel like we're proceeding here in a bit chaotic manner, with some unrequested changes being applied here.
I'll open a diff with suggested changes, so that we can proceed more smoothly. Will link it here once a do
| force-avd-creation: false | ||
| emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
| avd-name: e2e_emulator | ||
| rns_e2e_avd_name: e2e_emulator |
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.
avd-name is a configuration option from the github action this job step uses. Renaming here does not make much sense. I think you went too far with find & replace 😅
scripts/e2e/detox-utils.cjs
Outdated
| return process.env.RNS_E2E_AVD_NAME || isRunningCI | ||
| ? DEFAULT_CI_AVD_NAME | ||
| : detectLocalAndroidEmulator(); |
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 few remarks to this code:
- It introduces unnecessary uncertainty how to interpret this. Might be a skill issue on my end, but I prefer to have it written in such way I don't have to wonder whether
||operator has higher precedence than ternary?:operator in JavaScript or not:
(process.env.RNS_E2E_AVD_NAME || isRunningCI)
? DEFAULT_CI_AVD_NAME
: detectLocalAndroidEmulator();or
process.env.RNS_E2E_AVD_NAME || (isRunningCI
? DEFAULT_CI_AVD_NAME
: detectLocalAndroidEmulator());?
- Why do we change this code at all here? From all I see we haven't started passing emulator name from CI through env, it is still hard coded name, therefore there is no need to change this code like that.
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 confess, I assumed we were going to pass this value all the time, but we used hardcoded CI_AVD_NAME as a fallback due to a misconfig 😅 but that part was fine all along. That's also the reason I touched those github configs.
I'm withdrawing this now
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.
fixed with commit 3fbdad3
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.
c5fa206 to
3fbdad3
Compare
|
I've posted suggested review changes here: #3414 |
scripts/e2e/ios-devices.js
Outdated
| const passedVersion = process.env.RNS_E2E_IOS_VERSION; | ||
| if (passedVersion) { |
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 assume that the passed version should have some specific format, so I'd add some documentation and additional validation that it matches the proper regex
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.
configuration will be passed to Detox and I planned to rely on validation in Detox itself. However, now I think you're right, because for as long as I can remember, iPhones have had consistent naming conventions and I can expect them to maintain it.
| const envVariableKey = 'RNS_E2E_IOS_VERSION'; | ||
| const passedVersion = process.env[envVariableKey]; | ||
| if (passedVersion) { | ||
| if (/^(iOS)\s.+/.test(passedVersion)) { |
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.
nit: I haven't made up my mind, but we'll have a rather fixed number of checks; therefore, I'm wondering if startsWith won't improve readability compared to a regex. Treat it as a nitpick; for me, it's okay to leave it in its current form.
| const envVariableKey = 'RNS_E2E_APPLE_SIM_NAME'; | ||
| const passedDevice = process.env[envVariableKey]; | ||
| if (passedDevice) { | ||
| if (/^(iPhone|iPad)\s.+/.test(passedDevice)) { |
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.
nit: I haven't made up my mind, but we'll have a rather fixed number of checks; therefore, I'm wondering if startsWith won't improve readability compared to a regex. Treat it as a nitpick; for me, it's okay to leave it in its current form.
Description
This is first of three PRs in the scope of labs issue 569.
Realizing plans from labs discussion 572.
Changes
e2e tests could be run in more parametrized way - choosing ios version/device before the start.
CI_AVD_NAME and DETOX_AVD_NAME env variables combined into
RNS_E2E_AVD_NAMERNS_ADB_NAMEenvironment variable introduced for local testing against attached [physical] devices.Common e2e scripts restructured.
Screenshots / GIFs
Here you can add screenshots / GIFs documenting your change.
You can add before / after section if you're changing some behavior.
Before
Choosing apple simulator by changing config file for "ios.simulator" entry
After
Running test script with optional
RNS_E2E_APPLE_SIM_NAMEandRNS_E2E_IOS_VERSIONenvironment variables.Checklist