import type { Config as CLIConfig } from "@react-native-community/cli-types" ; import { parsePlatform } from "@rnx-kit/tools-react-native/platform" ; import { run as runJest } from "jest-cli" ; import path from "path" ; type Args = { platform : "android" | "ios" | "macos" | "windows" | "win32" ; } ; type Options = { name : string ; description ? : string ; parse ? : ( val : string ) => unknown ; default ? : string | boolean | number | ( ( config : CLIConfig ) => string | boolean | number ) ; } ; const COMMAND_NAME = "rnx-test" ; export function rnxTest ( _argv , _config , { platform } ) { const commandIndex = process . argv . indexOf ( COMMAND_NAME ) ; if ( commandIndex < 0 ) { throw new Error ( "Failed to parse command arguments" ) ; } const argv = process . argv . slice ( commandIndex + 1 ) ; const platformIndex = argv . indexOf ( "--platform" ) ; if ( platformIndex < 0 ) { throw new Error ( "A target platform must be specified" ) ; } argv . splice ( platformIndex , 2 ) ; process . env [ "RN_TARGET_PLATFORM" ] = platform ; runJest ( argv ) ; } function jestOptions ( ) { const jestPath = require . resolve ( "jest-cli/package.json" ) ; const { options } = require ( `${ path . dirname ( jestPath ) }/build/cli/args` ) ; return Object . keys ( options ) . map ( ( option ) => { const { default : defaultValue , description , type } = options [ option ] ; return { name : `--${ option } [${ type }]` , description , default : defaultValue } ; } ) ; } export const rnxTestCommand = { name : COMMAND_NAME , description : "Test runner for React Native apps" , func : rnxTest , options : [ { name : "--platform [android|ios|macos|windows|win32]" , description : "Platform to target" , parse : parsePlatform } , ... jestOptions ( ) , ] } ;