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

ci: Add React Native integration testing with Detox #5007

Merged
merged 26 commits into from
Feb 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 134 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
version: 2.1
machine:
environment:
PATH: '${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin'
Expand All @@ -14,6 +14,26 @@ defaults: &defaults
## this enables colors in the output
TERM: xterm

defaults_rn: &defaults_rn
macos:
xcode: '11.3.1'
working_directory: ~/amplify-js-samples-staging

commands:
restore_pods:
steps:
- restore_cache:
keys:
- v1-storage-app-pods-{{ checksum "ios/Podfile.lock" }}
- v1-storage-app-pods-

save_pods:
steps:
- save_cache:
key: v1-storage-app-pods-{{ checksum "ios/Podfile.lock" }}
paths:
- ios/Pods

jobs:
build:
<<: *defaults
Expand All @@ -23,8 +43,8 @@ jobs:
- checkout
- run: yarn config set workspaces-experimental true
- run: yarn
- run: yarn run bootstrap
- run: yarn run build
- run: yarn bootstrap
- run: yarn build

- save_cache:
key: amplify-ssh-deps-{{ .Branch }}
Expand Down Expand Up @@ -250,6 +270,108 @@ jobs:
path: amplify-js-samples-staging/cypress/videos
- store_artifacts:
path: amplify-js-samples-staging/cypress/screenshots

integ_rn_ios_storage:
<<: *defaults_rn
working_directory: ~/amplify-js-samples-staging/samples/react-native/storage/StorageApp
steps:
- attach_workspace:
at: ~/
- run:
name: Yarn Install
command: yarn install --non-interactive --no-lockfile
# Metro Bundler doesn't work with linked packages so we're copying them from amplify-js
# TODO: utilize Verdaccio for this instead
- run:
name: 'Link aws-amplify'
command: |
cp -rf ~/amplify-js/packages/aws-amplify/dist ./node_modules/aws-amplify/dist
cp -rf ~/amplify-js/packages/aws-amplify/lib ./node_modules/aws-amplify/lib
cp -rf ~/amplify-js/packages/aws-amplify/lib-esm ./node_modules/aws-amplify/lib-esm

cp -rf ~/amplify-js/packages/amazon-cognito-identity-js/dist ./node_modules/amazon-cognito-identity-js/dist
cp -rf ~/amplify-js/packages/amazon-cognito-identity-js/lib ./node_modules/amazon-cognito-identity-js/lib

cp -rf ~/amplify-js/packages/analytics/dist ./node_modules/@aws-amplify/analytics/dist
cp -rf ~/amplify-js/packages/analytics/lib ./node_modules/@aws-amplify/analytics/lib
cp -rf ~/amplify-js/packages/analytics/lib-esm ./node_modules/@aws-amplify/analytics/lib-esm

cp -rf ~/amplify-js/packages/api/dist ./node_modules/@aws-amplify/api/dist
cp -rf ~/amplify-js/packages/api/lib ./node_modules/@aws-amplify/api/lib
cp -rf ~/amplify-js/packages/api/lib-esm ./node_modules/@aws-amplify/api/lib-esm

cp -rf ~/amplify-js/packages/auth/dist ./node_modules/@aws-amplify/auth/dist
cp -rf ~/amplify-js/packages/auth/lib ./node_modules/@aws-amplify/auth/lib
cp -rf ~/amplify-js/packages/auth/lib-esm ./node_modules/@aws-amplify/auth/lib-esm

cp -rf ~/amplify-js/packages/cache/dist ./node_modules/@aws-amplify/cache/dist
cp -rf ~/amplify-js/packages/cache/lib ./node_modules/@aws-amplify/cache/lib
cp -rf ~/amplify-js/packages/cache/lib-esm ./node_modules/@aws-amplify/cache/lib-esm

cp -rf ~/amplify-js/packages/core/dist ./node_modules/@aws-amplify/core/dist
cp -rf ~/amplify-js/packages/core/lib ./node_modules/@aws-amplify/core/lib
cp -rf ~/amplify-js/packages/core/lib-esm ./node_modules/@aws-amplify/core/lib-esm

cp -rf ~/amplify-js/packages/interactions/dist ./node_modules/@aws-amplify/interactions/dist
cp -rf ~/amplify-js/packages/interactions/lib ./node_modules/@aws-amplify/interactions/lib
cp -rf ~/amplify-js/packages/interactions/lib-esm ./node_modules/@aws-amplify/interactions/lib-esm

cp -rf ~/amplify-js/packages/predictions/dist ./node_modules/@aws-amplify/predictions/dist
cp -rf ~/amplify-js/packages/predictions/lib ./node_modules/@aws-amplify/predictions/lib
cp -rf ~/amplify-js/packages/predictions/lib-esm ./node_modules/@aws-amplify/predictions/lib-esm

cp -rf ~/amplify-js/packages/pubsub/dist ./node_modules/@aws-amplify/pubsub/dist
cp -rf ~/amplify-js/packages/pubsub/lib ./node_modules/@aws-amplify/pubsub/lib
cp -rf ~/amplify-js/packages/pubsub/lib-esm ./node_modules/@aws-amplify/pubsub/lib-esm

cp -rf ~/amplify-js/packages/storage/dist ./node_modules/@aws-amplify/storage/dist
cp -rf ~/amplify-js/packages/storage/lib ./node_modules/@aws-amplify/storage/lib
cp -rf ~/amplify-js/packages/storage/lib-esm ./node_modules/@aws-amplify/storage/lib-esm

cp -rf ~/amplify-js/packages/amplify-ui/dist ./node_modules/@aws-amplify/ui/dist
cp -rf ~/amplify-js/packages/amplify-ui/lib ./node_modules/@aws-amplify/ui/lib

cp -rf ~/amplify-js/packages/xr/dist ./node_modules/@aws-amplify/xr/dist
cp -rf ~/amplify-js/packages/xr/lib ./node_modules/@aws-amplify/xr/lib
cp -rf ~/amplify-js/packages/xr/lib-esm ./node_modules/@aws-amplify/xr/lib-esm
Comment on lines +288 to +336
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks painful, thank you for getting through this! My only question, NON BLOCKING, is Verdaccio will solve this? I know you have it as the callout but just want to double check if itll be something similar we would have to do with Verdaccio

Copy link
Member Author

@iartemiev iartemiev Feb 28, 2020

Choose a reason for hiding this comment

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

Lol yea it was a little painful, but fun too. I think we technically only need the /lib dirs, since that's what RN consumes, but I copied dist and lib-esm as well just in case.

Verdaccio will def solve this though. The reason we're doing that ^ is because we can't yarn link like we do for the other (web) integ tests. So instead of linking or copying, we'll just yarn add aws-amplify from the Verdaccio registry running in CircleCI

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha makes sense to me on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we only need /lib. This is a problem when doing local dev for amplify-js and React Native too.
But I think we can do it a better way in the future, using Verdaccio ideally or even a script file that runs a build and changes the output directory to the corresponding path in the app's node_modules. And then here we just run that script in the config rather than writing all the steps to copy it over in the config (a bit verbose)?
But yeah its not a blocker for now, and great stuff getting this to work! 👍


- restore_pods
- run:
name: Install CocoaPods
command: |
cd ios
pod install
- save_pods
- run:
background: true
command: xcrun simctl boot "iPhone 11" || true
name: Start iOS simulator (background)
- run:
background: true
command: yarn start
name: Start Metro Packager (background)
- run:
name: Configure Detox
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
command: |
brew tap wix/brew
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wix/brew? Is there a certain homebrew that we need from wix? Or is this what they reccomend for adding detox?

Copy link
Member Author

Choose a reason for hiding this comment

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

brew install applesimutils
yarn global add detox-cli
- run:
name: Detox Build
command: detox build -c ios.sim.debug
- run:
environment:
JEST_JUNIT_OUTPUT_DIR: 'reports/junit'
JEST_JUNIT_OUTPUT_NAME: 'detox-test-results.xml'
name: Detox Test
command: detox test -c ios.sim.debug -u
- store_test_results:
path: reports/junit
- store_artifacts:
path: reports/junit

deploy:
<<: *defaults
working_directory: ~/amplify-js
Expand Down Expand Up @@ -328,6 +450,15 @@ workflows:
- 1.0-stable
requires:
- integ_setup
- integ_rn_ios_storage:
filters:
branches:
only:
- release
- master
- 1.0-stable
requires:
- integ_setup
- deploy:
filters:
branches:
Expand Down