@@ -40,12 +40,14 @@ const resolveWithPrefix = (
4040 humanOptionName,
4141 optionName,
4242 prefix,
43+ requireResolveFunction,
4344 rootDir,
4445 } : {
4546 filePath : string ;
4647 humanOptionName : string ;
4748 optionName : string ;
4849 prefix : string ;
50+ requireResolveFunction : ( moduleName : string ) => string ;
4951 rootDir : Config . Path ;
5052 } ,
5153) : string => {
@@ -59,7 +61,7 @@ const resolveWithPrefix = (
5961 }
6062
6163 try {
62- return require . resolve ( `${ prefix } ${ fileName } ` ) ;
64+ return requireResolveFunction ( `${ prefix } ${ fileName } ` ) ;
6365 } catch { }
6466
6567 module = Resolver . findNodeModule ( fileName , {
@@ -71,7 +73,7 @@ const resolveWithPrefix = (
7173 }
7274
7375 try {
74- return require . resolve ( fileName ) ;
76+ return requireResolveFunction ( fileName ) ;
7577 } catch { }
7678
7779 throw createValidationError (
@@ -94,15 +96,19 @@ const resolveWithPrefix = (
9496export const resolveTestEnvironment = ( {
9597 rootDir,
9698 testEnvironment : filePath ,
99+ // TODO: remove default in Jest 28
100+ requireResolveFunction = require . resolve ,
97101} : {
98102 rootDir : Config . Path ;
99103 testEnvironment : string ;
104+ requireResolveFunction ?: ( moduleName : string ) => string ;
100105} ) : string =>
101106 resolveWithPrefix ( undefined , {
102107 filePath,
103108 humanOptionName : 'Test environment' ,
104109 optionName : 'testEnvironment' ,
105110 prefix : 'jest-environment-' ,
111+ requireResolveFunction,
106112 rootDir,
107113 } ) ;
108114
@@ -116,13 +122,23 @@ export const resolveTestEnvironment = ({
116122 */
117123export const resolveWatchPlugin = (
118124 resolver : string | undefined | null ,
119- { filePath, rootDir} : { filePath : string ; rootDir : Config . Path } ,
125+ {
126+ filePath,
127+ rootDir,
128+ // TODO: remove default in Jest 28
129+ requireResolveFunction = require . resolve ,
130+ } : {
131+ filePath : string ;
132+ rootDir : Config . Path ;
133+ requireResolveFunction ?: ( moduleName : string ) => string ;
134+ } ,
120135) : string =>
121136 resolveWithPrefix ( resolver , {
122137 filePath,
123138 humanOptionName : 'Watch plugin' ,
124139 optionName : 'watchPlugins' ,
125140 prefix : 'jest-watch-' ,
141+ requireResolveFunction,
126142 rootDir,
127143 } ) ;
128144
@@ -136,24 +152,44 @@ export const resolveWatchPlugin = (
136152 */
137153export const resolveRunner = (
138154 resolver : string | undefined | null ,
139- { filePath, rootDir} : { filePath : string ; rootDir : Config . Path } ,
155+ {
156+ filePath,
157+ rootDir,
158+ // TODO: remove default in Jest 28
159+ requireResolveFunction = require . resolve ,
160+ } : {
161+ filePath : string ;
162+ rootDir : Config . Path ;
163+ requireResolveFunction ?: ( moduleName : string ) => string ;
164+ } ,
140165) : string =>
141166 resolveWithPrefix ( resolver , {
142167 filePath,
143168 humanOptionName : 'Jest Runner' ,
144169 optionName : 'runner' ,
145170 prefix : 'jest-runner-' ,
171+ requireResolveFunction,
146172 rootDir,
147173 } ) ;
148174
149175export const resolveSequencer = (
150176 resolver : string | undefined | null ,
151- { filePath, rootDir} : { filePath : string ; rootDir : Config . Path } ,
177+ {
178+ filePath,
179+ rootDir,
180+ // TODO: remove default in Jest 28
181+ requireResolveFunction = require . resolve ,
182+ } : {
183+ filePath : string ;
184+ rootDir : Config . Path ;
185+ requireResolveFunction ?: ( moduleName : string ) => string ;
186+ } ,
152187) : string =>
153188 resolveWithPrefix ( resolver , {
154189 filePath,
155190 humanOptionName : 'Jest Sequencer' ,
156191 optionName : 'testSequencer' ,
157192 prefix : 'jest-sequencer-' ,
193+ requireResolveFunction,
158194 rootDir,
159195 } ) ;
0 commit comments