From 9f5311812cbae5122ce2c6ebe522132273b0ebcc Mon Sep 17 00:00:00 2001 From: Julie Date: Wed, 4 Sep 2013 17:06:49 -0700 Subject: [PATCH] Improving the command line interface (adding more options). This allows the --spec option to be passed with test files that will be resolved relative to the current directory. Smarter merging of default config values. Closes #65. --- lib/cli.js | 65 ++++++++++++++++++++++++++++++++++++++++------- spec/basicConf.js | 9 +------ 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 2522be5ca..8a8c4bd91 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -11,6 +11,16 @@ var glob = require('glob'); var args = process.argv.slice(2); var configDir; +var merge = function(into, from) { + for (key in from) { + if (into[key] instanceof Object) { + merge(into[key], from[key]); + } else { + into[key] = from[key]; + } + } +}; + // Default configuration. var config = { seleniumServerJar: null, @@ -22,7 +32,6 @@ var config = { }, rootElement: 'body', jasmineNodeOpts: { - specs: [], isVerbose: false, showColors: true, includeStackTrace: true @@ -70,6 +79,8 @@ var printVersion = function () { }; var run = function() { + util.puts(util.inspect(config)); + process.exit(0); if (config.jasmineNodeOpts.specFolders) { throw new Error('Using config.jasmineNodeOpts.specFolders is deprecated ' + 'in Protractor 0.6.0. Please switch to config.specs.'); @@ -160,13 +171,20 @@ if (!args.length) { util.puts('USAGE: protractor configFile [options]'); util.puts('Options:'); util.puts(' --version: Print Protractor version'); - util.puts(' --seleniumAddress: A running selenium address to use'); - util.puts(' --seleniumServerJar: Location of the standalone selenium server .jar file'); - util.puts(' --seleniumPort: Optional port for the standalone selenium server'); + util.puts(' --seleniumAddress : A running selenium address to use'); + util.puts(' --seleniumServerJar : Location of the standalone selenium server .jar file'); + util.puts(' --seleniumPort : Optional port for the standalone selenium server'); + util.puts(' --baseUrl : URL to prepend to all relative paths'); + util.puts(' --rootElement : Element housing ng-app, if not html or body'); + util.puts(' --specs : Comma separated list of files to test'); + util.puts(' --[no]includeStackTrace: Print stack trace on error'); + util.puts(' --verbose: Print full spec names'); process.exit(0); } +var commandLineConfig = { capabilities: {}, jasmineNodeOpts: {}}; + while(args.length) { var arg = args.shift(); switch(arg) { @@ -174,20 +192,49 @@ while(args.length) { printVersion(); break; case '--browser': - config.capabilities.browserName = args.shift(); + commandLineConfig.capabilities.browserName = args.shift(); break; case '--seleniumAddress': - config.seleniumAddress = args.shift(); + commandLineConfig.seleniumAddress = args.shift(); break; case '--seleniumServerJar': - config.seleniumServerJar = args.shift(); + commandLineConfig.seleniumServerJar = args.shift(); break; case '--seleniumPort': - config.seleniumPort = args.shift(); + commandLineConfig.seleniumPort = args.shift(); + break; + case '--sauceUser': + commandLineConfig.sauceUser = args.shift(); + break; + case '--sauceKey': + commandLineConfig.sauceKey = args.shift(); + break; + case '--baseUrl': + commandLineConfig.baseUrl = args.shift(); + break; + case '--rootElement': + commandLineConfig.rootElement = args.shift(); + break; + case '--specs': + commandLineSpecs = args.shift().split(','); + commandLineSpecs.forEach(function(spec, index, arr) { + arr[index] = path.resolve(process.cwd(), spec); + }); + commandLineConfig.specs = commandLineSpecs; + break; + case '--includeStackTrace': + commandLineConfig.jasmineNodeOpts.includeStackTrace = true; + break; + case '--noincludeStackTrace': + commandLineConfig.jasmineNodeOpts.includeStackTrace = false; + break; + case '--verbose': + commandLineConfig.jasmineNodeOpts.isVerbose = true; break; default: var configPath = path.resolve(process.cwd(), arg); - config = require(configPath).config; + merge(config, require(configPath).config); + merge (config, commandLineConfig); configDir = path.dirname(configPath); break; } diff --git a/spec/basicConf.js b/spec/basicConf.js index 9d74b3305..0c5ef5383 100644 --- a/spec/basicConf.js +++ b/spec/basicConf.js @@ -7,7 +7,7 @@ exports.config = { // Spec patterns are relative to this directory. specs: [ - '*_spec.js', + '*_spec.js' ], capabilities: { @@ -15,11 +15,4 @@ exports.config = { }, baseUrl: 'http://localhost:8000', - - jasmineNodeOpts: { - onComplete: null, - isVerbose: false, - showColors: true, - includeStackTrace: true, - } };