@@ -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