Skip to content

Commit 3ab7745

Browse files
Lee EggebrotenJohn Doherty
authored andcommitted
Initial stab at adding a definable config file.
Looks in Node's working directory for the file "selenium-cucumber-js.json". If found, loads it and merges the definition into the pre-defined config. A possible improvement would be to load the default config file from the module root, providing an easy example to copy. However, it's probably just as easy to document the file in the README.md
1 parent 08e05d8 commit 3ab7745

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

index.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var fs = require('fs-plus');
34
var path = require('path');
45
var program = require('commander');
56
var pjson = require('./package.json');
@@ -10,21 +11,34 @@ function collectPaths(value, paths) {
1011
return paths;
1112
}
1213

14+
var config = {
15+
"step_def_dir": "./step-definitions",
16+
"page_obj_dir": "./page-objects",
17+
"shared_obj_dir": "./shared-objects",
18+
"reports_dir": "./reports",
19+
"default_browser": "chrome",
20+
"timeout": 10000
21+
};
22+
var configFileName = path.resolve(process.cwd(), 'selenium-cucumber-js.json');
23+
if (fs.isFileSync(configFileName)) {
24+
config = Object.assign(config, require(configFileName));
25+
}
26+
1327
program
14-
.version(pjson.version)
15-
.description(pjson.description)
16-
.option('-s, --steps <path>', 'path to step definitions. defaults to ./step-definitions', './step-definitions')
17-
.option('-p, --pageObjects <path>', 'path to page objects. defaults to ./page-objects', './page-objects')
18-
.option('-o, --sharedObjects [paths]', 'path to shared objects (repeatable). defaults to ./shared-objects', collectPaths, ['./shared-objects'])
19-
.option('-b, --browser <path>', 'name of browser to use. defaults to chrome', /^(chrome|firefox|phantomjs)$/i, 'chrome')
20-
.option('-r, --reports <path>', 'output path to save reports. defaults to ./reports', './reports')
21-
.option('-d, --disableLaunchReport [optional]', 'Disables the auto opening the browser with test report')
22-
.option('-j, --junit <path>', 'output path to save junit-report.xml defaults to ./reports')
23-
.option('-t, --tags <tagName>', 'name of tag to run')
24-
.option('-f, --featureFile <path>', 'a specific feature file to run')
25-
.option('-x, --timeOut <n>', 'steps definition timeout in milliseconds. defaults to 10 seconds', parseInt)
26-
.option('-n, --noScreenshot [optional]', 'disable auto capturing of screenshots when an error is encountered')
27-
.parse(process.argv);
28+
.version(pjson.version)
29+
.description(pjson.description)
30+
.option('-s, --steps <path>', 'path to step definitions. defaults to ' + config.step_def_dir, config.step_def_dir)
31+
.option('-p, --pageObjects <path>', 'path to page objects. defaults to ' + config.page_obj_dir, config.page_obj_dir)
32+
.option('-o, --sharedObjects [paths]', 'path to shared objects (repeatable). defaults to ' + config.shared_obj_dir, collectPaths, [config.shared_obj_dir])
33+
.option('-b, --browser <path>', 'name of browser to use. defaults to ' + config.default_browser, config.default_browser)
34+
.option('-r, --reports <path>', 'output path to save reports. defaults to ' + config.reports_dir, config.reports_dir)
35+
.option('-d, --disableLaunchReport [optional]', 'Disables the auto opening the browser with test report')
36+
.option('-j, --junit <path>', 'output path to save junit-report.xml defaults to ' + config.reports_dir)
37+
.option('-t, --tags <tagName>', 'name of tag to run')
38+
.option('-f, --featureFile <path>', 'a specific feature file to run')
39+
.option('-x, --timeOut <n>', 'steps definition timeout in milliseconds. defaults to ' + config.timeout, parseInt, config.timeout)
40+
.option('-n, --noScreenshot [optional]', 'disable auto capturing of screenshots when an error is encountered')
41+
.parse(process.argv);
2842

2943
program.on('--help', function() {
3044
console.log(' For more details please visit https://github.com/john-doherty/selenium-cucumber-js#readme\n');

0 commit comments

Comments
 (0)