-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use any config files: backstop.json, backstop.js #1565
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,32 +1,44 @@ | ||||||
const path = require('path'); | ||||||
const fs = require('fs'); | ||||||
const extendConfig = require('./extendConfig'); | ||||||
const logger = require('../util/logger')('init'); | ||||||
|
||||||
const NON_CONFIG_COMMANDS = ['init', 'version', 'stop']; | ||||||
|
||||||
function projectPath (config) { | ||||||
function projectPath () { | ||||||
return process.cwd(); | ||||||
} | ||||||
|
||||||
function loadProjectConfig (command, options, config) { | ||||||
options = options || {}; // make sure options is an object | ||||||
|
||||||
// TEST REPORT FILE NAME | ||||||
const customTestReportFileName = options && (options.testReportFileName || null); | ||||||
if (customTestReportFileName) { | ||||||
config.testReportFileName = options.testReportFileName || null; | ||||||
if (options.testReportFileName) { | ||||||
config.testReportFileName = options.testReportFileName; | ||||||
} | ||||||
|
||||||
let customConfigPath = options && (options.backstopConfigFilePath || options.configPath); | ||||||
if (options && typeof options.config === 'string' && !customConfigPath) { | ||||||
customConfigPath = options.config; | ||||||
// list of "config" files to search for | ||||||
const configFiles = ['backstop.json', 'backstop.js']; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all four of these are valid options:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maxfenton Do you REALLY need the support I personally don't mind if we add them, still I don't see it necessary. @garris ? What do you say? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @klodoma I have a coworker who — today — said he prefers it on his projects because it’s more clear when looking at the root of a project what's a config file. I'd feel bad if I didn't at least make this suggestion for his sake and since it’s probably the default some other users have been using with the config flag. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it’s the default name in the documentation here: https://github.com/garris/BackstopJS?tab=readme-ov-file#working-with-your-config-file |
||||||
|
||||||
// If a config file is specified in the options, add it to the list | ||||||
if (options.config && typeof options.config === 'string') { | ||||||
configFiles.unshift(options.config); | ||||||
configFiles.unshift(path.join(config.projectPath, options.config)); | ||||||
} | ||||||
|
||||||
if (customConfigPath) { | ||||||
if (path.isAbsolute(customConfigPath)) { | ||||||
config.backstopConfigFileName = customConfigPath; | ||||||
} else { | ||||||
config.backstopConfigFileName = path.join(config.projectPath, customConfigPath); | ||||||
// Searching for the first existing config file | ||||||
for (const configFile of configFiles) { | ||||||
const configPath = path.join(config.projectPath, configFile); | ||||||
if (fs.existsSync(configPath)) { | ||||||
config.backstopConfigFileName = configPath; | ||||||
break; // Stop searching once a valid config file is found | ||||||
} | ||||||
} else { | ||||||
config.backstopConfigFileName = path.join(config.projectPath, 'backstop.json'); | ||||||
} | ||||||
|
||||||
if (!config.backstopConfigFileName) { | ||||||
logger.error('No config file found in project path: ' + config.projectPath); | ||||||
logger.error('Looked for: ' + configFiles.join(', ')); | ||||||
process.exit(1); | ||||||
} | ||||||
|
||||||
let userConfig = {}; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@klodoma @maxfenton @dgrebb
FWIW: if we change line 15 to
config: 'backstop'
then require() will resolve this as a.js
then ajson
file on its own. This would be the absolute simplest change. I don't think any other changes would be needed.What do you guys think? Would this solve the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, I didn't know that :) good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garris
Please have a look at this PR. I'll add more comments in the PR.
#1566
So probably we'll abandon this current PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test both today, but I think the docs on the new PR still suggest a
backstop.config.js
filename and I'm not clear if resolve will find a file with.config
in it.I do like that this PR makes it clear what filenames are allowed and what order of priority they would take.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this PR to be more elegant than v2 which adds a
useJs
flag that seems extraneous. I think the logic in this PR handles the case where someone has added both abackstop.js
andbackstop.json
in the directory (the json is used because of array priority) and this PR handles more filenames and shows the order of them more explicitly.That's just my opinion, but I'd vote for this PR over the other one, even though
resolve
can spot.json
and.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And I really appreciate the work in both PR's @klodoma!)