* Load config from a file. * If js file provided: require it and get .config key * If json file provided: load and parse JSON * If directory provided: * * try to load `codecept.config.js` from it * * try to load `codecept.conf.js` from it * * try to load `codecept.js` from it *
(configFile)
| 90 | * @return {*} |
| 91 | */ |
| 92 | static async load(configFile) { |
| 93 | configFile = path.resolve(configFile || '.') |
| 94 | |
| 95 | if (!fileExists(configFile)) { |
| 96 | // Try different extensions if the file doesn't exist |
| 97 | const extensions = ['.ts', '.cjs', '.mjs'] |
| 98 | let found = false |
| 99 | |
| 100 | for (const ext of extensions) { |
| 101 | const altConfig = configFile.replace(/\.js$/, ext) |
| 102 | if (fileExists(altConfig)) { |
| 103 | configFile = altConfig |
| 104 | found = true |
| 105 | break |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (!found) { |
| 110 | throw new Error(`Config file ${configFile} does not exist. Execute 'codeceptjs init' to create config`) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // is config file |
| 115 | if (isFile(configFile)) { |
| 116 | return await loadConfigFile(configFile) |
| 117 | } |
| 118 | |
| 119 | for (const name of configFileNames) { |
| 120 | // is path to directory |
| 121 | const jsConfig = path.join(configFile, name) |
| 122 | |
| 123 | if (isFile(jsConfig)) { |
| 124 | return await loadConfigFile(jsConfig) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | const configPaths = configFileNames.map(name => path.join(configFile, name)).join(' or ') |
| 129 | |
| 130 | throw new Error(`Can not load config from ${configPaths}\nCodeceptJS is not initialized in this dir. Execute 'codeceptjs init' to start`) |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Get current config. |
no test coverage detected