-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Allow configuration object in projects array #5176
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d4e3b7
Allow configuration object in projects array
azz 0a4cf98
Add changelog
azz 75615e6
Fix type of packageRootOrConfig argument
azz fb2b4d4
Move along, nothing to see here...
azz 50d01f7
Change error message
azz b61f30e
Add unit test for readConfig()
azz b227bad
Remove unneeded ?
azz 3e4c825
Update integration tests
azz d91e999
Add documentation for runner and projects objects
azz c9d5fec
Add status code checks
azz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,12 @@ | |
*/ | ||
|
||
import type {Argv} from 'types/Argv'; | ||
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; | ||
import type { | ||
GlobalConfig, | ||
InitialOptions, | ||
Path, | ||
ProjectConfig, | ||
} from 'types/Config'; | ||
|
||
import {getTestEnvironment, isJSONString} from './utils'; | ||
import normalize from './normalize'; | ||
|
@@ -17,24 +22,34 @@ import readConfigFileAndSetRootDir from './read_config_file_and_set_root_dir'; | |
|
||
function readConfig( | ||
argv: Argv, | ||
packageRoot: string, | ||
packageRootOrConfig: Path | InitialOptions, | ||
// Whether it needs to look into `--config` arg passed to CLI. | ||
// It only used to read initial config. If the initial config contains | ||
// `project` property, we don't want to read `--config` value and rather | ||
// read individual configs for every project. | ||
skipArgvConfigOption?: boolean, | ||
parentConfigPath?: ?Path, | ||
): { | ||
configPath: ?Path, | ||
globalConfig: GlobalConfig, | ||
hasDeprecationWarnings: boolean, | ||
projectConfig: ProjectConfig, | ||
} { | ||
let rawOptions; | ||
let configPath; | ||
let configPath = null; | ||
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. Is there anywhere that requires a |
||
|
||
// A JSON string was passed to `--config` argument and we can parse it | ||
// and use as is. | ||
if (isJSONString(argv.config)) { | ||
if (typeof packageRootOrConfig !== 'string') { | ||
if (parentConfigPath) { | ||
rawOptions = packageRootOrConfig; | ||
rawOptions.rootDir = parentConfigPath; | ||
} else { | ||
throw new Error( | ||
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. can we have a test for this (mostly for coverage)? |
||
'Jest: Cannot use configuration as an object without a file path.', | ||
); | ||
} | ||
} else if (isJSONString(argv.config)) { | ||
// A JSON string was passed to `--config` argument and we can parse it | ||
// and use as is. | ||
let config; | ||
try { | ||
config = JSON.parse(argv.config); | ||
|
@@ -45,7 +60,7 @@ function readConfig( | |
} | ||
|
||
// NOTE: we might need to resolve this dir to an absolute path in the future | ||
config.rootDir = config.rootDir || packageRoot; | ||
config.rootDir = config.rootDir || packageRootOrConfig; | ||
rawOptions = config; | ||
// A string passed to `--config`, which is either a direct path to the config | ||
// or a path to directory containing `package.json` or `jest.conf.js` | ||
|
@@ -54,7 +69,7 @@ function readConfig( | |
rawOptions = readConfigFileAndSetRootDir(configPath); | ||
} else { | ||
// Otherwise just try to find config in the current rootDir. | ||
configPath = resolveConfigPath(packageRoot, process.cwd()); | ||
configPath = resolveConfigPath(packageRootOrConfig, process.cwd()); | ||
rawOptions = readConfigFileAndSetRootDir(configPath); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what does
?
on both sides mean? From my understandingname: ?type
allowsnull
,undefined
or a value, whilename?: type
allowsundefined
or a value.https://flow.org/en/docs/types/primitives/#toc-maybe-types
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'm not very proficient with Flow. I just added the
?
on the LHS to satisfy the checker. Maybe I can remove the one left, but the property is optional so I think I'll get an error when it's not explicitly passed.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.
Yeah, I think so 🙂
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.
Removing it worked.