66 *
77 */
88
9- import * as path from 'path' ;
10- import { fileURLToPath , pathToFileURL } from 'url' ;
119import * as fs from 'graceful-fs' ;
12- import { sync as resolveSync } from 'resolve' ;
1310import { type IModuleMap , ModuleMap } from 'jest-haste-map' ;
11+ import * as path from 'path' ;
12+ import { pathToFileURL } from 'url' ;
13+
1414import userResolver from '../__mocks__/userResolver' ;
1515import userResolverAsync from '../__mocks__/userResolverAsync' ;
16- import defaultResolver , { type PackageFilter } from '../defaultResolver' ;
16+ import defaultResolver from '../defaultResolver' ;
1717import nodeModulesPaths from '../nodeModulesPaths' ;
1818import Resolver from '../resolver' ;
1919import type { ResolverConfig } from '../types' ;
2020
2121jest . mock ( '../__mocks__/userResolver' ) . mock ( '../__mocks__/userResolverAsync' ) ;
2222
23- // Do not fully mock `resolve` because it is used by Jest. Doing it will crash
24- // in very strange ways. Instead, just spy on it and its `sync` method.
25- jest . mock ( 'resolve' , ( ) => {
26- const originalModule =
27- jest . requireActual < typeof import ( 'resolve' ) > ( 'resolve' ) ;
28-
29- const m = jest . fn < typeof import ( 'resolve' ) > ( ( ...args ) =>
30- originalModule ( ...args ) ,
31- ) ;
32- Object . assign ( m , originalModule ) ;
33- m . sync = jest . spyOn ( originalModule , 'sync' ) ;
34-
35- return m ;
36- } ) ;
37-
3823const mockUserResolver = jest . mocked ( userResolver ) ;
3924const mockUserResolverAsync = jest . mocked ( userResolverAsync ) ;
40- const mockResolveSync = jest . mocked ( resolveSync ) ;
4125
4226beforeEach ( ( ) => {
4327 mockUserResolver . mockClear ( ) ;
4428 mockUserResolverAsync . async . mockClear ( ) ;
45- mockResolveSync . mockClear ( ) ;
4629
4730 Resolver . clearDefaultResolverCache ( ) ;
4831} ) ;
@@ -134,25 +117,6 @@ describe('findNodeModule', () => {
134117 } ) ;
135118 } ) ;
136119
137- it ( 'wraps passed packageFilter to the resolve module when using the default resolver' , ( ) => {
138- const packageFilter = jest . fn < PackageFilter > ( ) ;
139-
140- // A resolver that delegates to defaultResolver with a packageFilter implementation
141- mockUserResolver . mockImplementation ( ( request , opts ) =>
142- opts . defaultResolver ( request , { ...opts , packageFilter} ) ,
143- ) ;
144-
145- Resolver . findNodeModule ( './test' , {
146- basedir : path . resolve ( __dirname , '../__mocks__/' ) ,
147- resolver : require . resolve ( '../__mocks__/userResolver' ) ,
148- } ) ;
149-
150- expect ( packageFilter ) . toHaveBeenCalledWith (
151- expect . objectContaining ( { name : '__mocks__' } ) ,
152- expect . any ( String ) ,
153- ) ;
154- } ) ;
155-
156120 it ( 'supports file URLs' , ( ) => {
157121 const path = pathToFileURL ( __filename ) . href ;
158122 const newPath = Resolver . findNodeModule ( path , {
@@ -209,7 +173,7 @@ describe('findNodeModule', () => {
209173 ) ;
210174 } ) ;
211175
212- test ( 'respects order in package.json, not conditions ' , ( ) => {
176+ test ( 'respects order in conditions over package.json' , ( ) => {
213177 const resultImport = Resolver . findNodeModule ( 'exports' , {
214178 basedir : conditionsRoot ,
215179 conditions : [ 'import' , 'require' ] ,
@@ -219,7 +183,7 @@ describe('findNodeModule', () => {
219183 conditions : [ 'require' , 'import' ] ,
220184 } ) ;
221185
222- expect ( resultImport ) . toEqual ( resultRequire ) ;
186+ expect ( resultImport ) . not . toEqual ( resultRequire ) ;
223187 } ) ;
224188
225189 test ( 'supports nested paths' , ( ) => {
@@ -407,7 +371,9 @@ describe('findNodeModule', () => {
407371 basedir : path . resolve ( importsRoot , './foo-import/index.js' ) ,
408372 conditions : [ ] ,
409373 } ) ;
410- } ) . toThrow ( 'Missing "#something-else" specifier in "foo-import" package' ) ;
374+ } ) . toThrow (
375+ `Package import specifier "#something-else" is not defined in package ${ path . join ( importsRoot , 'foo-import/package.json' ) } ` ,
376+ ) ;
411377 } ) ;
412378 } ) ;
413379} ) ;
@@ -446,27 +412,6 @@ describe('findNodeModuleAsync', () => {
446412 } ) ;
447413 } ) ;
448414
449- it ( 'passes packageFilter to the resolve module when using the default resolver' , async ( ) => {
450- const packageFilter = jest . fn < PackageFilter > ( ) ;
451-
452- // A resolver that delegates to defaultResolver with a packageFilter implementation
453- mockUserResolverAsync . async . mockImplementation ( ( request , opts ) =>
454- Promise . resolve ( opts . defaultResolver ( request , { ...opts , packageFilter} ) ) ,
455- ) ;
456-
457- await Resolver . findNodeModuleAsync ( 'test' , {
458- basedir : '/' ,
459- resolver : require . resolve ( '../__mocks__/userResolverAsync' ) ,
460- } ) ;
461-
462- expect ( mockResolveSync ) . toHaveBeenCalledWith (
463- 'test' ,
464- expect . objectContaining ( {
465- packageFilter,
466- } ) ,
467- ) ;
468- } ) ;
469-
470415 it ( 'supports file URLs' , async ( ) => {
471416 const path = pathToFileURL ( __filename ) . href ;
472417 const newPath = await Resolver . findNodeModuleAsync ( path , {
0 commit comments