Skip to content
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

[WIP] Transformers as modules #7279

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ const setupBabelJest = (options: InitialOptions) => {

if (customJSPattern) {
const customJSTransformer = transform[customJSPattern];
const isModule = typeof customJSTransformer !== 'string';

if (customJSTransformer === 'babel-jest') {
babelJest = require.resolve('babel-jest');
transform[customJSPattern] = babelJest;
} else if (customJSTransformer.includes('babel-jest')) {
} else if (!isModule && customJSTransformer.includes('babel-jest')) {
babelJest = customJSTransformer;
}
}
Expand Down Expand Up @@ -514,14 +515,23 @@ export default function normalize(options: InitialOptions, argv: Argv) {
const transform = options[key];
value =
transform &&
Object.keys(transform).map(regex => [
regex,
resolve(newOptions.resolver, {
filePath: transform[regex],
key,
rootDir: options.rootDir,
}),
]);
Object.keys(transform).map(regex => {
const transformer = transform[regex];
const isModule = typeof transformer !== 'string';

/**
* Do not try to resolve a module.
*/
const module = isModule
? transformer
: resolve(newOptions.resolver, {
filePath: transform[regex],
key,
rootDir: options.rootDir,
});

return [regex, module];
});
break;
case 'coveragePathIgnorePatterns':
case 'modulePathIgnorePatterns':
Expand Down