@@ -113,4 +113,76 @@ describe('toObjectEntry', () => {
113113 'src/bar' : path . join ( testDir , 'src/bar.ts' ) ,
114114 } )
115115 } )
116+
117+ // #660
118+ test ( 'object entry with glob negation pattern' , async ( context ) => {
119+ const { testDir } = await writeFixtures ( context , {
120+ 'src/hooks/index.ts' : '' ,
121+ 'src/hooks/useAuth.ts' : '' ,
122+ 'src/hooks/useUser.ts' : '' ,
123+ } )
124+ const result = await toObjectEntry (
125+ {
126+ 'hooks/*' : [ 'src/hooks/*.ts' , '!src/hooks/index.ts' ] ,
127+ } ,
128+ testDir ,
129+ )
130+ expect ( result ) . toEqual ( {
131+ 'hooks/useAuth' : path . join ( testDir , 'src/hooks/useAuth.ts' ) ,
132+ 'hooks/useUser' : path . join ( testDir , 'src/hooks/useUser.ts' ) ,
133+ } )
134+ expect ( Object . keys ( result ) ) . not . toContain ( 'hooks/index' )
135+ } )
136+
137+ test ( 'object entry with multiple negation patterns' , async ( context ) => {
138+ const { testDir } = await writeFixtures ( context , {
139+ 'src/utils/index.ts' : '' ,
140+ 'src/utils/internal.ts' : '' ,
141+ 'src/utils/helper.ts' : '' ,
142+ 'src/utils/format.ts' : '' ,
143+ } )
144+ const result = await toObjectEntry (
145+ {
146+ 'utils/*' : [
147+ 'src/utils/*.ts' ,
148+ '!src/utils/index.ts' ,
149+ '!src/utils/internal.ts' ,
150+ ] ,
151+ } ,
152+ testDir ,
153+ )
154+ expect ( result ) . toEqual ( {
155+ 'utils/helper' : path . join ( testDir , 'src/utils/helper.ts' ) ,
156+ 'utils/format' : path . join ( testDir , 'src/utils/format.ts' ) ,
157+ } )
158+ } )
159+
160+ test ( 'object entry with multiple positive patterns should throw' , async ( context ) => {
161+ const { testDir } = await writeFixtures ( context , {
162+ 'src/hooks/useAuth.ts' : '' ,
163+ 'src/utils/helper.ts' : '' ,
164+ } )
165+ await expect (
166+ toObjectEntry (
167+ {
168+ 'lib/*' : [ 'src/hooks/*.ts' , 'src/utils/*.ts' ] ,
169+ } ,
170+ testDir ,
171+ ) ,
172+ ) . rejects . toThrow ( / m u l t i p l e p o s i t i v e p a t t e r n s / )
173+ } )
174+
175+ test ( 'object entry with no positive pattern should throw' , async ( context ) => {
176+ const { testDir } = await writeFixtures ( context , {
177+ 'src/hooks/useAuth.ts' : '' ,
178+ } )
179+ await expect (
180+ toObjectEntry (
181+ {
182+ 'hooks/*' : [ '!src/hooks/index.ts' ] ,
183+ } ,
184+ testDir ,
185+ ) ,
186+ ) . rejects . toThrow ( / n o p o s i t i v e p a t t e r n / )
187+ } )
116188} )
0 commit comments