2019-04-12 16:50:13 +00:00
|
|
|
/**
|
2021-12-30 23:08:43 +00:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-04-12 16:50:13 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-12-21 19:48:02 +00:00
|
|
|
const {echo, exec, exit} = require('shelljs');
|
2019-04-12 16:50:13 +00:00
|
|
|
const argv = require('yargs').argv;
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2024-01-26 17:55:27 +00:00
|
|
|
describe('Test: feature flags codegen');
|
2024-10-29 15:02:54 +00:00
|
|
|
if (exec(`${YARN_BINARY} run featureflags --verify-unchanged`).code) {
|
2024-01-26 17:55:27 +00:00
|
|
|
echo('Failed to run featureflags check.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
|
|
|
|
2019-04-12 16:50:13 +00:00
|
|
|
describe('Test: eslint');
|
|
|
|
if (exec(`${YARN_BINARY} run lint`).code) {
|
|
|
|
echo('Failed to run eslint.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
|
|
|
|
2023-08-26 17:00:22 +00:00
|
|
|
describe('Test: Flow check');
|
|
|
|
if (exec(`${YARN_BINARY} run flow-check`).code) {
|
2019-04-12 16:50:13 +00:00
|
|
|
echo('Failed to run flow.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
|
|
|
|
2023-04-05 14:38:25 +00:00
|
|
|
/*
|
2023-10-23 19:00:54 +00:00
|
|
|
* Build @react-native/codegen and @react-native/codegen-typescript-test
|
2023-04-05 14:38:25 +00:00
|
|
|
*
|
|
|
|
* The typescript-test project use TypeScript to write test cases
|
|
|
|
* In order to make these tests discoverable to jest
|
|
|
|
* *-test.ts must be compiled to *-test.js before running jest
|
|
|
|
*/
|
|
|
|
|
2023-10-23 19:00:54 +00:00
|
|
|
describe('Test: Build @react-native/codegen');
|
|
|
|
if (
|
|
|
|
exec(`${YARN_BINARY} --cwd ./packages/react-native-codegen run build`).code
|
|
|
|
) {
|
|
|
|
echo('Failed to build @react-native/codegen.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
2023-04-05 14:38:25 +00:00
|
|
|
describe('Test: Build @react-native/codegen-typescript-test');
|
|
|
|
if (
|
|
|
|
exec(
|
|
|
|
`${YARN_BINARY} --cwd ./packages/react-native-codegen-typescript-test run build`,
|
|
|
|
).code
|
|
|
|
) {
|
|
|
|
echo('Failed to build @react-native/codegen-typescript-test.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
|
|
|
|
2024-03-29 08:42:24 +00:00
|
|
|
// TODO: Improve handling of `exec` (e.g. check `signal`). Also, why use `shelljs`?
|
|
|
|
|
2019-04-12 16:50:13 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-12-16 03:17:58 +00:00
|
|
|
describe('Test: TypeScript tests');
|
|
|
|
if (exec(`${YARN_BINARY} run test-typescript-offline`).code) {
|
|
|
|
echo('Failed to run TypeScript tests.');
|
|
|
|
exitCode = 1;
|
|
|
|
throw Error(exitCode);
|
|
|
|
}
|
|
|
|
|
2019-04-12 16:50:13 +00:00
|
|
|
exitCode = 0;
|
|
|
|
} finally {
|
|
|
|
// Do cleanup here
|
|
|
|
echo('Finished.');
|
|
|
|
}
|
|
|
|
exit(exitCode);
|