@@ -21,13 +21,17 @@ export abstract class QLTestNode {
2121 }
2222
2323 public abstract get children ( ) : readonly QLTestNode [ ] ;
24+
25+ public abstract finish ( ) : void ;
2426}
2527
2628/**
2729 * A directory containing one or more QL tests or other test directories.
2830 */
2931export class QLTestDirectory extends QLTestNode {
30- constructor ( _path : string , _name : string , private _children : QLTestNode [ ] ) {
32+ private _children : QLTestNode [ ] = [ ] ;
33+
34+ constructor ( _path : string , _name : string ) {
3135 super ( _path , _name ) ;
3236 }
3337
@@ -50,13 +54,20 @@ export class QLTestDirectory extends QLTestNode {
5054 }
5155 }
5256
57+ public finish ( ) : void {
58+ this . _children . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
59+ for ( const child of this . _children ) {
60+ child . finish ( ) ;
61+ }
62+ }
63+
5364 private createChildDirectory ( name : string ) : QLTestDirectory {
5465 const existingChild = this . _children . find ( ( child ) => child . name === name ) ;
5566 if ( existingChild !== undefined ) {
5667 return < QLTestDirectory > existingChild ;
5768 }
5869 else {
59- const newChild = new QLTestDirectory ( path . join ( this . path , name ) , name , [ ] ) ;
70+ const newChild = new QLTestDirectory ( path . join ( this . path , name ) , name ) ;
6071 this . addChild ( newChild ) ;
6172 return newChild ;
6273 }
@@ -74,6 +85,9 @@ export class QLTestFile extends QLTestNode {
7485 public get children ( ) : readonly QLTestNode [ ] {
7586 return [ ] ;
7687 }
88+
89+ public finish ( ) : void {
90+ }
7791}
7892
7993/**
@@ -177,14 +191,16 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
177191 return undefined ;
178192 }
179193 else {
180- const rootDirectory = new QLTestDirectory ( fullPath , name , [ ] ) ;
194+ const rootDirectory = new QLTestDirectory ( fullPath , name ) ;
181195 for ( const testPath of resolvedTests ) {
182196 const relativePath = path . normalize ( path . relative ( fullPath , testPath ) ) ;
183197 const dirName = path . dirname ( relativePath ) ;
184198 const parentDirectory = rootDirectory . createDirectory ( dirName ) ;
185199 parentDirectory . addChild ( new QLTestFile ( testPath , path . basename ( testPath ) ) ) ;
186200 }
187201
202+ rootDirectory . finish ( ) ;
203+
188204 return rootDirectory ;
189205 }
190206 }
0 commit comments