From a2f3ba864ed17ca32e71f15724a8ebf2b1e640c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= <165856+hramos@users.noreply.github.com> Date: Wed, 31 Jan 2018 14:48:51 -0800 Subject: [PATCH] Generate JUnit test reports for iOS builds Summary: Closes https://github.com/facebook/react-native/pull/17794 Differential Revision: D6850015 Pulled By: hramos fbshipit-source-id: bd230a5aa6fe14fb760f7b0c5f0989bf6ee1e8ea --- .circleci/config.yml | 68 +++++++++++++++++++++++++++++++++++++------- package.json | 2 ++ scripts/objc-test.sh | 3 +- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 18a1a4492887b4..acb58f8bd15475 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -88,8 +88,8 @@ aliases: sudo apt-get install -y nodejs - &run-js-tests - | - yarn test --maxWorkers=2 + name: JavaScript Test Suite + command: yarn test-ci - &run-lint-checks | @@ -183,11 +183,16 @@ aliases: - &collect-android-test-results name: Collect Test Results command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/build/test-results/debug/.*xml" -exec cp {} ~/junit/ \; - find . -type f -regex ".*/outputs/androidTest-results/connected/.*xml" -exec cp {} ~/junit/ \; + find . -type f -regex ".*/build/test-results/debug/.*xml" -exec cp {} ~/reports/junit/ \; + find . -type f -regex ".*/outputs/androidTest-results/connected/.*xml" -exec cp {} ~/reports/junit/ \; + find . -type f -regex ".*/buck-out/gen/ReactAndroid/src/test/.*/.*xml" -exec cp {} ~/reports/junit/ \; when: always + - &setup-artifacts + name: Initial Setup + command: | + mkdir -p ~/reports/junit/ + defaults: &defaults working_directory: ~/react-native @@ -213,6 +218,8 @@ jobs: - image: circleci/node:8 steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache @@ -226,10 +233,16 @@ jobs: - image: circleci/node:8 steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache - run: *run-js-tests + - store_test_results: + path: ~/reports/junit + - store_artifacts: + path: ~/reports/junit # Runs JavaScript tests on Node 6 test-js-node-6: @@ -238,10 +251,16 @@ jobs: - image: circleci/node:6 steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache - run: *run-js-tests + - store_test_results: + path: ~/reports/junit + - store_artifacts: + path: ~/reports/junit # Runs unit tests on iOS devices test-objc-ios: @@ -253,10 +272,16 @@ jobs: - xcrun instruments -w "iPhone 5s (10.3.1)" || true steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache - run: ./scripts/objc-test-ios.sh + - store_test_results: + path: ~/reports/junit + - store_artifacts: + path: ~/reports/junit # Runs unit tests on tvOS devices test-objc-tvos: @@ -268,10 +293,16 @@ jobs: - xcrun instruments -w "Apple TV 1080p (10.0)" || true steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache - run: ./scripts/objc-test-tvos.sh + - store_test_results: + path: ~/reports/junit + - store_artifacts: + path: ~/reports/junit # Runs end to end tests test-objc-e2e: @@ -283,6 +314,8 @@ jobs: - xcrun instruments -w "iPhone 5s (10.3.1)" || true steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache @@ -295,6 +328,8 @@ jobs: xcode: "9.0" steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-yarn-cache - run: *yarn - save-cache: *save-yarn-cache @@ -305,6 +340,7 @@ jobs: <<: *android_defaults steps: - checkout + - run: *setup-artifacts # Configure Android dependencies - run: *configure-android-path @@ -349,7 +385,8 @@ jobs: <<: *android_defaults steps: - checkout - + - run: *setup-artifacts + # Configure Android dependencies - run: *configure-android-path - run: *install-build-dependencies @@ -399,9 +436,9 @@ jobs: # post (always runs) - run: *collect-android-test-results - store_test_results: - path: ~/junit + path: ~/reports/junit - store_artifacts: - path: ~/junit + path: ~/reports/junit analyze-pull-request: <<: *defaults @@ -409,12 +446,14 @@ jobs: - image: circleci/node:8 steps: - checkout + - run: *setup-artifacts + - restore-cache: *restore-cache-analysis - run: *yarn - run: name: Install Additional Dependencies command: | - if [ -n "$CIRCLE_PULL_REQUEST" ]; then + if [ -n "$CIRCLE_PR_NUMBER" ]; then yarn add github@0.2.4 cd danger yarn install --non-interactive --cache-folder ~/.cache/yarn @@ -425,22 +464,29 @@ jobs: - run: name: Analyze Pull Request command: | - if [ -n "$CIRCLE_PULL_REQUEST" ]; then + if [ -n "$CIRCLE_PR_NUMBER" ]; then cd danger && DANGER_GITHUB_API_TOKEN="e622517d9f1136ea8900""07c6373666312cdfaa69" yarn danger else echo "Skipping pull request analysis." fi + background: true when: always - run: name: Analyze Code command: | if [ -n "$CIRCLE_PR_NUMBER" ]; then cat <(echo eslint; yarn --silent lint --format=json; echo flow; yarn --silent flow check --json) | GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" CI_USER=$CIRCLE_PROJECT_USERNAME CI_REPO=$CIRCLE_PROJECT_REPONAME PULL_REQUEST_NUMBER=$CIRCLE_PR_NUMBER node bots/code-analysis-bot.js + yarn lint --format junit -o ~/reports/junit/js-lint-results.xml else echo "Skipping code analysis." fi + background: true when: always - + - store_test_results: + path: ~/reports/junit + - store_artifacts: + path: ~/reports/junit + # Workflows enables us to run multiple jobs in parallel workflows: version: 2 diff --git a/package.json b/package.json index 557ed5a1818fd5..2a5f3cfcd93bf9 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ ], "scripts": { "test": "jest", + "test-ci": "JEST_JUNIT_OUTPUT=\"~/reports/junit/js-test-results.xml\" jest --maxWorkers=2 --ci --testResultsProcessor=\"jest-junit\"", "flow": "flow", "lint": "eslint .", "prettier": "find . -name node_modules -prune -or -name '*.js' -print | xargs prettier --write", @@ -216,6 +217,7 @@ "eslint-plugin-react": "^7.2.1", "flow-bin": "^0.64.0", "jest": "22.1.2", + "jest-junit": "^3.4.1", "prettier": "1.9.1", "react": "16.2.0", "react-test-renderer": "16.2.0", diff --git a/scripts/objc-test.sh b/scripts/objc-test.sh index 154d96a69357bd..a282ed922611de 100755 --- a/scripts/objc-test.sh +++ b/scripts/objc-test.sh @@ -81,7 +81,8 @@ xcodebuild \ -scheme $SCHEME \ -sdk $SDK \ -destination "$DESTINATION" \ - build test + build test \ + | xcpretty --report junit --output ~/reports/junit/objc-xcodebuild-results.xml else