Skip to content

Commit

Permalink
Run the same JavaScript test script in Sandcastle and Circle (faceboo…
Browse files Browse the repository at this point in the history
…k#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.

[General] [Changed] - Switch internal and external CI to use the same script when running JavaScript tests

Pull Request resolved: facebook#24422

Reviewed By: cpojer

Differential Revision: D14895773

fbshipit-source-id: d428929cc4e5219e02f5920259e08e0b3d24874c
  • Loading branch information
hramos authored and facebook-github-bot committed Apr 12, 2019
1 parent 00243c5 commit 5bac2b7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
21 changes: 15 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
77 changes: 77 additions & 0 deletions scripts/run-ci-javascript-tests.js
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 5bac2b7

Please sign in to comment.