Skip to content

Commit

Permalink
Uses the resolver to resolve the other configuration values
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Apr 12, 2018
1 parent b80dc79 commit 0c620b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,17 @@ export default function normalize(options: InitialOptions, argv: Argv) {
const newOptions = Object.assign({}, DEFAULT_CONFIG);
// Cast back to exact type
options = (options: InitialOptions);

if (options.resolver) {
newOptions.resolver = resolve(null, options.rootDir, 'resolver', options.resolver);
}

Object.keys(options).reduce((newOptions, key) => {
// The resolver has been resolved separately; skip it
if (key === 'resolver') {
return newOptions;
}

let value;
switch (key) {
case 'collectCoverageOnlyFrom':
Expand All @@ -373,7 +383,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'snapshotSerializers':
value =
options[key] &&
options[key].map(resolve.bind(null, options.rootDir, key));
options[key].map(resolve.bind(null, newOptions.resolver, options.rootDir, key));
break;
case 'modulePaths':
case 'roots':
Expand Down Expand Up @@ -401,12 +411,11 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'globalSetup':
case 'globalTeardown':
case 'moduleLoader':
case 'resolver':
case 'runner':
case 'setupTestFrameworkScriptFile':
case 'testResultsProcessor':
case 'testRunner':
value = options[key] && resolve(options.rootDir, key, options[key]);
value = options[key] && resolve(newOptions.resolver, options.rootDir, key, options[key]);
break;
case 'moduleNameMapper':
const moduleNameMapper = options[key];
Expand All @@ -423,7 +432,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
transform &&
Object.keys(transform).map(regex => [
regex,
resolve(options.rootDir, key, transform[regex]),
resolve(newOptions.resolver, options.rootDir, key, transform[regex]),
]);
break;
case 'coveragePathIgnorePatterns':
Expand All @@ -438,6 +447,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
value = Object.assign({}, options[key]);
if (value.hasteImplModulePath != null) {
value.hasteImplModulePath = resolve(
newOptions.resolver,
options.rootDir,
'haste.hasteImplModulePath',
replaceRootDirInPath(options.rootDir, value.hasteImplModulePath),
Expand Down Expand Up @@ -520,7 +530,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
break;
case 'watchPlugins':
value = (options[key] || []).map(watchPlugin =>
resolve(options.rootDir, key, watchPlugin),
resolve(newOptions.resolver, options.rootDir, key, watchPlugin),
);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-config/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const createValidationError = (message: string) => {
);
};

export const resolve = (rootDir: string, key: string, filePath: Path) => {
export const resolve = (resolver: ?string, rootDir: string, key: string, filePath: Path) => {
const module = Resolver.findNodeModule(
replaceRootDirInPath(rootDir, filePath),
{
basedir: rootDir,
resolver,
},
);

Expand Down

0 comments on commit 0c620b6

Please sign in to comment.