From 6f5a9d10017fd974ca4fef6a9c27d32bce783381 Mon Sep 17 00:00:00 2001 From: Dan Graham Date: Fri, 10 Feb 2017 10:38:04 -0800 Subject: [PATCH] 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' --- lib/parser.js | 3 ++- test/config-specs.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/parser.js b/lib/parser.js index 5ee9185c..d9dcfa10 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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; diff --git a/test/config-specs.js b/test/config-specs.js index 3c1335f3..ce9f398f 100644 --- a/test/config-specs.js +++ b/test/config-specs.js @@ -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?