@@ -39,6 +39,33 @@ describe('pathsToModuleNameMapper', () => {
3939 ` )
4040 } )
4141
42+ test ( 'should add `js` extension to resolved config with useESM: true' , ( ) => {
43+ expect ( pathsToModuleNameMapper ( tsconfigMap , { useESM : true } ) ) . toEqual ( {
44+ /**
45+ * Why not using snapshot here?
46+ * Because the snapshot does not keep the property order, which is important for jest.
47+ * A pattern ending with `\\.js` should appear before another pattern without the extension does.
48+ */
49+ '^log$' : 'src/utils/log' ,
50+ '^server$' : 'src/server' ,
51+ '^client$' : [ 'src/client' , 'src/client/index' ] ,
52+ '^util/(.*)\\.js$' : 'src/utils/$1' ,
53+ '^util/(.*)$' : 'src/utils/$1' ,
54+ '^api/(.*)\\.js$' : 'src/api/$1' ,
55+ '^api/(.*)$' : 'src/api/$1' ,
56+ '^test/(.*)\\.js$' : 'test/$1' ,
57+ '^test/(.*)$' : 'test/$1' ,
58+ '^mocks/(.*)\\.js$' : 'test/mocks/$1' ,
59+ '^mocks/(.*)$' : 'test/mocks/$1' ,
60+ '^test/(.*)/mock\\.js$' : [ 'test/mocks/$1' , 'test/__mocks__/$1' ] ,
61+ '^test/(.*)/mock$' : [ 'test/mocks/$1' , 'test/__mocks__/$1' ] ,
62+ '^@foo\\-bar/common$' : '../common/dist/library' ,
63+ '^@pkg/(.*)\\.js$' : './packages/$1' ,
64+ '^@pkg/(.*)$' : './packages/$1' ,
65+ '^(\\.{1,2}/.*)\\.js$' : '$1' ,
66+ } )
67+ } )
68+
4269 test . each ( [ '<rootDir>/' , 'foo' ] ) ( 'should convert tsconfig mapping with given prefix' , ( prefix ) => {
4370 expect ( pathsToModuleNameMapper ( tsconfigMap , { prefix } ) ) . toMatchSnapshot ( prefix )
4471 } )
0 commit comments