Skip to content

Commit

Permalink
Merge 6854c48 into 803444d
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Sep 24, 2018
2 parents 803444d + 6854c48 commit 03dbf71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/android-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,12 @@ helpers.pushStrings = async function (language, adb, opts) {
// clean up remote string.json if present
await adb.rimraf(remoteFile);

const app = opts.app || await adb.pullApk(opts.appPackage, opts.tmpDir);
let app;
try {
app = opts.app || await adb.pullApk(opts.appPackage, opts.tmpDir);
} catch (err) {
logger.info(`Failed to pull an apk from '${opts.appPackage}' to '${opts.tmpDir}'. Original error: ${err.message}`);
}

if (_.isEmpty(opts.appPackage) || !(await fs.exists(app))) {
logger.debug(`No app or package specified. Returning empty strings`);
Expand Down
13 changes: 12 additions & 1 deletion test/unit/android-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,17 @@ describe('Android Helpers', function () {
});
}));
describe('pushStrings', withMocks({adb, fs}, (mocks) => {
const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};
it('should return {} because of no app, no package and no app in the target device', async function () {
const opts = {tmpDir: '/tmp_dir', appPackage: 'pkg'};
mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();
mocks.adb.expects('pullApk').withExactArgs(opts.appPackage, opts.tmpDir)
.throws(`adb: error: remote object ${opts.appPackage} does not exist`);
(await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({});
mocks.adb.verify();
mocks.fs.verify();
});
it('should extracts string.xml and converts it to string.json and pushes it', async function () {
const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};
mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();
mocks.fs.expects('exists').withExactArgs(opts.app).returns(true);
mocks.fs.expects('rimraf').once();
Expand All @@ -518,13 +527,15 @@ describe('Android Helpers', function () {
mocks.adb.verify();
});
it('should delete remote strings.json if app is not present', async function () {
const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};
mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();
mocks.fs.expects('exists').withExactArgs(opts.app).returns(false);
(await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({});
mocks.adb.verify();
mocks.fs.verify();
});
it('should push an empty json object if app does not have strings.xml', async function () {
const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};
mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();
mocks.fs.expects('exists').withExactArgs(opts.app).returns(true);
mocks.fs.expects('rimraf').once();
Expand Down

0 comments on commit 03dbf71

Please sign in to comment.