Skip to content

Commit 13cad6a

Browse files
committed
fix: add unit tests
1 parent 9e6c839 commit 13cad6a

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

test/ios-project-service.ts

+125
Original file line numberDiff line numberDiff line change
@@ -1055,3 +1055,128 @@ describe("Merge Project XCConfig files", () => {
10551055
}
10561056
});
10571057
});
1058+
1059+
describe("buildProject", () => {
1060+
let xcodeBuildCommandArgs: string[] = [];
1061+
1062+
function setup(data: { frameworkVersion: string, deploymentTarget: string, devices?: Mobile.IDevice[] }): IInjector {
1063+
const projectPath = "myTestProjectPath";
1064+
const projectName = "myTestProjectName";
1065+
const testInjector = createTestInjector(projectPath, projectName);
1066+
1067+
const childProcess = testInjector.resolve("childProcess");
1068+
childProcess.spawnFromEvent = (command: string, args: string[]) => {
1069+
if (command === "xcodebuild" && args[0] !== "-exportArchive") {
1070+
xcodeBuildCommandArgs = args;
1071+
}
1072+
};
1073+
1074+
const projectDataService = testInjector.resolve("projectDataService");
1075+
projectDataService.getNSValue = (projectDir: string, propertyName: string) => {
1076+
if (propertyName === "tns-ios") {
1077+
return {
1078+
name: "tns-ios",
1079+
version: data.frameworkVersion
1080+
};
1081+
}
1082+
};
1083+
1084+
const projectData = testInjector.resolve("projectData");
1085+
projectData.appResourcesDirectoryPath = path.join(projectPath, "app", "App_Resources");
1086+
1087+
const devicesService = testInjector.resolve("devicesService");
1088+
devicesService.initialize = () => ({});
1089+
devicesService.getDeviceInstances = () => data.devices || [];
1090+
1091+
const xCConfigService = testInjector.resolve("xCConfigService");
1092+
xCConfigService.readPropertyValue = (projectDir: string, propertyName: string) => {
1093+
if (propertyName === "IPHONEOS_DEPLOYMENT_TARGET") {
1094+
return data.deploymentTarget;
1095+
}
1096+
};
1097+
1098+
const pbxprojDomXcode = testInjector.resolve("pbxprojDomXcode");
1099+
pbxprojDomXcode.Xcode = {
1100+
open: () => ({
1101+
getSigning: () => ({}),
1102+
setAutomaticSigningStyle: () => ({}),
1103+
save: () => ({})
1104+
})
1105+
};
1106+
1107+
const iOSProvisionService = testInjector.resolve("iOSProvisionService");
1108+
iOSProvisionService.getDevelopmentTeams = () => ({});
1109+
iOSProvisionService.getTeamIdsWithName = () => ({});
1110+
1111+
return testInjector;
1112+
}
1113+
1114+
function executeTests(testCases: any[], data: { buildForDevice: boolean }) {
1115+
_.each(testCases, testCase => {
1116+
it(`${testCase.name}`, async () => {
1117+
const testInjector = setup({ frameworkVersion: testCase.frameworkVersion, deploymentTarget: testCase.deploymentTarget });
1118+
const projectData: IProjectData = testInjector.resolve("projectData");
1119+
1120+
const iOSProjectService = <IOSProjectService>testInjector.resolve("iOSProjectService");
1121+
(<any>iOSProjectService).getExportOptionsMethod = () => ({});
1122+
await iOSProjectService.buildProject("myProjectRoot", projectData, <any>{ buildForDevice: data.buildForDevice });
1123+
1124+
const archsItem = xcodeBuildCommandArgs.find(item => item.startsWith("ARCHS="));
1125+
if (testCase.expectedArchs) {
1126+
const archsValue = archsItem.split("=")[1];
1127+
assert.deepEqual(archsValue, testCase.expectedArchs);
1128+
} else {
1129+
assert.deepEqual(undefined, archsItem);
1130+
}
1131+
});
1132+
});
1133+
}
1134+
1135+
describe("for device", () => {
1136+
afterEach(() => {
1137+
xcodeBuildCommandArgs = [];
1138+
});
1139+
1140+
const testCases = <any[]>[{
1141+
name: "shouldn't exclude armv7 architecture when deployment target 10",
1142+
frameworkVersion: "5.0.0",
1143+
deploymentTarget: "10.0",
1144+
expectedArchs: "armv7 arm64"
1145+
}, {
1146+
name: "should exclude armv7 architecture when deployment target is 11",
1147+
frameworkVersion: "5.0.0",
1148+
deploymentTarget: "11.0",
1149+
expectedArchs: "arm64"
1150+
}, {
1151+
name: "shouldn't pass architecture to xcodebuild command when frameworkVersion is 5.1.0",
1152+
frameworkVersion: "5.1.0",
1153+
deploymentTarget: "11.0"
1154+
}];
1155+
1156+
executeTests(testCases, { buildForDevice: true });
1157+
});
1158+
1159+
describe("for simulator", () => {
1160+
afterEach(() => {
1161+
xcodeBuildCommandArgs = [];
1162+
});
1163+
1164+
const testCases = [{
1165+
name: "shouldn't exclude i386 architecture when deployment target is 10",
1166+
frameworkVersion: "5.0.0",
1167+
deploymentTarget: "10.0",
1168+
expectedArchs: "i386 x86_64"
1169+
}, {
1170+
name: "should exclude i386 architecture when deployment target is 11",
1171+
frameworkVersion: "5.0.0",
1172+
deploymentTarget: "11.0",
1173+
expectedArchs: "x86_64"
1174+
}, {
1175+
name: "shouldn't pass architecture to xcodebuild command when frameworkVersion is 5.1.0",
1176+
frameworkVersion: "5.1.0",
1177+
deploymentTarget: "11.0"
1178+
}];
1179+
1180+
executeTests(testCases, { buildForDevice: false });
1181+
});
1182+
});

test/stubs.ts

+7
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
467467
getPluginPlatformsFolderPath(pluginData: IPluginData, platform: string): string {
468468
return "";
469469
}
470+
getDeploymentTarget(projectData: IProjectData): IDeploymentTargetData {
471+
return;
472+
}
470473
}
471474

472475
export class PlatformsDataStub extends EventEmitter implements IPlatformsData {
@@ -828,6 +831,10 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
828831
return true;
829832
}
830833

834+
public async validateInstall(device: Mobile.IDevice): Promise<void> {
835+
return;
836+
}
837+
831838
public installApplication(device: Mobile.IDevice, options: IRelease): Promise<void> {
832839
return Promise.resolve();
833840
}

0 commit comments

Comments
 (0)