Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/utils/__tests__/test-common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,51 @@ describe('createTestExecutor', () => {
expect(runTestsIndex).toBeGreaterThan(-1);
expect(finalSummaryIndex).toBeGreaterThan(runTestsIndex);
});
it('uses the source test phase for prepared products containing multiple simulator platforms', async () => {
const commands: string[][] = [];
const executor: CommandExecutor = async (command) => {
commands.push(command);
if (command.at(-1) === 'build-for-testing') {
const testProductsIndex = command.indexOf('-testProductsPath');
const testProductsPath = command[testProductsIndex + 1]!;
mkdirSync(join(testProductsPath, 'Tests', '0'), { recursive: true });
writeFileSync(
join(testProductsPath, 'Tests', '0', 'Weather.xctestrun'),
`<?xml version="1.0"?><plist><dict><key>TestConfigurations</key><array><dict><key>TestTargets</key><array><dict><key>DependentProductPaths</key><array><string>__TESTROOT__/Debug-iphonesimulator/Weather.app</string><string>__TESTROOT__/Debug-watchsimulator/WatchTests.xctest</string></array></dict></array></dict></array></dict></plist>`,
);
}
return createSuccessfulCommandResponse();
};

const executeTest = createTestExecutor(executor, {
preflight: createPreflight(),
toolName: 'test_sim',
target: 'simulator',
request: {
scheme: 'Weather',
projectPath: 'Weather.xcodeproj',
configuration: 'Debug',
platform: XcodePlatform.iOSSimulator,
},
});

await executeTest(
{
projectPath: 'Weather.xcodeproj',
scheme: 'Weather',
configuration: 'Debug',
simulatorId: 'A2C64636-37E9-4B68-B872-E7F0A82A5670',
platform: XcodePlatform.iOSSimulator,
},
new DefaultStreamingExecutionContext(),
);

expect(commands).toHaveLength(2);
expect(commands[1]).toContain('-project');
expect(commands[1]).toContain('-scheme');
expect(commands[1]).toContain('-derivedDataPath');
expect(commands[1]).not.toContain('-testProductsPath');
});

it('injects a workspace-scoped default result bundle path for macOS test commands', async () => {
const commands: string[][] = [];
Expand Down
41 changes: 31 additions & 10 deletions src/utils/test-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as path from 'node:path';
import { log } from './logger.ts';
import { constructDestinationString, XcodePlatform } from './xcode.ts';
import { executeXcodeBuildCommand } from './build/index.ts';
import type { BuildCommandResult } from './build/index.ts';
import { extractTestFailuresFromXcresult } from './xcresult-test-failures.ts';

import { normalizeTestRunnerEnv } from './environment.ts';
Expand All @@ -23,6 +24,7 @@ import {
} from './result-bundle-path.ts';
import {
createDefaultTestProductsPath,
hasMultipleSimulatorPlatforms,
markTestProductsPathCompleted,
} from './test-products-path.ts';
import { resolvePathFromCwd } from './path.ts';
Expand Down Expand Up @@ -317,17 +319,36 @@ export function createTestExecutor(
message: 'Running tests',
});

let testWithoutBuildingResult: PreparedTestCommandResult;
let testWithoutBuildingResult: PreparedTestCommandResult | BuildCommandResult;
try {
testWithoutBuildingResult = await executePreparedTestCommand(
{ ...params, testProductsPath },
filterPreparedTestExtraArgs(executionPlan.testArgs),
resultBundlePath,
executor,
execOpts,
started.pipeline,
getPreparedTestDestinationArgs(executionPlan.testArgs),
);
const usesMultipleSimulatorPlatforms =
await hasMultipleSimulatorPlatforms(testProductsPath);
testWithoutBuildingResult = usesMultipleSimulatorPlatforms
? await executeXcodeBuildCommand(
{
...params,
extraArgs: [
...filterPreparedTestExtraArgs(executionPlan.testArgs),
'-resultBundlePath',
resultBundlePath,
],
},
platformOptions,
params.preferXcodebuild,
'test-without-building',
executor,
execOpts,
started.pipeline,
)
: await executePreparedTestCommand(
{ ...params, testProductsPath },
filterPreparedTestExtraArgs(executionPlan.testArgs),
resultBundlePath,
executor,
execOpts,
started.pipeline,
getPreparedTestDestinationArgs(executionPlan.testArgs),
);
} finally {
markTestProductsPathCompleted(testProductsPath);
if (shouldUseDefaultResultBundlePath) {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/test-products-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ export async function findXctestrunPaths(testProductsPath: string): Promise<stri
await collectXctestrunPaths(testProductsPath, paths);
return paths.sort((left, right) => left.localeCompare(right));
}
export async function hasMultipleSimulatorPlatforms(testProductsPath: string): Promise<boolean> {
const xctestrunPaths = await findXctestrunPaths(testProductsPath);
const simulatorPlatforms = new Set<string>();

for (const xctestrunPath of xctestrunPaths) {
const contents = await fs.promises.readFile(xctestrunPath, 'utf8');
for (const match of contents.matchAll(/(?:^|[-/])([A-Za-z]+simulator)(?:[/\\])/gu)) {
simulatorPlatforms.add(match[1]!.toLowerCase());
}
if (simulatorPlatforms.size > 1) {
return true;
}
}

return false;
}

export function markTestProductsPathCompleted(testProductsPath: string | undefined): void {
if (!testProductsPath) {
Expand Down