Skip to content

Commit

Permalink
Add warning for apppackage, appactivity and appwaitpackages (#371)
Browse files Browse the repository at this point in the history
* add warning for app

* add check in appwaitactivity

* apply reviews

* extract validation method

* use \w

* tweak arguments and warning messages

* combine validation methods
  • Loading branch information
KazuCocoa committed May 31, 2018
1 parent 63aaf5a commit a6ca8eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/android-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,32 @@ helpers.createADB = async function (opts = {}) {
return adb;
};

helpers.validatePackageActivityNames = function (opts) {
for (const key of ['appPackage', 'appActivity', 'appWaitPackage', 'appWaitActivity']) {
const name = opts[key];
if (!name) {
continue;
}

const match = /([^\w.*])+/.exec(name);
if (!match) {
continue;
}

logger.warn(`'${name}' is expected to only include latin letters, digits, underscore, dot and asterisk characters.`);
logger.warn(`'${name.substring(0, match.index + 1)}' <- the first non-matching character occurrence is at index ${match.index}.`);
}
};

helpers.getLaunchInfo = async function (adb, opts) {
let {app, appPackage, appActivity, appWaitPackage, appWaitActivity} = opts;
if (!app) {
logger.warn("No app sent in, not parsing package/activity");
return;
}

this.validatePackageActivityNames(opts);

if (appPackage && appActivity) {
return;
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/android-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,18 @@ describe('Android Helpers', function () {
appActivity: "act"});
mocks.adb.verify();
});
it('should print warn when all parameters are already present but the format is odd', async function () {
// It only prints warn message
mocks.adb.expects('packageAndLaunchActivityFromManifest').never();
await helpers.getLaunchInfo(adb, {app: "foo", appPackage: "bar ", appWaitPackage: "*", appActivity: "a_act", appWaitActivity: ". "});
mocks.adb.verify();
});
it('should print warn when appPackage & appActivity are already present but the format is odd', async function () {
// It only prints warn message
mocks.adb.expects('packageAndLaunchActivityFromManifest').never();
await helpers.getLaunchInfo(adb, {app: "foo", appPackage: "bar", appActivity: "a_act "});
mocks.adb.verify();
});
it('should return package and launch activity from manifest', async function () {
mocks.adb.expects('packageAndLaunchActivityFromManifest').withExactArgs('foo')
.returns({apkPackage: 'pkg', apkActivity: 'ack'});
Expand Down

0 comments on commit a6ca8eb

Please sign in to comment.