Don't allow undefined process.argv[1] in parser

argParse breaks if process.argv[1], which is a problem if Appium is being run as a binary. Added check so that if process.argv[1] is undefined, set the prog name to 'Appium'
This commit is contained in:
Dan Graham 2017-02-10 10:38:04 -08:00
Родитель 56ebf37d16
Коммит 6f5a9d1001
2 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -782,7 +782,8 @@ function getParser () {
let parser = new ArgumentParser({
version: pkgObj.version,
addHelp: true,
description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.'
description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
prog: process.argv[1] || 'Appium'
});
let allArgs = _.union(args, deprecatedArgs);
parser.rawArgs = allArgs;

Просмотреть файл

@ -194,6 +194,30 @@ describe('Config', () => {
});
});
describe('parsing args with empty argv[1]', () => {
let argv1;
before(() => {
argv1 = process.argv[1];
});
after(() => {
process.argv[1] = argv1;
});
it('should not fail if process.argv[1] is undefined', () => {
process.argv[1] = undefined;
let args = getParser();
args.prog.should.be.equal('Appium');
});
it('should set "prog" to process.argv[1]', () => {
process.argv[1] = 'Hello World';
let args = getParser();
args.prog.should.be.equal('Hello World');
});
});
describe('validateServerArgs', () => {
let parser = getParser();
parser.debug = true; // throw instead of exit on error; pass as option instead?