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

Commit 74761e8

Browse files
committed
feat(cli): use protractor.conf.js as a default config file if none is passed
Closes #615
1 parent fca9c5f commit 74761e8

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/cli.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ process.argv.slice(2).forEach(function(arg) {
3131
var util = require('util');
3232
var path = require('path');
3333
var child = require('child_process');
34-
var argv = require('optimist').
34+
var fs = require('fs');
35+
var optimist = require('optimist').
3536
usage('Usage: protractor [options] [configFile]\n' +
37+
'configFile defaults to protractor.conf.js\n' +
3638
'The [options] object will override values from the config file.\n' +
3739
'See the reference config for a full list of options.').
3840
describe('help', 'Print Protractor help menu').
@@ -62,11 +64,9 @@ var argv = require('optimist').
6264
if (arg._.length > 1) {
6365
throw 'Error: more than one config file specified';
6466
}
65-
if (process.argv.length < 3 || arg.help) {
66-
throw '';
67-
}
68-
}).
69-
parse(args);
67+
});
68+
69+
var argv = optimist.parse(args);
7070

7171
if (argv.version) {
7272
util.puts('Version ' + require(path.join(__dirname, '../package.json')).version);
@@ -114,5 +114,17 @@ if (argv.excludes) {
114114
argv.excludes = processFilePatterns_(argv.excludes);
115115
}
116116

117+
// Use default configuration, if it exists.
118+
var configFile = argv._[0];
119+
if (!configFile) {
120+
if (fs.existsSync('./protractor.conf.js')) {
121+
configFile = './protractor.conf.js';
122+
}
123+
}
124+
if (!configFile && args.length < 3) {
125+
optimist.showHelp();
126+
process.exit(1);
127+
}
128+
117129
// Run the launcher
118-
require('./launcher').init(argv._[0], argv);
130+
require('./launcher').init(configFile, argv);

lib/launcher.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var init = function(configFile, additionalConfig) {
5353
launcherExitCode = 0;
5454

5555
var configParser = new ConfigParser();
56+
5657
if (configFile) {
5758
configParser.addFileConfig(configFile);
5859
}

0 commit comments

Comments
 (0)