Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add try/catch to avoid error by pullApk in pushString #430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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