Skip to content

Commit 5d543b5

Browse files
committed
Extract duplicated isResultBundlePathValue helper to shared utility
Create src/utils/result-bundle-path.ts with shared result bundle path parsing utilities to eliminate duplication between test-common.ts and simulator-test-execution.ts
1 parent 899b5b7 commit 5d543b5

3 files changed

Lines changed: 36 additions & 35 deletions

File tree

src/utils/result-bundle-path.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Shared utilities for parsing and validating -resultBundlePath arguments
3+
*/
4+
5+
export function isResultBundlePathValue(value: string | undefined): value is string {
6+
return value !== undefined && value.length > 0 && !value.startsWith('-');
7+
}
8+
9+
export function findResultBundlePathArg(extraArgs?: readonly string[]): string | undefined {
10+
if (!extraArgs) {
11+
return undefined;
12+
}
13+
14+
let resultBundlePath: string | undefined;
15+
for (let index = 0; index < extraArgs.length; index += 1) {
16+
const argument = extraArgs[index];
17+
if (argument === '-resultBundlePath') {
18+
const value = extraArgs[index + 1];
19+
if (isResultBundlePathValue(value)) {
20+
resultBundlePath = value;
21+
index += 1;
22+
}
23+
continue;
24+
}
25+
if (argument?.startsWith('-resultBundlePath=')) {
26+
const value = argument.slice('-resultBundlePath='.length);
27+
if (isResultBundlePathValue(value)) {
28+
resultBundlePath = value;
29+
}
30+
}
31+
}
32+
33+
return resultBundlePath;
34+
}

src/utils/simulator-test-execution.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { TestPreflightResult } from './test-preflight.ts';
2-
3-
function isResultBundlePathValue(value: string | undefined): value is string {
4-
return value !== undefined && value.length > 0 && !value.startsWith('-');
5-
}
2+
import { isResultBundlePathValue } from './result-bundle-path.ts';
63

74
function parseTestSelectorArgs(extraArgs: string[] | undefined): {
85
remainingArgs: string[];

src/utils/test-common.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getDefaultCommandExecutor } from './command.ts';
1616
import { type TestPreflightResult } from './test-preflight.ts';
1717

1818
import { createSimulatorTwoPhaseExecutionPlan } from './simulator-test-execution.ts';
19+
import { findResultBundlePathArg } from './result-bundle-path.ts';
1920

2021
import type {
2122
BuildTarget,
@@ -59,37 +60,6 @@ function getFallbackErrorMessages(
5960
return [...streamedLines, ...(responseContent ?? []).map((item) => item.text)];
6061
}
6162

62-
function isResultBundlePathValue(value: string | undefined): value is string {
63-
return value !== undefined && value.length > 0 && !value.startsWith('-');
64-
}
65-
66-
function findResultBundlePathArg(extraArgs?: readonly string[]): string | undefined {
67-
if (!extraArgs) {
68-
return undefined;
69-
}
70-
71-
let resultBundlePath: string | undefined;
72-
for (let index = 0; index < extraArgs.length; index += 1) {
73-
const argument = extraArgs[index];
74-
if (argument === '-resultBundlePath') {
75-
const value = extraArgs[index + 1];
76-
if (isResultBundlePathValue(value)) {
77-
resultBundlePath = value;
78-
index += 1;
79-
}
80-
continue;
81-
}
82-
if (argument?.startsWith('-resultBundlePath=')) {
83-
const value = argument.slice('-resultBundlePath='.length);
84-
if (isResultBundlePathValue(value)) {
85-
resultBundlePath = value;
86-
}
87-
}
88-
}
89-
90-
return resultBundlePath;
91-
}
92-
9363
function createXcodebuildTestArtifacts(
9464
params: Pick<SharedTestExecutorParams, 'deviceId'>,
9565
started: ReturnType<typeof createDomainStreamingPipeline>,

0 commit comments

Comments
 (0)