Skip to content

Commit b121e8c

Browse files
committed
Enhance func pathsToESModuleNameMapper
- Modified the regex in the mappings to return a cleaner module mappings objects.
1 parent 9e8fdb4 commit b121e8c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

jest.config.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ function pathsToESModuleNameMapper() {
2121
const [key, val] = entry;
2222

2323
if (/.*\(\.\*\)\$$/.test(key)) {
24-
const convertedKey = `${key.substring(0, key.length - 1)}\\.js$`;
24+
// eslint-disable-next-line prefer-template
25+
const convertedKey = key.substring(0, key.length - 2)
26+
+ '[^\\.js])(\\.js)?$';
2527
esmMap[convertedKey] = val;
2628
}
27-
28-
esmMap[key] = val;
2929
});
3030

31+
// Append the mapping for relative paths without path alias.
32+
esmMap['^(\\.{1,2}/.*)\\.js$'] = '$1';
33+
3134
return esmMap;
3235
}
3336

0 commit comments

Comments
 (0)