Skip to content

Commit 8fa4721

Browse files
committed
added option to select config file
1 parent fa29574 commit 8fa4721

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

bin/codecept.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ program.command('run [suite] [test]')
5858
.option('--debug', 'output additional information')
5959
.option('--verbose', 'output internal logging information')
6060
.option('--profile [value]', 'configuration profile to be used')
61+
.option('--config [file]', 'configuration file to be used')
6162

6263
// mocha options
6364
.option('-c, --colors', 'force enabling of colors')

lib/command/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ let output = require('../output');
77
module.exports = function (suite, test, options) {
88
// registering options globally to use in config
99
process.profile = options.profile;
10+
let configfile = options.config;
1011

1112
let testRoot = getTestRoot(suite);
12-
let config = getConfig(testRoot);
13+
let config = getConfig(testRoot, configfile);
1314
try {
1415
let codecept = new Codecept(config, options);
1516
codecept.init(testRoot);

lib/command/utils.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,39 @@ module.exports.getTestRoot = function (currentPath) {
99
return testsPath;
1010
};
1111

12-
module.exports.getConfig = function (testRoot) {
12+
module.exports.getConfig = function (testRoot, configfile) {
1313

14-
let config,
15-
jsConfigFile = path.join(testRoot, 'codecept.conf.js'),
16-
jsConfigFileDeprecated = path.join(testRoot, 'codecept.js'),
17-
jsonConfigFile = path.join(testRoot, 'codecept.json');
14+
let config;
1815

19-
if (fileExists(jsConfigFile)) {
20-
config = require(jsConfigFile).config;
21-
} else if (fileExists(jsConfigFileDeprecated)) {
22-
console.log('Using codecept.js as configuration is deprecated, please rename it to codecept.conf.js');
23-
config = require(jsConfigFileDeprecated).config;
24-
} else if (fileExists(jsonConfigFile)) {
25-
config = JSON.parse(fs.readFileSync(jsonConfigFile, 'utf8'));
26-
} else {
27-
output.error(`Can not load config from ${jsConfigFile} or ${jsonConfigFile}\nCodeceptJS is not initialized in this dir. Execute 'codeceptjs init' to start`);
28-
process.exit(1);
16+
if(configfile){
17+
let manualConfigFile = path.resolve(configfile);
18+
if (fileExists(manualConfigFile)){
19+
if(path.extname(manualConfigFile) === '.js'){
20+
config = require(manualConfigFile).config;
21+
}else{
22+
config = JSON.parse(fs.readFileSync(manualConfigFile, 'utf8'));
23+
}
24+
}else{
25+
output.error(`Can not load config from ${manualConfigFile}: File does not exist.`);
26+
process.exit(1);
27+
}
28+
29+
}else{
30+
let jsConfigFile = path.join(testRoot, 'codecept.conf.js'),
31+
jsConfigFileDeprecated = path.join(testRoot, 'codecept.js'),
32+
jsonConfigFile = path.join(testRoot, 'codecept.json');
33+
34+
if (fileExists(jsConfigFile)) {
35+
config = require(jsConfigFile).config;
36+
} else if (fileExists(jsConfigFileDeprecated)) {
37+
console.log('Using codecept.js as configuration is deprecated, please rename it to codecept.conf.js');
38+
config = require(jsConfigFileDeprecated).config;
39+
} else if (fileExists(jsonConfigFile)) {
40+
config = JSON.parse(fs.readFileSync(jsonConfigFile, 'utf8'));
41+
} else {
42+
output.error(`Can not load config from ${jsConfigFile} or ${jsonConfigFile}\nCodeceptJS is not initialized in this dir. Execute 'codeceptjs init' to start`);
43+
process.exit(1);
44+
}
2945
}
3046

3147
if (!config.include) config.include = {};

0 commit comments

Comments
 (0)