Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham committed Apr 2, 2018
1 parent 4a319ca commit a9cb84c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
37 changes: 20 additions & 17 deletions lib/android-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,18 @@ helpers.installApk = async function (adb, opts = {}) {
* @param {Object} opts Opts defined in driver.js
*/
helpers.installOtherApks = async function (otherApps, adb, opts) {
let {androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT,
autoGrantPermissions} = opts;
let {
androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT,
autoGrantPermissions
} = opts;

// Install all of the APK's asynchronously
await B.all(otherApps.map((otherApp) => {
logger.debug(`Installing app: ${otherApp}`);
return adb.install(otherApp, {
grantPermissions: autoGrantPermissions,
timeout: androidInstallTimeout,
"-r": true,
replace: true,
});
}));
};
Expand Down Expand Up @@ -584,21 +586,22 @@ helpers.removeAllSessionWebSocketHandlers = async function (server, sessionId) {
}
};

helpers.parseArray = function (cap) {
// If it's a string, try parsing as an object/array
if (_.isString(cap)) {
let parsedCaps;
try {
parsedCaps = JSON.parse(cap);
} catch (ign) { }
/**
* Takes a desired capability and tries to JSON.parse it as an array,
* and either returns the parsed array or a singleton array.
*
* @param {any} cap A desired capability
*/
helpers.parseArray = function (cap) {
let parsedCaps;
try {
parsedCaps = JSON.parse(cap);
} catch (ign) { }

if (_.isArray(parsedCaps)) {
return parsedCaps;
} else if (_.isPlainObject(parsedCaps)) {
throw new Error(`must provide a string or JSON array; received ${cap}`);
} else {
return [cap];
}
if (_.isArray(parsedCaps)) {
return parsedCaps;
} else if (_.isString(cap)) {
return [cap];
}

throw new Error(`must provide a string or JSON Array; received ${cap}`);
Expand Down
12 changes: 4 additions & 8 deletions test/unit/android-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ describe('Android Helpers', function () {
}));
describe('installOtherApks', withMocks({adb, fs, helpers}, function (mocks) {
const opts = {
app : 'local',
appPackage : 'pkg',
androidInstallTimeout : 90000
app: 'local',
appPackage: 'pkg',
androidInstallTimeout: 90000
};

const fakeApk = '/path/to/fake/app.apk';
Expand All @@ -405,7 +405,7 @@ describe('Android Helpers', function () {
const expectedADBInstallOpts = {
grantPermissions: undefined,
timeout: opts.androidInstallTimeout,
"-r": true,
replace: true,
};

it('should not call adb.install if otherApps is empty', async function () {
Expand Down Expand Up @@ -695,9 +695,5 @@ describe('Android Helpers', function () {
it('should parse a simple string to one item array', function () {
helpers.parseArray('abc').should.eql(['abc']);
});
it('should reject if an Object is provided', function () {
(() => helpers.parseArray('{"hello": "world"}')).should.throw(/s/);
//(() => helpers.parseArray('{"hello": "world"}'))().should.throw(/must provide a/);
});
});
});

0 comments on commit a9cb84c

Please sign in to comment.