@@ -40,12 +40,14 @@ const resolveWithPrefix = (
40
40
humanOptionName,
41
41
optionName,
42
42
prefix,
43
+ requireResolveFunction,
43
44
rootDir,
44
45
} : {
45
46
filePath : string ;
46
47
humanOptionName : string ;
47
48
optionName : string ;
48
49
prefix : string ;
50
+ requireResolveFunction : ( moduleName : string ) => string ;
49
51
rootDir : Config . Path ;
50
52
} ,
51
53
) : string => {
@@ -59,7 +61,7 @@ const resolveWithPrefix = (
59
61
}
60
62
61
63
try {
62
- return require . resolve ( `${ prefix } ${ fileName } ` ) ;
64
+ return requireResolveFunction ( `${ prefix } ${ fileName } ` ) ;
63
65
} catch { }
64
66
65
67
module = Resolver . findNodeModule ( fileName , {
@@ -71,7 +73,7 @@ const resolveWithPrefix = (
71
73
}
72
74
73
75
try {
74
- return require . resolve ( fileName ) ;
76
+ return requireResolveFunction ( fileName ) ;
75
77
} catch { }
76
78
77
79
throw createValidationError (
@@ -94,15 +96,19 @@ const resolveWithPrefix = (
94
96
export const resolveTestEnvironment = ( {
95
97
rootDir,
96
98
testEnvironment : filePath ,
99
+ // TODO: remove default in Jest 28
100
+ requireResolveFunction = require . resolve ,
97
101
} : {
98
102
rootDir : Config . Path ;
99
103
testEnvironment : string ;
104
+ requireResolveFunction ?: ( moduleName : string ) => string ;
100
105
} ) : string =>
101
106
resolveWithPrefix ( undefined , {
102
107
filePath,
103
108
humanOptionName : 'Test environment' ,
104
109
optionName : 'testEnvironment' ,
105
110
prefix : 'jest-environment-' ,
111
+ requireResolveFunction,
106
112
rootDir,
107
113
} ) ;
108
114
@@ -116,13 +122,23 @@ export const resolveTestEnvironment = ({
116
122
*/
117
123
export const resolveWatchPlugin = (
118
124
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
+ } ,
120
135
) : string =>
121
136
resolveWithPrefix ( resolver , {
122
137
filePath,
123
138
humanOptionName : 'Watch plugin' ,
124
139
optionName : 'watchPlugins' ,
125
140
prefix : 'jest-watch-' ,
141
+ requireResolveFunction,
126
142
rootDir,
127
143
} ) ;
128
144
@@ -136,24 +152,44 @@ export const resolveWatchPlugin = (
136
152
*/
137
153
export const resolveRunner = (
138
154
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
+ } ,
140
165
) : string =>
141
166
resolveWithPrefix ( resolver , {
142
167
filePath,
143
168
humanOptionName : 'Jest Runner' ,
144
169
optionName : 'runner' ,
145
170
prefix : 'jest-runner-' ,
171
+ requireResolveFunction,
146
172
rootDir,
147
173
} ) ;
148
174
149
175
export const resolveSequencer = (
150
176
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
+ } ,
152
187
) : string =>
153
188
resolveWithPrefix ( resolver , {
154
189
filePath,
155
190
humanOptionName : 'Jest Sequencer' ,
156
191
optionName : 'testSequencer' ,
157
192
prefix : 'jest-sequencer-' ,
193
+ requireResolveFunction,
158
194
rootDir,
159
195
} ) ;
0 commit comments