Files
react-native/scripts/run-ci-javascript-tests.js
T
Rubén Norte 705c675d51 Implement new feature flag system (#42430)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42430

This PR creates a new internal feature flags system for React Native. This is only meant to be used internally within the framework, but we might expose it externally in some form in the future to allow customizing specific feature flags in frameworks and applications.

Features:
* 2 types of flags:
  * Common: can be overridden from native and are accessible from all layers of the stack (Objective-C/Swift, Java/Kotlin, C++ and JavaScript).
  * JS-only: flags that can only be defined and accessed from JS (to allow things like hot reloading without a native build).
* 1 source of truth for each flag.
* Feature flags are application/process scoped (using C++ singletons).

See the `README.md` file in this PR for additional information.

This also adds modifies `run-ci-javascript-tests` to run a new check to make sure that the generate files are in sync with the JSON file that contains the definitions.

Changelog: [internal]

Reviewed By: huntie

Differential Revision: D52806730

fbshipit-source-id: 0ba95803f61ec2f05266ee535921321bf6d3dc6a
2024-01-25 13:55:11 -08:00

109 lines
2.7 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and 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
*/
const {echo, exec, exit} = require('shelljs');
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');
describe('Test: feature flags codegen');
if (exec(`${YARN_BINARY} run featureflags-check`).code) {
echo('Failed to run featureflags check.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: eslint');
if (exec(`${YARN_BINARY} run lint`).code) {
echo('Failed to run eslint.');
exitCode = 1;
throw Error(exitCode);
}
describe('Test: Flow check');
if (exec(`${YARN_BINARY} run flow-check`).code) {
echo('Failed to run flow.');
exitCode = 1;
throw Error(exitCode);
}
/*
* Build @react-native/codegen and @react-native/codegen-typescript-test
*
* 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
*/
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);
}
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);
}
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);
}
describe('Test: TypeScript tests');
if (exec(`${YARN_BINARY} run test-typescript-offline`).code) {
echo('Failed to run TypeScript tests.');
exitCode = 1;
throw Error(exitCode);
}
exitCode = 0;
} finally {
// Do cleanup here
echo('Finished.');
}
exit(exitCode);