1/** 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 * @format 8 */ 9 10'use strict'; 11 12/** 13 * This script runs JavaScript tests. 14 * Available arguments: 15 * --maxWorkers [num] - how many workers, default 1 16 * --jestBinary [path] - path to jest binary, defaults to local node modules 17 * --yarnBinary [path] - path to yarn binary, defaults to yarn 18 */ 19 20const {echo, exec, exit} = require('shelljs'); 21const argv = require('yargs').argv; 22 23const numberOfMaxWorkers = argv.maxWorkers || 1; 24let exitCode; 25 26const JEST_BINARY = argv.jestBinary || './node_modules/.bin/jest'; 27const YARN_BINARY = argv.yarnBinary || 'yarn'; 28 29function describe(message) { 30 echo(`\n\n>>>>> ${message}\n\n\n`); 31} 32 33try { 34 echo('Executing JavaScript tests'); 35 36 describe('Test: eslint'); 37 if (exec(`${YARN_BINARY} run lint`).code) { 38 echo('Failed to run eslint.'); 39 exitCode = 1; 40 throw Error(exitCode); 41 } 42 43 describe('Test: Flow check (iOS)'); 44 if (exec(`${YARN_BINARY} run flow-check-ios`).code) { 45 echo('Failed to run flow.'); 46 exitCode = 1; 47 throw Error(exitCode); 48 } 49 describe('Test: Flow check (Android)'); 50 if (exec(`${YARN_BINARY} run flow-check-android`).code) { 51 echo('Failed to run flow.'); 52 exitCode = 1; 53 throw Error(exitCode); 54 } 55 56 describe('Test: Jest'); 57 if ( 58 exec( 59 `${JEST_BINARY} --maxWorkers=${numberOfMaxWorkers} --ci --reporters="default" --reporters="jest-junit"`, 60 ).code 61 ) { 62 echo('Failed to run JavaScript tests.'); 63 echo('Most likely the code is broken.'); 64 exitCode = 1; 65 throw Error(exitCode); 66 } 67 68 exitCode = 0; 69} finally { 70 // Do cleanup here 71 echo('Finished.'); 72} 73exit(exitCode); 74