@@ -144,4 +144,59 @@ test.group('Seeds Source', (group) => {
144144 ]
145145 )
146146 } )
147+
148+ test ( 'use a natural sort to order files when configured' , async ( { fs, assert } ) => {
149+ const app = new AppFactory ( ) . create ( fs . baseUrl , ( ) => { } )
150+ await app . init ( )
151+ const db = getDb ( )
152+
153+ const config = Object . assign ( { } , db . getRawConnection ( 'primary' ) ! . config , {
154+ seeders : {
155+ naturalSort : true ,
156+ paths : [ 'database/seeders' ] ,
157+ } ,
158+ } )
159+
160+ const seedersSource = new SeedersSource ( config , app )
161+ await fs . create ( 'database/seeders/1.ts' , '' )
162+ await fs . create ( 'database/seeders/2.ts' , '' )
163+ await fs . create ( 'database/seeders/10.ts' , '' )
164+ await fs . create ( 'database/seeders/3.ts' , '' )
165+ await fs . create ( 'database/seeders/100.ts' , '' )
166+ await fs . create ( 'database/seeders/4.ts' , '' )
167+ await db . manager . closeAll ( )
168+
169+ const files = await seedersSource . getSeeders ( )
170+ assert . deepEqual (
171+ files . map ( ( file ) => {
172+ return { absPath : file . absPath , name : file . name }
173+ } ) ,
174+ [
175+ {
176+ absPath : join ( fs . basePath , 'database/seeders/1.ts' ) ,
177+ name : 'database/seeders/1' ,
178+ } ,
179+ {
180+ absPath : join ( fs . basePath , 'database/seeders/2.ts' ) ,
181+ name : 'database/seeders/2' ,
182+ } ,
183+ {
184+ absPath : join ( fs . basePath , 'database/seeders/3.ts' ) ,
185+ name : 'database/seeders/3' ,
186+ } ,
187+ {
188+ absPath : join ( fs . basePath , 'database/seeders/4.ts' ) ,
189+ name : 'database/seeders/4' ,
190+ } ,
191+ {
192+ absPath : join ( fs . basePath , 'database/seeders/10.ts' ) ,
193+ name : 'database/seeders/10' ,
194+ } ,
195+ {
196+ absPath : join ( fs . basePath , 'database/seeders/100.ts' ) ,
197+ name : 'database/seeders/100' ,
198+ } ,
199+ ]
200+ )
201+ } )
147202} )
0 commit comments