@@ -250,4 +250,53 @@ describe('toObjectEntry', () => {
250250 'src/utils/helper' : path . join ( testDir , 'src/utils/helper.ts' ) ,
251251 } )
252252 } )
253+
254+ test ( 'object entry with custom root' , async ( context ) => {
255+ const { testDir } = await writeFixtures ( context , {
256+ 'src/index.ts' : '' ,
257+ 'src/utils/helper.ts' : '' ,
258+ } )
259+ const root = testDir
260+ const [ result , resolvedRoot ] = await toObjectEntry (
261+ { main : 'src/index.ts' , helper : 'src/utils/helper.ts' } ,
262+ testDir ,
263+ root ,
264+ )
265+ expect ( resolvedRoot ) . toBe ( root )
266+ // Object entry keys are user-provided, so the root must not rename them.
267+ expect ( result ) . toEqual ( {
268+ main : 'src/index.ts' ,
269+ helper : 'src/utils/helper.ts' ,
270+ } )
271+ } )
272+
273+ test ( 'object entry with glob key and custom root' , async ( context ) => {
274+ const { testDir } = await writeFixtures ( context , {
275+ 'src/index.ts' : '' ,
276+ 'src/utils/helper.ts' : '' ,
277+ } )
278+ const root = testDir
279+ const [ result , resolvedRoot ] = await toObjectEntry (
280+ { 'lib/*' : 'src/**/*.ts' } ,
281+ testDir ,
282+ root ,
283+ )
284+ expect ( resolvedRoot ) . toBe ( root )
285+ expect ( result ) . toEqual ( {
286+ 'lib/index' : path . join ( testDir , 'src/index.ts' ) ,
287+ 'lib/utils/helper' : path . join ( testDir , 'src/utils/helper.ts' ) ,
288+ } )
289+ } )
290+
291+ test ( 'object entry without custom root' , async ( context ) => {
292+ const { testDir } = await writeFixtures ( context , {
293+ 'src/index.ts' : '' ,
294+ 'src/utils/helper.ts' : '' ,
295+ } )
296+ const [ , resolvedRoot ] = await toObjectEntry (
297+ { main : 'src/index.ts' , helper : 'src/utils/helper.ts' } ,
298+ testDir ,
299+ )
300+ expect ( resolvedRoot ) . toBe ( 'src' )
301+ } )
253302} )
0 commit comments