@@ -248,6 +248,47 @@ describe('Runtime requireModule', () => {
248
248
expect ( hastePackage . isHastePackage ) . toBe ( true ) ;
249
249
} ) ) ;
250
250
251
+ it ( 'supports resolving the same path to multiple modules' , ( ) =>
252
+ createRuntime ( __filename , {
253
+ // using the default resolver as a custom resolver
254
+ resolver : require . resolve ( '../__mocks__/resourceQueryResolver.js' ) ,
255
+ } ) . then ( runtime => {
256
+ const moduleNoQuery1 = runtime . requireModule (
257
+ runtime . __mockRootPath ,
258
+ './moduleWithResourceQuery.js' ,
259
+ ) ;
260
+ const moduleNoQuery2 = runtime . requireModule (
261
+ runtime . __mockRootPath ,
262
+ './moduleWithResourceQuery.js' ,
263
+ ) ;
264
+ expect ( moduleNoQuery1 . name ) . toBe ( 'moduleWithoutResourceQuery' ) ;
265
+ expect ( moduleNoQuery1 ) . toBe ( moduleNoQuery2 ) ;
266
+
267
+ const moduleWithQueryA = runtime . requireModule (
268
+ runtime . __mockRootPath ,
269
+ './moduleWithResourceQuery.js?a' ,
270
+ ) ;
271
+ const moduleWithQueryB = runtime . requireModule (
272
+ runtime . __mockRootPath ,
273
+ './moduleWithResourceQuery.js?b' ,
274
+ ) ;
275
+ expect ( moduleWithQueryA . name ) . toBe ( 'moduleWithoutResourceQuery' ) ;
276
+ expect ( moduleWithQueryB . name ) . toBe ( 'moduleWithoutResourceQuery' ) ;
277
+ expect ( moduleWithQueryA ) . not . toBe ( moduleWithQueryB ) ;
278
+
279
+ const moduleWithSameQuery1 = runtime . requireModule (
280
+ runtime . __mockRootPath ,
281
+ './moduleWithResourceQuery.js?sameQuery' ,
282
+ ) ;
283
+ const moduleWithSameQuery2 = runtime . requireModule (
284
+ runtime . __mockRootPath ,
285
+ './moduleWithResourceQuery.js?sameQuery' ,
286
+ ) ;
287
+ expect ( moduleWithSameQuery1 . name ) . toBe ( 'moduleWithoutResourceQuery' ) ;
288
+ expect ( moduleWithSameQuery2 . name ) . toBe ( 'moduleWithoutResourceQuery' ) ;
289
+ expect ( moduleWithSameQuery1 ) . toBe ( moduleWithSameQuery2 ) ;
290
+ } ) ) ;
291
+
251
292
it ( 'resolves node modules properly when crawling node_modules' , ( ) =>
252
293
// While we are crawling a node module, we shouldn't put package.json
253
294
// files of node modules to resolve to `package.json` but rather resolve
0 commit comments