| 8 | } |
| 9 | |
| 10 | function loadProjectConfig (command, options, config) { |
| 11 | // TEST REPORT FILE NAME |
| 12 | const customTestReportFileName = options && (options.testReportFileName || null); |
| 13 | if (customTestReportFileName) { |
| 14 | config.testReportFileName = options.testReportFileName || null; |
| 15 | } |
| 16 | |
| 17 | let customConfigPath = options && (options.backstopConfigFilePath || options.configPath); |
| 18 | if (options && typeof options.config === 'string' && !customConfigPath) { |
| 19 | customConfigPath = options.config; |
| 20 | } |
| 21 | |
| 22 | if (customConfigPath) { |
| 23 | if (path.isAbsolute(customConfigPath)) { |
| 24 | config.backstopConfigFileName = customConfigPath; |
| 25 | } else { |
| 26 | config.backstopConfigFileName = path.join(config.projectPath, customConfigPath); |
| 27 | } |
| 28 | } else { |
| 29 | config.backstopConfigFileName = path.join(config.projectPath, 'backstop.json'); |
| 30 | } |
| 31 | |
| 32 | let userConfig = {}; |
| 33 | const CMD_REQUIRES_CONFIG = !NON_CONFIG_COMMANDS.includes(command); |
| 34 | if (CMD_REQUIRES_CONFIG) { |
| 35 | // This flow is confusing -- is checking for !config.backstopConfigFileName more reliable? |
| 36 | if (options && typeof options.config === 'object' && options.config.scenarios) { |
| 37 | console.log('Object-literal config detected.'); |
| 38 | if (options.config.debug) { |
| 39 | console.log(JSON.stringify(options.config, null, 2)); |
| 40 | } |
| 41 | userConfig = options.config; |
| 42 | } else if (config.backstopConfigFileName) { |
| 43 | // Remove from cache config content |
| 44 | delete require.cache[require.resolve(config.backstopConfigFileName)]; |
| 45 | console.log('Loading config: ', config.backstopConfigFileName, '\n'); |
| 46 | userConfig = require(config.backstopConfigFileName); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return userConfig; |
| 51 | } |
| 52 | |
| 53 | function makeConfig (command, options) { |
| 54 | const config = {}; |