Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 9f53118

Browse files
committed
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.
1 parent cfc6438 commit 9f53118

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

lib/cli.js

+56-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ var glob = require('glob');
1111
var args = process.argv.slice(2);
1212
var configDir;
1313

14+
var merge = function(into, from) {
15+
for (key in from) {
16+
if (into[key] instanceof Object) {
17+
merge(into[key], from[key]);
18+
} else {
19+
into[key] = from[key];
20+
}
21+
}
22+
};
23+
1424
// Default configuration.
1525
var config = {
1626
seleniumServerJar: null,
@@ -22,7 +32,6 @@ var config = {
2232
},
2333
rootElement: 'body',
2434
jasmineNodeOpts: {
25-
specs: [],
2635
isVerbose: false,
2736
showColors: true,
2837
includeStackTrace: true
@@ -70,6 +79,8 @@ var printVersion = function () {
7079
};
7180

7281
var run = function() {
82+
util.puts(util.inspect(config));
83+
process.exit(0);
7384
if (config.jasmineNodeOpts.specFolders) {
7485
throw new Error('Using config.jasmineNodeOpts.specFolders is deprecated ' +
7586
'in Protractor 0.6.0. Please switch to config.specs.');
@@ -160,34 +171,70 @@ if (!args.length) {
160171
util.puts('USAGE: protractor configFile [options]');
161172
util.puts('Options:');
162173
util.puts(' --version: Print Protractor version');
163-
util.puts(' --seleniumAddress: A running selenium address to use');
164-
util.puts(' --seleniumServerJar: Location of the standalone selenium server .jar file');
165-
util.puts(' --seleniumPort: Optional port for the standalone selenium server');
174+
util.puts(' --seleniumAddress <string>: A running selenium address to use');
175+
util.puts(' --seleniumServerJar <string>: Location of the standalone selenium server .jar file');
176+
util.puts(' --seleniumPort <string>: Optional port for the standalone selenium server');
177+
util.puts(' --baseUrl <string>: URL to prepend to all relative paths');
178+
util.puts(' --rootElement <string>: Element housing ng-app, if not html or body');
179+
util.puts(' --specs <list>: Comma separated list of files to test');
180+
util.puts(' --[no]includeStackTrace: Print stack trace on error');
181+
util.puts(' --verbose: Print full spec names');
166182

167183
process.exit(0);
168184
}
169185

186+
var commandLineConfig = { capabilities: {}, jasmineNodeOpts: {}};
187+
170188
while(args.length) {
171189
var arg = args.shift();
172190
switch(arg) {
173191
case '--version':
174192
printVersion();
175193
break;
176194
case '--browser':
177-
config.capabilities.browserName = args.shift();
195+
commandLineConfig.capabilities.browserName = args.shift();
178196
break;
179197
case '--seleniumAddress':
180-
config.seleniumAddress = args.shift();
198+
commandLineConfig.seleniumAddress = args.shift();
181199
break;
182200
case '--seleniumServerJar':
183-
config.seleniumServerJar = args.shift();
201+
commandLineConfig.seleniumServerJar = args.shift();
184202
break;
185203
case '--seleniumPort':
186-
config.seleniumPort = args.shift();
204+
commandLineConfig.seleniumPort = args.shift();
205+
break;
206+
case '--sauceUser':
207+
commandLineConfig.sauceUser = args.shift();
208+
break;
209+
case '--sauceKey':
210+
commandLineConfig.sauceKey = args.shift();
211+
break;
212+
case '--baseUrl':
213+
commandLineConfig.baseUrl = args.shift();
214+
break;
215+
case '--rootElement':
216+
commandLineConfig.rootElement = args.shift();
217+
break;
218+
case '--specs':
219+
commandLineSpecs = args.shift().split(',');
220+
commandLineSpecs.forEach(function(spec, index, arr) {
221+
arr[index] = path.resolve(process.cwd(), spec);
222+
});
223+
commandLineConfig.specs = commandLineSpecs;
224+
break;
225+
case '--includeStackTrace':
226+
commandLineConfig.jasmineNodeOpts.includeStackTrace = true;
227+
break;
228+
case '--noincludeStackTrace':
229+
commandLineConfig.jasmineNodeOpts.includeStackTrace = false;
230+
break;
231+
case '--verbose':
232+
commandLineConfig.jasmineNodeOpts.isVerbose = true;
187233
break;
188234
default:
189235
var configPath = path.resolve(process.cwd(), arg);
190-
config = require(configPath).config;
236+
merge(config, require(configPath).config);
237+
merge (config, commandLineConfig);
191238
configDir = path.dirname(configPath);
192239
break;
193240
}

spec/basicConf.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@ exports.config = {
77

88
// Spec patterns are relative to this directory.
99
specs: [
10-
'*_spec.js',
10+
'*_spec.js'
1111
],
1212

1313
capabilities: {
1414
'browserName': 'chrome'
1515
},
1616

1717
baseUrl: 'http://localhost:8000',
18-
19-
jasmineNodeOpts: {
20-
onComplete: null,
21-
isVerbose: false,
22-
showColors: true,
23-
includeStackTrace: true,
24-
}
2518
};

0 commit comments

Comments
 (0)