From 9b669244fb08467f11f7493c8af6f46eec9e37c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Thu, 11 Apr 2019 17:36:50 -0700 Subject: [PATCH] Run the same JavaScript test script in Sandcastle and Circle (#24422) Summary: Consolidate JavaScript tests from open source into a single script that can be executed by both Circle CI and Sandcastle, the internal Facebook CI. Pull Request resolved: https://github.com/facebook/react-native/pull/24422 Differential Revision: D14895773 fbshipit-source-id: fa3efbb569783d972f96cf275e3b0eb63a453b20 --- .circleci/config.yml | 21 +++++--- scripts/run-ci-javascript-tests.js | 77 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 scripts/run-ci-javascript-tests.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 28a65be33fd8a4..b99eebf5ea33c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -266,6 +266,7 @@ jobs: - run: name: Lint code command: scripts/circleci/exec_swallow_error.sh yarn lint --format junit -o ~/react-native/reports/junit/eslint/results.xml + when: always - run: name: Check for errors in code using Flow (iOS) @@ -284,6 +285,11 @@ jobs: ./scripts/circleci/validate_yarn_lockfile.sh when: always + - run: + name: Check formatting + command: yarn run format-check + when: always + - store_test_results: path: ~/react-native/reports/junit - store_artifacts: @@ -299,11 +305,13 @@ jobs: - attach_workspace: at: ~/react-native - - run: *run-js-tests + - run: + name: JavaScript Test Suite + command: node ./scripts/run-ci-javascript-tests.js --maxWorkers 2 - run: name: JavaScript End-to-End Test Suite - command: node ./scripts/run-ci-e2e-tests.js --js --retries 3; + command: node ./scripts/run-ci-e2e-tests.js --js --retries 3 - store_test_results: path: ~/react-native/reports/junit @@ -319,9 +327,9 @@ jobs: - run: *yarn - - run: *run-js-tests - - - run: yarn run format-check + - run: + name: JavaScript Test Suite + command: node ./scripts/run-ci-javascript-tests.js --maxWorkers 2 - store_test_results: path: ~/react-native/reports/junit @@ -608,7 +616,8 @@ workflows: - test_android: *run-after-checkout - test_ios: *run-after-checkout - test_detox_end_to_end: *run-after-checkout - - test_docker_build + - test_docker_build: + filters: *filter-ignore-gh-pages releases: jobs: diff --git a/scripts/run-ci-javascript-tests.js b/scripts/run-ci-javascript-tests.js new file mode 100644 index 00000000000000..dfcda32cac832f --- /dev/null +++ b/scripts/run-ci-javascript-tests.js @@ -0,0 +1,77 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +'use strict'; + +/** + * This script runs JavaScript tests. + * Available arguments: + * --maxWorkers [num] - how many workers, default 1 + * --jestBinary [path] - path to jest binary, defaults to local node modules + * --yarnBinary [path] - path to yarn binary, defaults to yarn + */ +/*eslint-disable no-undef */ +require('shelljs/global'); + +const argv = require('yargs').argv; +const path = require('path'); + +const numberOfMaxWorkers = argv.maxWorkers || 1; +let exitCode; + +const JEST_BINARY = argv.jestBinary || './node_modules/.bin/jest'; +const YARN_BINARY = argv.yarnBinary || 'yarn'; + +function describe(message) { + echo(`\n\n>>>>> ${message}\n\n\n`); +} + +try { + echo('Executing JavaScript tests'); + + describe('Test: eslint'); + if (exec(`${YARN_BINARY} run lint`).code) { + echo('Failed to run eslint.'); + exitCode = 1; + throw Error(exitCode); + } + + describe('Test: Flow check (iOS)'); + if (exec(`${YARN_BINARY} run flow-check-ios`).code) { + echo('Failed to run flow.'); + exitCode = 1; + throw Error(exitCode); + } + describe('Test: Flow check (Android)'); + if (exec(`${YARN_BINARY} run flow-check-android`).code) { + echo('Failed to run flow.'); + exitCode = 1; + throw Error(exitCode); + } + + describe('Test: Jest'); + if ( + exec( + `${JEST_BINARY} --maxWorkers=${numberOfMaxWorkers} --ci --reporters="default" --reporters="jest-junit"`, + ).code + ) { + echo('Failed to run JavaScript tests.'); + echo('Most likely the code is broken.'); + exitCode = 1; + throw Error(exitCode); + } + + exitCode = 0; +} finally { + // Do cleanup here + echo('Finished.'); +} +exit(exitCode); + +/*eslint-enable no-undef */