Skip to content

chore: fix tests #5786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2024
Merged
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
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