Skip to content

Commit

Permalink
chore: fix tests (#5786)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Walker <walkerrunpdx@gmail.com>
  • Loading branch information
rigor789 and NathanWalker committed Feb 2, 2024
1 parent 6d133d9 commit 2577ff7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/services/ios/xcodebuild-args-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
platformData.projectRoot,
`${projectData.projectName}.xcworkspace`
);

// Introduced in Xcode 14+
// ref: https://forums.swift.org/t/telling-xcode-14-beta-4-to-trust-build-tool-plugins-programatically/59305/5
const skipPackageValidation = "-skipPackagePluginValidation";
Expand Down
67 changes: 44 additions & 23 deletions test/services/ios/xcodebuild-args-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as path from "path";
import * as _ from "lodash";
import { assert } from "chai";
import { IInjector } from "../../../lib/common/definitions/yok";
import { BUILD_XCCONFIG_FILE_NAME } from "../../../lib/constants";

function createTestInjector(data: {
logLevel: string;
Expand All @@ -18,7 +19,13 @@ function createTestInjector(data: {
getDevicesForPlatform: () => data.connectedDevices || [],
});
injector.register("fs", {
exists: () => data.hasProjectWorkspace,
exists: (filepath: string) => {
if (filepath.includes(BUILD_XCCONFIG_FILE_NAME)) {
return true;
} else {
return data.hasProjectWorkspace;
}
},
});
injector.register("logger", {
getLevel: () => data.logLevel,
Expand All @@ -32,6 +39,8 @@ function createTestInjector(data: {
}

const projectRoot = "path/to/my/app/folder/platforms/ios";
const normalizedPlatformName = "iOS";
const appResourcesDirectoryPath = "App_Resources";
const projectName = "myApp";
const buildOutputPath = path.join(projectRoot, projectName, "archive");

Expand All @@ -43,18 +52,27 @@ function getCommonArgs() {
}

function getXcodeProjectArgs(data?: { hasProjectWorkspace: boolean }) {
const extraArgs = [
"-scheme",
projectName,
"-skipPackagePluginValidation",
"-xcconfig",
path.join(
appResourcesDirectoryPath,
normalizedPlatformName,
BUILD_XCCONFIG_FILE_NAME
),
];
return data && data.hasProjectWorkspace
? [
"-workspace",
path.join(projectRoot, `${projectName}.xcworkspace`),
"-scheme",
projectName,
...extraArgs,
]
: [
"-project",
path.join(projectRoot, `${projectName}.xcodeproj`),
"-scheme",
projectName,
...extraArgs,
];
}

Expand Down Expand Up @@ -84,11 +102,12 @@ describe("xcodebuildArgsService", () => {
const xcodebuildArgsService = injector.resolve(
"xcodebuildArgsService"
);
const actualArgs = await xcodebuildArgsService.getBuildForSimulatorArgs(
{ projectRoot },
{ projectName },
buildConfig
);
const actualArgs =
await xcodebuildArgsService.getBuildForSimulatorArgs(
{ projectRoot, normalizedPlatformName },
{ projectName, appResourcesDirectoryPath },
buildConfig
);

const expectedArgs = [
"ONLY_ACTIVE_ARCH=NO",
Expand All @@ -114,8 +133,7 @@ describe("xcodebuildArgsService", () => {
describe("getBuildForDeviceArgs", () => {
const testCases = [
{
name:
"should return correct args when there are more than one connected device",
name: "should return correct args when there are more than one connected device",
connectedDevices: [
{ deviceInfo: { activeArchitecture: "arm64" } },
{ deviceInfo: { activeArchitecture: "armv7" } },
Expand All @@ -125,8 +143,7 @@ describe("xcodebuildArgsService", () => {
),
},
{
name:
"should return correct args when there is only one connected device",
name: "should return correct args when there is only one connected device",
connectedDevices: [{ deviceInfo: { activeArchitecture: "arm64" } }],
expectedArgs: ["-sdk", "iphoneos"].concat(getCommonArgs()),
},
Expand All @@ -150,21 +167,25 @@ describe("xcodebuildArgsService", () => {

const platformData = {
projectRoot,
normalizedPlatformName,
getBuildOutputPath: () => buildOutputPath,
};
const projectData = { projectName };
const projectData = {
projectName,
appResourcesDirectoryPath,
};
const buildConfig = {
buildForDevice: true,
release: configuration === "Release",
};
const xcodebuildArgsService: IXcodebuildArgsService = injector.resolve(
"xcodebuildArgsService"
);
const actualArgs = await xcodebuildArgsService.getBuildForDeviceArgs(
<any>platformData,
<any>projectData,
<any>buildConfig
);
const xcodebuildArgsService: IXcodebuildArgsService =
injector.resolve("xcodebuildArgsService");
const actualArgs =
await xcodebuildArgsService.getBuildForDeviceArgs(
<any>platformData,
<any>projectData,
<any>buildConfig
);

const expectedArgs = [
"-destination",
Expand Down

0 comments on commit 2577ff7

Please sign in to comment.