Skip to content

Commit

Permalink
refactor(jest-config): mergeOptionWithPreset (#13190)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Aug 30, 2022
1 parent 132e815 commit 2b04388
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,16 @@ function verifyDirectoryExists(path: string, key: string) {
}
}

// TS 3.5 forces us to split these into 2
const mergeModuleNameMapperWithPreset = (
options: Config.InitialOptionsWithRootDir,
preset: Config.InitialOptions,
) => {
if (options['moduleNameMapper'] && preset['moduleNameMapper']) {
options['moduleNameMapper'] = {
...options['moduleNameMapper'],
...preset['moduleNameMapper'],
...options['moduleNameMapper'],
};
}
};

const mergeTransformWithPreset = (
options: Config.InitialOptionsWithRootDir,
const mergeOptionWithPreset = <T extends 'moduleNameMapper' | 'transform'>(
options: Config.InitialOptions,
preset: Config.InitialOptions,
optionName: T,
) => {
if (options['transform'] && preset['transform']) {
options['transform'] = {
...options['transform'],
...preset['transform'],
...options['transform'],
if (options[optionName] && preset[optionName]) {
options[optionName] = {
...options[optionName],
...preset[optionName],
...options[optionName],
};
}
};
Expand Down Expand Up @@ -206,8 +193,8 @@ const setupPreset = async (
options.modulePathIgnorePatterns,
);
}
mergeModuleNameMapperWithPreset(options, preset);
mergeTransformWithPreset(options, preset);
mergeOptionWithPreset(options, preset, 'moduleNameMapper');
mergeOptionWithPreset(options, preset, 'transform');
mergeGlobalsWithPreset(options, preset);

return {...preset, ...options};
Expand Down

0 comments on commit 2b04388

Please sign in to comment.