Skip to content
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

[RNMobile][Monorepo] Use github actions to run React Native e2e tests #22189

Merged

Conversation

ceyhun
Copy link
Member

@ceyhun ceyhun commented May 7, 2020

Description

This is part of a migration effort of gutenberg-mobile to gutenberg repository with git history. More related PRs here: #18508

This PR aims to get all mobile e2e tests working on the most up to date gb-mobile / gutenberg Monorepo branch (feat/import-gutenberg-mobile-no-squash) using GitHub actions

Bonus: The emulator screens are recorded while the tests are running and uploaded as artifacts to help debugging.

How has this been tested?

The following two commands should work, with all tests passing:

  • npm run native test:e2e:android:local
  • npm run native test:e2e:ios:local

PR check on this PR should be green for the tasks:

  • React Native E2E Tests (Android)
  • React Native E2E Tests (iOS)

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented May 7, 2020

Size Change: 0 B

Total Size: 828 kB

ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 4.08 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.59 kB 0 B
build/block-directory/style-rtl.css 764 B 0 B
build/block-directory/style.css 764 B 0 B
build/block-editor/index.js 104 kB 0 B
build/block-editor/style-rtl.css 10.6 kB 0 B
build/block-editor/style.css 10.6 kB 0 B
build/block-library/editor-rtl.css 7.15 kB 0 B
build/block-library/editor.css 7.15 kB 0 B
build/block-library/index.js 115 kB 0 B
build/block-library/style-rtl.css 7.38 kB 0 B
build/block-library/style.css 7.38 kB 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 181 kB 0 B
build/components/style-rtl.css 17 kB 0 B
build/components/style.css 16.9 kB 0 B
build/compose/index.js 6.66 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.42 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.1 kB 0 B
build/edit-navigation/index.js 5.59 kB 0 B
build/edit-navigation/style-rtl.css 618 B 0 B
build/edit-navigation/style.css 617 B 0 B
build/edit-post/index.js 28 kB 0 B
build/edit-post/style-rtl.css 12.2 kB 0 B
build/edit-post/style.css 12.2 kB 0 B
build/edit-site/index.js 12.1 kB 0 B
build/edit-site/style-rtl.css 5.22 kB 0 B
build/edit-site/style.css 5.22 kB 0 B
build/edit-widgets/index.js 8.37 kB 0 B
build/edit-widgets/style-rtl.css 4.69 kB 0 B
build/edit-widgets/style.css 4.69 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/index.js 44.3 kB 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/index.js 7.63 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14.8 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.02 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@ceyhun ceyhun force-pushed the try/github-actions-ios-ci branch from 8f36267 to 94a1e41 Compare May 12, 2020 16:02
@ceyhun ceyhun changed the title [RNMobile][Monorepo] Try github actions to run e2e tests [RNMobile][Monorepo] Use github actions to run e2e tests May 13, 2020
@ceyhun ceyhun changed the title [RNMobile][Monorepo] Use github actions to run e2e tests [RNMobile][Monorepo] Use github actions to run React Native e2e tests May 13, 2020
@ceyhun ceyhun marked this pull request as ready for review May 13, 2020 12:43
@ceyhun ceyhun requested review from Tug and gziolo and removed request for karmatosed, youknowriad and mapk May 13, 2020 12:43
Copy link
Contributor

@Tug Tug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Great work @ceyhun !!

@@ -60,6 +60,10 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
await paragraphBlockElement.click();

await editorPage.addNewParagraphBlock();

// wait for accessibility ids to update
await driver.sleep( 1000 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice that's why I had some failures locally and on travis I think 👍

npm ci
npm run native test:e2e:android:local

- uses: actions/upload-artifact@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain a bit how this works? Where are the artifacts stored? For how long? How can one access it when looking at a PR?
This could be a nice addition to the mobile doc, otherwise just a comment on this PR so people can find this information using git blame :)

Copy link
Contributor

@Tug Tug May 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, found them here at the top right of the check screen
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it's useful, there is some more information here about GitHub actions artifacts: https://help.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts.

@ceyhun 👋 😄 nice work on this! I ❤️ seeing these workflows integrated with GitHub!

@Tug Tug added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label May 13, 2020
@gziolo
Copy link
Member

gziolo commented May 13, 2020

Excellent idea to use GitHub actions and great work integration all that into branch 👍

How long does it take to run those tests?

Screen Shot 2020-05-13 at 15 58 37

47 minutes?

Travis takes 20 minutes at most to run all jobs, an individual job finishes in maximum of 13-14 minutes. Do you have some ideas on how to make it faster?

Do you know if there are any limits to GH actions?

@ceyhun ceyhun force-pushed the try/github-actions-ios-ci branch from 55ed0d6 to 08c90a9 Compare May 14, 2020 09:56
@ceyhun
Copy link
Member Author

ceyhun commented May 14, 2020

@gziolo GH actions have a concurrency limit of 5 for macOS jobs and 20 in total: https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits. Currently both Android and iOS are running on macOS.

We have some ideas but we'd like to iterate on this later on. For now we thought we'll just run a subset of the tests in parallel to make it faster and so this PR can be merged. It should be around ~15min now.

@ceyhun ceyhun requested a review from Tug May 14, 2020 11:01
@gziolo
Copy link
Member

gziolo commented May 14, 2020

@gziolo GH actions have a concurrency limit of 5 for macOS jobs and 20 in total: https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions#usage-limits. Currently both Android and iOS are running on macOS.

I knew there needs to be some sort of limit. I'm wondering whether there is some OSS plan that we could request. I guess it would be already enabled. There is also an option to use self-hosted jobs. 2 existing actions use Ubuntu, now we would have 4 more actions running macOS, so it still looks good.

We have some ideas but we'd like to iterate on this later on. For now we thought we'll just run a subset of the tests in parallel to make it faster and so this PR can be merged. It should be around ~15min now.

It's fine for now, but it'd be great to optimize it as much as possible – ideally aiming at 5-10 minutes per job. (Not sure if that is realistic though, boot process for WordPress env takes nearly 5 minutes on Travis ...)

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Based on the discussion and results from GitHub's actions. I would appreciate review from someone who knows how the test suite works :)

@Tug
Copy link
Contributor

Tug commented May 14, 2020

It's fine for now, but it'd be great to optimize it as much as possible – ideally aiming at 5-10 minutes per job.

That would be awesome indeed but that might be quite hard to achieve, I believe it takes around 10mins at least to just "build" the apps. The upside of parallelisation is that we can keep adding e2e tests while staying around 15mins total.
If we optimize caching we might be able to gain a few minutes here and there, but still there's probably a hard limit around 5 to 10 minutes.

I would appreciate review from someone who knows how the test suite works :)

Given the recent contributions to .travis, @aduth do you mind having a look at this one?

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much of anything about the native testing, and only a fairly basic comprehension of GitHub Actions, so I'm maybe not the best person to review 😄 But from what I can grasp, it appears to be in good shape.

Like @gziolo , I'm especially conscious of the timing of these checks. Unfortunately the existing testing isn't especially reliable, so it's quite common to need to restart them from time to time. I guess if these are outside of Travis, any such rebuilds wouldn't need to run this process again, which is good at least.

@@ -60,6 +60,10 @@ describe( 'Gutenberg Editor tests for Block insertion', () => {
await paragraphBlockElement.click();

await editorPage.addNewParagraphBlock();

// wait for accessibility ids to update
await driver.sleep( 1000 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what other options might exist in the native testing, but in web code it's typically discouraged to use arbitrary timeouts, due to (a) slowing down test runtime and (b) not guaranteeing to always work (example). In Puppeteer tests, we'd instead actually express this as whatever it is that's being waited for (e.g. waitForSelector instead of waitFor( timeout )). Are there any equivalent options here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using xpath to find our elements on native so we could indeed use driver.waitForElementByXPath to speed up tests on faster devices.

Tbh we have quite many anti-patterns on those native e2e tests that we're hoping to fix. This PR was supposed to only be a simple port from gutenberg-mobile so we were not supposed to touch this code but since we did I guess we could improve the code a little bit there 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ceyhun Do we really need that sleep given that you're setting an implicit wait timeout of 10s here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be gone now, updated the tests with the ones from gutenberg-mobile/develop. setImplicitWaitTimeout was also initially added there and I had increased it.

@@ -41,6 +41,8 @@ export default class EditorPage {
this.accessibilityIdKey = 'contentDescription';
this.accessibilityIdSuffix = ', ';
}

driver.setImplicitWaitTimeout( 10000 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 🤔 By default this is 0, so setting this to 10s, makes sure each and every element query is "transformed" into its equivalent waitFor... neat!

@@ -114,8 +114,8 @@
"test:e2e:bundle:android": "mkdir -p android/app/src/main/assets && react-native bundle --reset-cache --platform android --dev false --minify false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
"test:e2e:build-app:android": "npm run test:e2e:bundle:android && cd android && ./gradlew clean && ./gradlew assembleDebug",
"test:e2e:install-app:android": "cd android && ./gradlew installDebug",
"test:e2e:bundle:ios": "react-native bundle --reset-cache --platform=ios --dev=false --minify false --entry-file=index.js --bundle-output=./ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app/main.jsbundle --assets-dest=./ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app",
"test:e2e:build-app:ios": "npm run ios --configuration Release --no-packager",
"test:e2e:bundle:ios": "mkdir -p ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app && react-native bundle --reset-cache --platform=ios --dev=false --minify false --entry-file=index.js --bundle-output=./ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app/main.jsbundle --assets-dest=./ios/build/gutenberg/Build/Products/Release-iphonesimulator/GutenbergDemo.app",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call this script from test:e2e:ios:local? Otherwise we have to call it manually each time

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundling should automatically happen when test:e2e:build-app:ios is called via a script in the iOS Xcode project. In the CI case we call them seperately for caching purposes and add SKIP_BUNDLING=true flag before calling test:e2e:build-app:ios

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed for automated CI using github actions. But for manually running e2e tests locally (which is what test:e2e:ios:local is used for atm) we need to automatically build the js bundle. I'll add it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to say it was already happening during test:e2e:build-app:ios locally. There's this script in Xcode:
https://github.com/facebook/react-native/blob/0.61-stable/scripts/react-native-xcode.sh

xcode

This is invoked by Xcode via react-native run-ios when test:e2e:build-app:ios is called and should create the bundle already.
But now it returns an error saying gutenberg/index.js was not found. Maybe that's why test:e2e:ios:local was returning an error locally .

If we create the bundle before react-native-xcode.sh is invoked, it exits without throwing an error
So it's fine, for now 🙂

@hypest
Copy link
Contributor

hypest commented May 15, 2020

Per @Tug 's ping over chat, will now merge this PR with the "Commit merge" strategy and lift the setting right afterwards.

@hypest hypest merged commit 0a75b3b into feat/import-gutenberg-mobile-no-squash May 15, 2020
@hypest hypest deleted the try/github-actions-ios-ci branch May 15, 2020 06:54
@dratwas dratwas mentioned this pull request May 15, 2020
21 tasks
@Tug Tug mentioned this pull request Jun 5, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants