diff --git a/packages/react-native-fantom/runner/EnvironmentOptions.js b/packages/react-native-fantom/runner/EnvironmentOptions.js new file mode 100644 index 00000000000..dd2cfd7fdc2 --- /dev/null +++ b/packages/react-native-fantom/runner/EnvironmentOptions.js @@ -0,0 +1,14 @@ +/** + * 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 + * @oncall react_native + */ + +export const printCLIOutput: boolean = Boolean(process.env.FANTOM_PRINT_OUTPUT); + +export const logCommands: boolean = Boolean(process.env.FANTOM_LOG_COMMANDS); diff --git a/packages/react-native-fantom/runner/runner.js b/packages/react-native-fantom/runner/runner.js index 1b53dc7f906..ef86cd44415 100644 --- a/packages/react-native-fantom/runner/runner.js +++ b/packages/react-native-fantom/runner/runner.js @@ -13,6 +13,7 @@ import type {TestSuiteResult} from '../runtime/setup'; import type {AsyncCommandResult} from './utils'; import entrypointTemplate from './entrypoint-template'; +import * as EnvironmentOptions from './EnvironmentOptions'; import getFantomTestConfig from './getFantomTestConfig'; import {FantomTestConfigMode} from './getFantomTestConfig'; import { @@ -43,8 +44,6 @@ const BUILD_OUTPUT_PATH = fs.mkdtempSync( path.join(BUILD_OUTPUT_ROOT, `run-${Date.now()}-`), ); -const PRINT_FANTOM_OUTPUT: false = false; - async function processRNTesterCommandResult( result: AsyncCommandResult, ): Promise { @@ -108,7 +107,7 @@ async function processRNTesterCommandResult( throw new Error(getDebugInfoFromCommandResult(getResultWithOutput())); } - if (PRINT_FANTOM_OUTPUT) { + if (EnvironmentOptions.printCLIOutput) { console.log(getDebugInfoFromCommandResult(getResultWithOutput())); } @@ -248,7 +247,7 @@ module.exports = async function runTest( '--featureFlags', JSON.stringify(testConfig.flags.common), '--minLogLevel', - PRINT_FANTOM_OUTPUT ? 'info' : 'error', + EnvironmentOptions.printCLIOutput ? 'info' : 'error', ]); const processedResult = await processRNTesterCommandResult( diff --git a/packages/react-native-fantom/runner/utils.js b/packages/react-native-fantom/runner/utils.js index 4ec6299e8ce..868ec44a573 100644 --- a/packages/react-native-fantom/runner/utils.js +++ b/packages/react-native-fantom/runner/utils.js @@ -9,6 +9,7 @@ * @oncall react_native */ +import * as EnvironmentOptions from './EnvironmentOptions'; import {spawn, spawnSync} from 'child_process'; import crypto from 'crypto'; import fs from 'fs'; @@ -66,10 +67,18 @@ export type SyncCommandResult = { stderr: string, }; +function maybeLogCommand(command: string, args: Array): void { + if (EnvironmentOptions.logCommands) { + console.log(`RUNNING \`${command} ${args.join(' ')}\``); + } +} + export function runCommand( command: string, args: Array, ): AsyncCommandResult { + maybeLogCommand(command, args); + const childProcess = spawn(command, args, { encoding: 'utf8', env: { @@ -107,6 +116,8 @@ export function runCommandSync( command: string, args: Array, ): SyncCommandResult { + maybeLogCommand(command, args); + const result = spawnSync(command, args, { encoding: 'utf8', env: {