-
-
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 all 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {readConfig} from '../index'; | ||
|
||
test('readConfig() throws when an object is passed without a file path', () => { | ||
expect(() => { | ||
readConfig( | ||
null /* argv */, | ||
{} /* packageRootOrConfig */, | ||
false /* skipArgvConfigOption */, | ||
null /* parentConfigPath */, | ||
); | ||
}).toThrowError( | ||
'Jest: Cannot use configuration as an object without a file path', | ||
); | ||
}); |
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,33 +8,52 @@ | |
*/ | ||
|
||
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 path from 'path'; | ||
import {isJSONString} from './utils'; | ||
import normalize from './normalize'; | ||
import resolveConfigPath from './resolve_config_path'; | ||
import readConfigFileAndSetRootDir from './read_config_file_and_set_root_dir'; | ||
|
||
function readConfig( | ||
export {getTestEnvironment, isJSONString} from './utils'; | ||
export {default as normalize} from './normalize'; | ||
|
||
export 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; | ||
|
||
// 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 = path.dirname(parentConfigPath); | ||
} else { | ||
throw new Error( | ||
'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 +64,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 +73,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); | ||
} | ||
|
||
|
@@ -166,10 +185,3 @@ const getConfigs = ( | |
}), | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
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 this on purpose? 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. Yes it is, you |
||
getTestEnvironment, | ||
isJSONString, | ||
normalize, | ||
readConfig, | ||
}; |
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.
Is there anywhere that requires a
configPath
to be set other thanreadConfigFileAndSetRootDir
?