2019-04-12 09:50:13 -07:00
|
|
|
/**
|
2021-12-30 15:08:43 -08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-04-12 09:50:13 -07:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
*
|
|
|
|
|
* @format
|
2025-07-02 03:09:18 -07:00
|
|
|
* @flow strict-local
|
2019-04-12 09:50:13 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'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
|
2025-07-02 03:09:18 -07:00
|
|
|
* --flowBinary [path] - path to flow binary, defaults to running `yarn run flow-check`
|
2019-04-12 09:50:13 -07:00
|
|
|
*/
|
|
|
|
|
|
2025-06-23 09:39:44 -07:00
|
|
|
const {execSync} = require('child_process');
|
2025-08-01 20:18:36 -07:00
|
|
|
const argv /*:$ReadOnly<{
|
2025-07-02 03:09:18 -07:00
|
|
|
maxWorkers?: number,
|
|
|
|
|
jestBinary?: string,
|
|
|
|
|
flowBinary?: string,
|
|
|
|
|
yarnBinary?: string,
|
2025-08-01 20:18:36 -07:00
|
|
|
}> */ =
|
2025-08-22 10:35:39 -07:00
|
|
|
// $FlowFixMe[incompatible-type]
|
|
|
|
|
// $FlowFixMe[incompatible-exact]
|
|
|
|
|
// $FlowFixMe[incompatible-indexer]
|
2025-08-01 20:18:36 -07:00
|
|
|
require('yargs').argv;
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2025-07-02 03:09:18 -07:00
|
|
|
const numberOfMaxWorkers = argv.maxWorkers ?? 1;
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2025-07-02 03:09:18 -07:00
|
|
|
const JEST_BINARY = argv.jestBinary ?? './node_modules/.bin/jest';
|
2025-04-15 16:09:45 -07:00
|
|
|
const FLOW_BINARY = argv.flowBinary;
|
2025-07-02 03:09:18 -07:00
|
|
|
const YARN_BINARY = argv.yarnBinary ?? 'yarn';
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2025-07-02 03:09:18 -07:00
|
|
|
class ExecError extends Error {
|
|
|
|
|
constructor(cause /*: Error */) {
|
|
|
|
|
super(cause.message, {cause});
|
|
|
|
|
this.name = 'ExecError';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function describe(message /*: string */) {
|
2025-06-23 09:39:44 -07:00
|
|
|
console.log(`\n\n>>>>> ${message}\n\n\n`);
|
2019-04-12 09:50:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2025-06-23 09:39:44 -07:00
|
|
|
console.log('Executing JavaScript tests');
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2024-01-26 09:55:27 -08:00
|
|
|
describe('Test: feature flags codegen');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(`${YARN_BINARY} run featureflags --verify-unchanged`);
|
2026-02-05 09:14:33 -08:00
|
|
|
|
2019-04-12 09:50:13 -07:00
|
|
|
describe('Test: eslint');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(`${YARN_BINARY} run lint`);
|
2024-12-06 13:21:23 -08:00
|
|
|
|
2025-07-01 08:58:15 -07:00
|
|
|
describe('Test: Validate JS API snapshot');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(`${YARN_BINARY} run build-types --validate`);
|
2025-07-01 08:58:15 -07:00
|
|
|
|
2023-08-26 10:00:22 -07:00
|
|
|
describe('Test: Flow check');
|
2025-04-15 16:09:45 -07:00
|
|
|
const flowCommand =
|
|
|
|
|
FLOW_BINARY == null
|
|
|
|
|
? `${YARN_BINARY} run flow-check`
|
2025-12-15 15:41:33 -08:00
|
|
|
: `${FLOW_BINARY} full-check`;
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(flowCommand);
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2023-04-05 07:38:25 -07:00
|
|
|
/*
|
2023-10-23 12:00:54 -07:00
|
|
|
* Build @react-native/codegen and @react-native/codegen-typescript-test
|
2023-04-05 07:38:25 -07: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 12:00:54 -07:00
|
|
|
describe('Test: Build @react-native/codegen');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(`${YARN_BINARY} --cwd ./packages/react-native-codegen run build`);
|
2023-04-05 07:38:25 -07:00
|
|
|
describe('Test: Build @react-native/codegen-typescript-test');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(
|
|
|
|
|
`${YARN_BINARY} --cwd ./private/react-native-codegen-typescript-test run build`,
|
|
|
|
|
);
|
2023-04-05 07:38:25 -07:00
|
|
|
|
2019-04-12 09:50:13 -07:00
|
|
|
describe('Test: Jest');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(
|
|
|
|
|
`${JEST_BINARY} --maxWorkers=${numberOfMaxWorkers} --ci --reporters="default" --reporters="jest-junit"`,
|
|
|
|
|
);
|
2019-04-12 09:50:13 -07:00
|
|
|
|
2022-12-15 19:17:58 -08:00
|
|
|
describe('Test: TypeScript tests');
|
2025-07-02 03:09:18 -07:00
|
|
|
execAndLog(`${YARN_BINARY} run test-typescript`);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e instanceof ExecError) {
|
|
|
|
|
console.error(e.message);
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
} else {
|
|
|
|
|
throw e;
|
2022-12-15 19:17:58 -08:00
|
|
|
}
|
2019-04-12 09:50:13 -07:00
|
|
|
} finally {
|
2025-06-23 09:39:44 -07:00
|
|
|
console.log('Finished.');
|
2019-04-12 09:50:13 -07:00
|
|
|
}
|
2025-07-02 03:09:18 -07:00
|
|
|
|
|
|
|
|
function execAndLog(command /*: string */) {
|
|
|
|
|
console.log(`Executing: ${command}`);
|
|
|
|
|
try {
|
|
|
|
|
execSync(command, {
|
|
|
|
|
stdio: ['ignore', 'inherit', 'inherit'],
|
|
|
|
|
encoding: 'utf8',
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new ExecError(e);
|
|
|
|
|
}
|
|
|
|
|
}
|