Skip to content

Commit 6b67141

Browse files
feat: add js-samples (#148)
* feat: add js-samples
1 parent bcf6434 commit 6b67141

20 files changed

+251
-68
lines changed

.npmignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/**/*.ts
33
/**/*.map
44
!/**/*.d.ts
5-
e2e/reports
6-
e2e/**/*.js
7-
!e2e/*.ts
8-
!e2e/tsconfig.json
5+
samples/reports
6+
samples/e2e-tsc/*.js
7+
!samples/e2e-tsc/*.ts
8+
!samples/e2e-tsc/tsconfig.json
99
publish-next.js
1010
test-app
1111
.vscode

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"**/.hg": true,
88
"**/CVS": true,
99
"**/.DS_Store": true,
10-
"**/*.js": true,
10+
"/lib/**/*.js": true,
11+
"/bin/**/*.js": true,
12+
"samples/e2e-js/*.js": false,
1113
"**/*.map": true,
1214
"**/*.d.ts": true,
1315
"postinstall.js": false

lib/device-manager.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { INsCapabilities } from "./interfaces/ns-capabilities";
22
import { IDeviceManager } from "./interfaces/device-manager";
3-
import { IDevice, DeviceType } from "mobile-devices-controller";
3+
import { IDevice, Device, DeviceType } from "mobile-devices-controller";
44
export declare class DeviceManager implements IDeviceManager {
55
private static _emulators;
66
constructor();
@@ -9,7 +9,7 @@ export declare class DeviceManager implements IDeviceManager {
99
installApp(args: INsCapabilities): Promise<any>;
1010
uninstallApp(args: INsCapabilities): Promise<any>;
1111
static kill(device: IDevice): Promise<void>;
12-
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): any;
12+
static getDefaultDevice(args: INsCapabilities, deviceName?: string, token?: string, type?: DeviceType, platformVersion?: number): Device;
1313
static setDontKeepActivities(args: INsCapabilities, driver: any, value: any): Promise<void>;
1414
static executeShellCommand(driver: any, commandAndargs: {
1515
command: string;

lib/image-helper.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export declare class ImageHelper {
1010
blockOutAreas: IRectangle[];
1111
imageOutputLimit(): ImageOptions;
1212
thresholdType(): ImageOptions;
13-
threshold(thresholdType: any): 10 | 0.01;
13+
threshold(thresholdType: any): 0.01 | 10;
1414
delta(): number;
1515
static cropImageDefault(_args: INsCapabilities): {
1616
x: number;

lib/ns-capabilities.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { INsCapabilities } from "./interfaces/ns-capabilities";
22
import { INsCapabilitiesArgs } from "./interfaces/ns-capabilities-args";
33
import { AutomationName } from "./automation-name";
44
import { resolveCapabilities } from "./capabilities-helper";
5-
import { getAppPath, fileExists, logInfo, logError } from "./utils";
5+
import { getAppPath, fileExists, logInfo, logError, logWarn } from "./utils";
66
import { IDevice } from "mobile-devices-controller";
77
import { IDeviceManager } from "./interfaces/device-manager";
88

@@ -146,13 +146,13 @@ export class NsCapabilities implements INsCapabilities {
146146
if (this._ignoreDeviceController) {
147147
this.appiumCaps["fullReset"] = true;
148148
this.appiumCaps["noReset"] = false;
149-
console.log("Changing appium setting fullReset: true and noReset: false ");
149+
logInfo("Changing appium setting fullReset: true and noReset: false ");
150150
}
151151

152152
if (this._attachToDebug || this._devMode) {
153153
this.appiumCaps["fullReset"] = false;
154154
this.appiumCaps["noReset"] = true;
155-
console.log("Changing appium setting fullReset: false and noReset: true ");
155+
logInfo("Changing appium setting fullReset: false and noReset: true ");
156156
}
157157
}
158158

@@ -194,23 +194,25 @@ export class NsCapabilities implements INsCapabilities {
194194
}
195195

196196
private resolveApplication() {
197-
if (this.isSauceLab) {
198-
if (this.appPath){
199-
if (this.appPath.startsWith("http")){
200-
this._appiumCaps.app = this.appPath;
201-
} else {
202-
this._appiumCaps.app = `sauce-storage:${this.appPath}`;
203-
}
204-
} else if (!this._appiumCaps.app){
205-
throw new Error("Neither appPath option nor capabilities.app provided!!!");
197+
if (this._isSauceLab) {
198+
if (this._appPath) {
199+
this._appiumCaps.app = this._appPath.startsWith("http") ? this._appPath : `sauce-storage:${this._appPath}`;
200+
}
201+
202+
if (!this._appiumCaps.app) {
203+
const errorMsg = "Neither appPath option nor capabilities.app provided!!!";
204+
logError(errorMsg);
205+
throw new Error(errorMsg);
206206
}
207-
207+
208+
this._appPath = this._appiumCaps.app;
208209
this._ignoreDeviceController = true;
209-
console.log("Using Sauce Labs. The application path is changed to: " + this._appiumCaps.app);
210+
logInfo(`Using Sauce Labs. The application path is changed to: ${this._appiumCaps.app}`);
210211
} else {
211-
this.appiumCaps.app = getAppPath(this);
212+
this._appiumCaps.app = getAppPath(this);
212213
this._appPath = this._appiumCaps.app;
213-
console.log("Application full path: " + this._appiumCaps.app);
214+
215+
logInfo(`Application full path: ${this._appiumCaps.app}`);
214216
}
215217
}
216218

@@ -230,7 +232,7 @@ export class NsCapabilities implements INsCapabilities {
230232
}
231233

232234
if (!this._appiumCaps.platformVersion) {
233-
console.warn("Platform version is missing! You'd better to set it in order to use the correct device");
235+
logWarn("Platform version is missing! You'd better to set it in order to use the correct device");
234236
}
235237

236238
if (!this._appiumCaps.deviceName && !this._appiumCaps.udid) {

lib/ui-element.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ export class UIElement {
2323
return await (await this.element()).click();
2424
}
2525

26-
/**
27-
* Click a point by providing coordinates
28-
* @param x
29-
* @param y
30-
*/
3126
public async tapCenter() {
3227
let action = new this._wd.TouchAction(this._driver);
3328
const rect = await this.getActualRectangle();

lib/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ export const getRegexResultsAsArray = (regex, str) => {
307307
}
308308

309309
function getAppName(args: INsCapabilities) {
310-
const appLocation = args.appPath || args.appiumCaps.app;
311-
const appName = args.appName || appLocation
312-
.substring(appLocation.lastIndexOf("/") + 1, appLocation.lastIndexOf("."))
310+
const appName = args.appName || path.basename(args.appPath)
311+
.replace(path.extname(args.appPath), "")
313312
.replace("-release", "").replace("-debug", "");
314313

315314
return appName;
@@ -557,6 +556,7 @@ export const prepareApp = async (args: INsCapabilities) => {
557556
args.appName = groupings[groupings.length - 1];
558557
console.log(`Setting application name as ${args.appName}`);
559558
if (!args.devMode && !args.ignoreDeviceController) {
559+
logInfo("Check and uninstall application from device.");
560560
await args.deviceManager.uninstallApp(args);
561561
} else {
562562
args.appiumCaps.app = "";

postinstall.js

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
#!/usr/bin/env node
22

3-
const { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } = require("fs");
3+
const {
4+
existsSync,
5+
mkdirSync,
6+
readdirSync,
7+
readFileSync,
8+
statSync,
9+
writeFileSync
10+
} = require("fs");
411
const { basename, resolve } = require("path");
5-
6-
const appRootPath = require('app-root-path').toString();
712
const childProcess = require("child_process");
13+
const appRootPath = require('app-root-path').toString();
14+
15+
const sampleTestsFolder = "samples";
816
const e2eTests = "e2e";
9-
const e2eProjectFolderPath = resolve(appRootPath, e2eTests);
10-
const e2ePluginFolderPath = resolve(appRootPath, "node_modules", "nativescript-dev-appium", "e2e");
17+
const sampleTestsProjectFolderPath = resolve(appRootPath, e2eTests);
18+
const sampleTestsPluginFolderPath = resolve(appRootPath, "node_modules", "nativescript-dev-appium", sampleTestsFolder);
1119
const packageJsonPath = resolve(appRootPath, "package.json");
1220
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
21+
1322
const isTypeScriptProject =
14-
(
15-
packageJson.dependencies &&
16-
packageJson.dependencies.hasOwnProperty("typescript")
17-
) || (
18-
packageJson.devDependencies &&
19-
packageJson.devDependencies.hasOwnProperty("typescript")
20-
);
23+
(packageJson.dependencies && packageJson.dependencies.hasOwnProperty("typescript"))
24+
|| (packageJson.devDependencies && packageJson.devDependencies.hasOwnProperty("typescript"));
2125
const isWin = /^win/.test(process.platform);
2226

23-
function executeNpmInstall(cwd) {
27+
const executeNpmInstall = cwd => {
2428
let spawnArgs = [];
2529
let command = "";
2630
if (isWin) {
@@ -33,7 +37,7 @@ function executeNpmInstall(cwd) {
3337
childProcess.spawnSync(command, spawnArgs, { cwd, stdio: "inherit" });
3438
}
3539

36-
function copy(src, dest) {
40+
const copy = (src, dest) => {
3741
if (!existsSync(src)) {
3842
return Error("Source doesn't exist: " + src);
3943
}
@@ -57,25 +61,24 @@ function copy(src, dest) {
5761
}
5862
}
5963

60-
function getDevDependencies() {
64+
const getDevDependencies = () => {
6165
// These are nativescript-dev-appium plugin's dependencies.
6266
// There is NO need to explicitly install them to the project.
6367
// const requiredDevDependencies = [
6468
// { name: "chai", version: "~4.1.1" },
6569
// { name: "chai-as-promised", version: "~7.1.1" },
66-
// { name: "mocha", version: "~3.5.0" },
70+
// { name: "mocha", version: "~5.2.0" },
6771
// { name: "mocha-junit-reporter", version: "^1.13.0" },
68-
// { name: "mocha-multi", version: "^0.11.0" },
72+
// { name: "mocha-multi", version: "^1.0.1" },
6973
// ];
7074

7175
// These are nativescript-dev-appium plugin's devDependencies.
7276
// There is need to explicitly install them to the project.
73-
const typeScriptDevDependencies = [
74-
//{ name: "tslib", version: "^1.7.1" },
75-
{ name: "@types/chai", version: "~4.1.3" },
76-
{ name: "@types/mocha", version: "~5.2.1" },
77-
{ name: "@types/node", version: "^7.0.5" },
78-
];
77+
// const typeScriptDevDependencies = [
78+
// { name: "@types/chai", version: "~4.1.3" },
79+
// { name: "@types/mocha", version: "~5.2.1" },
80+
// { name: "@types/node", version: "^7.0.5" },
81+
// ];
7982

8083
// return isTypeScriptProject ?
8184
// [
@@ -84,10 +87,15 @@ function getDevDependencies() {
8487
// ] :
8588
// requiredDevDependencies;
8689

87-
return typeScriptDevDependencies;
90+
return !isTypeScriptProject ? [] :
91+
[
92+
{ name: "@types/chai", version: "~4.1.3" },
93+
{ name: "@types/mocha", version: "~5.2.1" },
94+
{ name: "@types/node", version: "^7.0.5" },
95+
];
8896
}
8997

90-
function configureDevDependencies(packageJson) {
98+
const configureDevDependencies = packageJson => {
9199
if (!packageJson.devDependencies) {
92100
packageJson.devDependencies = {};
93101
}
@@ -100,13 +108,13 @@ function configureDevDependencies(packageJson) {
100108
if (devDependenciesToInstall.length) {
101109
console.info("Installing new devDependencies ...");
102110
// Execute `npm install` after everything else
103-
setTimeout(function() {
111+
setTimeout(function () {
104112
executeNpmInstall(appRootPath);
105113
}, 300);
106114
}
107115
}
108116

109-
function updatePackageJsonDependencies(packageJson, isTypeScriptProject) {
117+
const updatePackageJsonDependencies = (packageJson, isTypeScriptProject) => {
110118
if (!packageJson.scripts) {
111119
packageJson.scripts = {};
112120
}
@@ -126,14 +134,19 @@ function updatePackageJsonDependencies(packageJson, isTypeScriptProject) {
126134

127135
if (basename(appRootPath) !== "nativescript-dev-appium") {
128136
updatePackageJsonDependencies(packageJson, isTypeScriptProject);
129-
if (!existsSync(e2eProjectFolderPath)) {
130-
mkdirSync(e2eProjectFolderPath);
137+
if (!existsSync(sampleTestsProjectFolderPath)) {
138+
mkdirSync(sampleTestsProjectFolderPath);
131139
if (isTypeScriptProject) {
132-
console.info("TypeScript project - adding sample config and test ...");
133-
console.info("Copying " + e2ePluginFolderPath + " to " + e2eProjectFolderPath + " ...");
134-
copy(e2ePluginFolderPath, e2eProjectFolderPath);
140+
console.info(`TypeScript project - adding sample config and test ...`);
141+
const tscSampleTestsPath = resolve(sampleTestsPluginFolderPath, "e2e-tsc")
142+
console.info(`Copying ${tscSampleTestsPath} to ${sampleTestsProjectFolderPath} ...`);
143+
copy(tscSampleTestsPath, sampleTestsProjectFolderPath);
135144
} else {
136-
console.info("JavaScript project - not adding sample config and test ...");
145+
const jsSampleTestsPath = resolve(sampleTestsPluginFolderPath, "e2e-js")
146+
console.info("JavaScript project - adding sample config and test ...");
147+
console.info(`Copying ${jsSampleTestsPath} to ${sampleTestsProjectFolderPath} ...`);
148+
copy(jsSampleTestsPath, sampleTestsProjectFolderPath);
137149
}
138150
}
139-
}
151+
}
152+
File renamed without changes.

0 commit comments

Comments
 (0)