-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use jest-resolve to resolve reporters
- Loading branch information
1 parent
8dec8ba
commit 19168b9
Showing
7 changed files
with
76 additions
and
21 deletions.
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
'use strict'; | ||
|
||
import type {InitialOptions} from 'types/Config'; | ||
import type {InitialOptions, ReporterConfig} from 'types/Config'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
aaronabramov
Author
Contributor
|
||
|
||
const { | ||
BULLET, | ||
|
@@ -20,7 +20,11 @@ const { | |
getTestEnvironment, | ||
resolve, | ||
} = require('./utils'); | ||
const {NODE_MODULES, DEFAULT_JS_PATTERN} = require('./constants'); | ||
const { | ||
NODE_MODULES, | ||
DEFAULT_JS_PATTERN, | ||
DEFAULT_REPORTER_LABEL, | ||
} = require('./constants'); | ||
const {validateReporters} = require('./reporterValidationErrors'); | ||
const {ValidationError, validate} = require('jest-validate'); | ||
const chalk = require('chalk'); | ||
|
@@ -249,17 +253,59 @@ const normalizeArgv = (options: InitialOptions, argv: Object) => { | |
} | ||
}; | ||
|
||
const normalizeReporters = (options: InitialOptions, basedir) => { | ||
if (options.reporters && Array.isArray(options.reporters)) { | ||
validateReporters(options.reporters); | ||
|
||
if (!options.reporters) { | ||
This comment has been minimized.
Sorry, something went wrong.
thymikee
Collaborator
|
||
return options; | ||
} | ||
|
||
options.reporters = options.reporters.map(reporterConfig => { | ||
const normalizedReporterConfig: ReporterConfig = typeof reporterConfig === | ||
'string' | ||
? // if reporter config is a string, we wrap it in an array | ||
// and pass an empty object for options argument, to make | ||
// them have the same shape. | ||
[reporterConfig, {}] | ||
: reporterConfig; | ||
|
||
const reporterPath = _replaceRootDirInPath( | ||
options.rootDir, | ||
normalizedReporterConfig[0], | ||
); | ||
|
||
if (reporterPath !== DEFAULT_REPORTER_LABEL) { | ||
const resolvedReporterPath = Resolver.findNodeModule(reporterPath, { | ||
basedir: options.rootDir, | ||
}); | ||
|
||
if (!resolvedReporterPath) { | ||
throw new Error( | ||
` | ||
Could not resolve a module for a custom reporter. | ||
moduleName: ${reporterPath} | ||
`, | ||
); | ||
} | ||
|
||
normalizedReporterConfig[0] = resolvedReporterPath; | ||
} | ||
return normalizedReporterConfig; | ||
}); | ||
} | ||
|
||
return options; | ||
}; | ||
|
||
function normalize(options: InitialOptions, argv: Object = {}) { | ||
const {hasDeprecationWarnings} = validate(options, { | ||
comment: DOCUMENTATION_NOTE, | ||
deprecatedConfig: DEPRECATED_CONFIG, | ||
exampleConfig: VALID_CONFIG, | ||
}); | ||
|
||
if (options.reporters && Array.isArray(options.reporters)) { | ||
validateReporters(options.reporters); | ||
} | ||
|
||
normalizeReporters(options); | ||
normalizePreprocessor(options); | ||
normalizeRootDir(options); | ||
normalizeMissingOptions(options); | ||
|
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
Shouldn't this land in
types/Reporters
?