( executor: CommandExecutor = getDefaultCommandExecutor(), options: SharedTestExecutorOptions, )
| 106 | } |
| 107 | |
| 108 | export function createTestExecutor( |
| 109 | executor: CommandExecutor = getDefaultCommandExecutor(), |
| 110 | options: SharedTestExecutorOptions, |
| 111 | ): StreamingExecutor<SharedTestExecutorParams, TestResultDomainResult> { |
| 112 | return async (params, ctx) => { |
| 113 | log( |
| 114 | 'info', |
| 115 | `Starting test run for scheme ${params.scheme} on platform ${params.platform} (executor)`, |
| 116 | ); |
| 117 | |
| 118 | const execOpts: CommandExecOptions | undefined = params.testRunnerEnv |
| 119 | ? { env: normalizeTestRunnerEnv(params.testRunnerEnv) } |
| 120 | : undefined; |
| 121 | const shouldUseTwoPhaseSimulatorExecution = |
| 122 | String(params.platform).includes('Simulator') && Boolean(options.preflight); |
| 123 | const toolName = options.toolName ?? 'test_sim'; |
| 124 | const target = options.target ?? getBuildTarget(params.platform); |
| 125 | const started = createDomainStreamingPipeline(toolName, 'TEST', ctx, 'test-result'); |
| 126 | const platformOptions = { |
| 127 | platform: params.platform, |
| 128 | simulatorName: params.simulatorName, |
| 129 | simulatorId: params.simulatorId, |
| 130 | deviceId: params.deviceId, |
| 131 | useLatestOS: params.useLatestOS, |
| 132 | packageCachePath: params.packageCachePath, |
| 133 | logPrefix: 'Test Run', |
| 134 | }; |
| 135 | const discoveryEvent = createTestDiscoveryFragment(options.preflight); |
| 136 | |
| 137 | if (discoveryEvent) { |
| 138 | started.pipeline.emitFragment(discoveryEvent); |
| 139 | } |
| 140 | |
| 141 | try { |
| 142 | const parsedResultBundleArgs = parseResultBundlePathArgs(params.extraArgs); |
| 143 | const shouldUseDefaultResultBundlePath = !parsedResultBundleArgs.resultBundlePath; |
| 144 | const resultBundlePath = |
| 145 | parsedResultBundleArgs.resultBundlePath ?? createDefaultResultBundlePath(toolName); |
| 146 | |
| 147 | if (shouldUseTwoPhaseSimulatorExecution) { |
| 148 | const executionPlan = createSimulatorTwoPhaseExecutionPlan({ |
| 149 | extraArgs: params.extraArgs, |
| 150 | preflight: options.preflight, |
| 151 | resultBundlePath, |
| 152 | }); |
| 153 | |
| 154 | const buildForTestingResult = await executeXcodeBuildCommand( |
| 155 | { ...params, extraArgs: executionPlan.buildArgs }, |
| 156 | platformOptions, |
| 157 | params.preferXcodebuild, |
| 158 | 'build-for-testing', |
| 159 | executor, |
| 160 | execOpts, |
| 161 | started.pipeline, |
| 162 | ); |
| 163 | |
| 164 | if (buildForTestingResult.isError) { |
| 165 | return createTestDomainResult({ |
no test coverage detected