Skip to content

Commit 68b32eb

Browse files
refactor(utils): resolve new ios app paths (#197)
* refactor(utils): resolve new ios app paths
1 parent 8ede903 commit 68b32eb

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

lib/appium-server.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="node" />
2-
import * as child_process from "child_process";
31
import { INsCapabilities } from "./interfaces/ns-capabilities";
42
import { IDeviceManager } from "./interfaces/device-manager";
53
export declare class AppiumServer {
@@ -12,7 +10,7 @@ export declare class AppiumServer {
1210
constructor(_args: INsCapabilities);
1311
port: number;
1412
runType: string;
15-
readonly server: child_process.ChildProcess;
13+
readonly server: any;
1614
hasStarted: boolean;
1715
start(port: any, deviceManager?: IDeviceManager): Promise<boolean | this>;
1816
private startAppiumServer;

lib/appium-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { existsSync } from "fs";
1818
import { killAllProcessAndRelatedCommand } from "mobile-devices-controller";
1919

2020
export class AppiumServer {
21-
private _server: child_process.ChildProcess;
21+
private _server: any;
2222
private _appium;
2323
private _port: number;
2424
private _runType: string;

lib/utils.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="node" />
2-
import * as childProcess from "child_process";
31
import { INsCapabilities } from "./interfaces/ns-capabilities";
42
import { Point } from "./point";
53
import { Direction } from "./direction";
@@ -8,7 +6,7 @@ export declare function resolvePath(mainPath: any, ...args: any[]): string;
86
export declare function isDirectory(fullName: any): boolean;
97
export declare function isFile(fullName: any): boolean;
108
export declare function copy(src: any, dest: any, verbose: any): any;
11-
export declare function shutdown(processToKill: childProcess.ChildProcess, verbose: any): void;
9+
export declare function shutdown(processToKill: any, verbose: any): void;
1210
export declare function killPid(pid: any, verbose: any): void;
1311
export declare function waitForOutput(process: any, matcher: any, errorMatcher: any, timeout: any, verbose: any): Promise<boolean>;
1412
export declare function executeCommand(args: any, cwd?: string): string;

lib/utils.ts

+27-10
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function getAllFileNames(folder) {
141141
// return files;
142142
// }
143143

144-
export function shutdown(processToKill: childProcess.ChildProcess, verbose) {
144+
export function shutdown(processToKill: any, verbose) {
145145
try {
146146
if (processToKill && processToKill !== null) {
147147
if (isWin()) {
@@ -307,22 +307,39 @@ export function getAppPath(caps: INsCapabilities) {
307307
}
308308
} else {
309309
const iosPlatformsPath = 'platforms/ios/build';
310-
const appType = caps.runType || caps.device.type === DeviceType.SIMULATOR ? "sim" : "device";
311-
basePath = appType.includes("device") ? `${iosPlatformsPath}/device/**/*.ipa` : `${iosPlatformsPath}/emulator/**/*.app`;
310+
// possible paths
311+
// "Release-iphoneos"
312+
// "Release-iphonesimulator"
313+
// "Debug-iphoneos"
314+
// "Debug-iphonesimulator"
315+
// "device"
316+
// "emulator"
317+
if (caps.device && caps.device.type) {
318+
basePath = caps.device.type === DeviceType.DEVICE ? `${iosPlatformsPath}/**/*.ipa` : `${iosPlatformsPath}/**/*.app`;
319+
} else if (caps.runType.startsWith("dev")) {
320+
basePath = `${iosPlatformsPath}/**/*.ipa`;
321+
} else {
322+
basePath = `${iosPlatformsPath}/**/*.app`;
323+
}
312324
}
313325
}
314326

315327
let apps = glob.sync(basePath);
316-
317328
if (!apps || apps.length === 0) {
318-
apps = glob.sync(`${caps.projectDir}`)
319-
.filter(function (file) {
320-
return file.endsWith(".ipa") || file.endsWith(".app") || file.endsWith(".apk")
321-
});
329+
if (caps.isAndroid) {
330+
apps = glob.sync(`${caps.projectDir}/**/*.apk`);
331+
}
332+
if (caps.isIOS) {
333+
if (caps.runType.startsWith("dev")) {
334+
apps = glob.sync(`${caps.projectDir}/**/*.app`);
335+
} else {
336+
apps = glob.sync(`${caps.projectDir}/**/*.ipa`);
337+
}
338+
}
322339
}
323340

324341
if (!apps || apps.length === 0) {
325-
logError(`No 'app' capability provided or the convension for 'runType'${caps.runType} is not as excpeced!
342+
logError(`No 'app' capability provided or the convention for 'runType'${caps.runType} is not as expected!
326343
In order to automatically search and locate app package please use 'device' in your 'runType' name. E.g --runType device.iPhone7.iOS110, --runType sim.iPhone7.iOS110 or
327344
specify correct app path`);
328345
}
@@ -582,7 +599,7 @@ const convertObjToString = obj => {
582599
return "";
583600
}
584601

585-
export const shouldUserMobileDevicesController = (args: INsCapabilities)=>{
602+
export const shouldUserMobileDevicesController = (args: INsCapabilities) => {
586603
const useDsCS = process.env["USE_DEVICES_CONTROLLER_SERVER"] || false;
587604
const useMDsCS = process.env["USE_MOBILE_DEVICES_CONTROLLER_SERVER"] || false;
588605

postinstall.js

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ const run = async () => {
249249
switch (template.testingFramwork) {
250250
case jasmine:
251251
tsConfigJson.compilerOptions.types.push("jasmine");
252+
tsConfigJson.compilerOptions.types.push("node");
252253
break;
253254
case mocha:
254255
tsConfigJson.compilerOptions.types.push("mocha");

test-app/package.json

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
"readme": "NativeScript Application",
55
"repository": "<fill-your-repository-here>",
66
"devDependencies": {
7-
"typescript": "~2.5.1",
8-
"@types/chai": "^4.0.2",
9-
"@types/mocha": "^2.2.41",
10-
"@types/node": "^7.0.5",
11-
"babel-traverse": "6.25.0",
12-
"babel-types": "6.25.0",
13-
"babylon": "6.17.4",
14-
"chai": "~4.1.1",
15-
"chai-as-promised": "~7.1.1",
16-
"mocha": "~3.5.0",
17-
"mocha-junit-reporter": "^1.13.0",
18-
"mocha-multi": "^0.11.0",
19-
"mocha-typescript": "^1.1.9"
7+
"typescript": "~3.3.3",
8+
"@types/chai": "~4.1.7",
9+
"@types/mocha": "~5.2.5",
10+
"@types/node": "~10.12.18",
11+
"mocha": "~5.2.0",
12+
"mocha-junit-reporter": "~1.18.0",
13+
"mocha-multi": "~1.0.1"
2014
}
2115
}

0 commit comments

Comments
 (0)