Files
react-native/private/react-native-fantom/runner/EnvironmentOptions.js
T
Rubén NorteandFacebook GitHub Bot 54d733311d Add validation for environment variables for Fantom (#52779)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52779

Changelog: [internal]

Adds validation for Fantom environment variables at runtime, to catch typos or variables that no longer have an effect.

Reviewed By: rshest

Differential Revision: D78803045

fbshipit-source-id: efb28a4f3fd6a4be35fb525d91fb093a1e88f7e4
2025-07-23 04:41:42 -07:00

79 lines
2.2 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.
*
* @flow strict
* @format
*/
const VALID_ENVIRONMENT_VARIABLES = [
'FANTOM_DEBUG_CPP',
'FANTOM_ENABLE_CPP_DEBUGGING',
'FANTOM_FORCE_CI_MODE',
'FANTOM_FORCE_OSS_BUILD',
'FANTOM_FORCE_TEST_MODE',
'FANTOM_LOG_COMMANDS',
'FANTOM_PRINT_OUTPUT',
];
/**
* Prints the output of the Fantom tester to the test output.
*/
export const printCLIOutput: boolean = Boolean(process.env.FANTOM_PRINT_OUTPUT);
/**
* Logs all external commands executed by the runner.
*/
export const logCommands: boolean = Boolean(process.env.FANTOM_LOG_COMMANDS);
/**
* Enables the C++ debugger for the current test run.
*/
export const debugCpp: boolean =
Boolean(process.env.FANTOM_DEBUG_CPP) ||
// Legacy
Boolean(process.env.FANTOM_ENABLE_CPP_DEBUGGING);
/**
* Indicates if the current test run is done in an OSS environment (as opposed
* to internal Meta infra).
*/
export const isOSS: boolean = Boolean(process.env.FANTOM_FORCE_OSS_BUILD);
/**
* Indicates if the current test run is done in CI, which forces:
* 1. Prebuilding all binaries (Fantom tester and Hermes compiler).
* 2. Running benchmarks in test mode (see below).
*/
export const isCI: boolean =
Boolean(process.env.FANTOM_FORCE_CI_MODE) ||
Boolean(process.env.SANDCASTLE) ||
Boolean(process.env.GITHUB_ACTIONS);
/**
* Forces benchmarks to run in test mode (running a single time to ensure
* correctness instead of multiples times to measure performance).
*/
export const forceTestModeForBenchmarks: boolean = Boolean(
process.env.FANTOM_FORCE_TEST_MODE,
);
/**
* Throws an error if there is an environment variable defined with the FANTOM_
* prefix that is not recognized.
*/
export function validateEnvironmentVariables(): void {
for (const key of Object.keys(process.env)) {
if (
key.startsWith('FANTOM_') &&
!VALID_ENVIRONMENT_VARIABLES.includes(key)
) {
throw new Error(
`Unexpected Fantom environment variable: ${key}=${String(process.env[key])}. Accepted variables are: ${VALID_ENVIRONMENT_VARIABLES.join(', ')}`,
);
}
}
}