@@ -64,7 +64,7 @@ export class TestTree {
6464 private _treeItemByTestId = new Map < string , TestItem | TestCaseItem > ( ) ;
6565 readonly pathSeparator : string ;
6666
67- constructor ( rootFolder : string , rootSuite : reporterTypes . Suite | undefined , loadErrors : reporterTypes . TestError [ ] , projectFilters : Map < string , boolean > | undefined , pathSeparator : string ) {
67+ constructor ( rootFolder : string , rootSuite : reporterTypes . Suite | undefined , loadErrors : reporterTypes . TestError [ ] , projectFilters : Map < string , boolean > | undefined , pathSeparator : string , hideFiles : boolean ) {
6868 const filterProjects = projectFilters && [ ...projectFilters . values ( ) ] . some ( Boolean ) ;
6969 this . pathSeparator = pathSeparator ;
7070 this . rootItem = {
@@ -81,11 +81,11 @@ export class TestTree {
8181 } ;
8282 this . _treeItemById . set ( rootFolder , this . rootItem ) ;
8383
84- const visitSuite = ( project : reporterTypes . FullProject , parentSuite : reporterTypes . Suite , parentGroup : GroupItem ) => {
85- for ( const suite of parentSuite . suites ) {
84+ const visitSuite = ( project : reporterTypes . FullProject , parentSuite : reporterTypes . Suite , parentGroup : GroupItem , mode : 'tests' | 'suites' | 'all' ) => {
85+ for ( const suite of mode === 'tests' ? [ ] : parentSuite . suites ) {
8686 if ( ! suite . title ) {
8787 // Flatten anonymous describes.
88- visitSuite ( project , suite , parentGroup ) ;
88+ visitSuite ( project , suite , parentGroup , 'all' ) ;
8989 continue ;
9090 }
9191
@@ -105,10 +105,10 @@ export class TestTree {
105105 } ;
106106 this . _addChild ( parentGroup , group ) ;
107107 }
108- visitSuite ( project , suite , group ) ;
108+ visitSuite ( project , suite , group , 'all' ) ;
109109 }
110110
111- for ( const test of parentSuite . tests ) {
111+ for ( const test of mode === 'suites' ? [ ] : parentSuite . tests ) {
112112 const title = test . title ;
113113 let testCaseItem = parentGroup . children . find ( t => t . kind !== 'group' && t . title === title ) as TestCaseItem ;
114114 if ( ! testCaseItem ) {
@@ -167,8 +167,16 @@ export class TestTree {
167167 if ( filterProjects && ! projectFilters . get ( projectSuite . title ) )
168168 continue ;
169169 for ( const fileSuite of projectSuite . suites ) {
170- const fileItem = this . _fileItem ( fileSuite . location ! . file . split ( pathSeparator ) , true ) ;
171- visitSuite ( projectSuite . project ( ) ! , fileSuite , fileItem ) ;
170+ if ( hideFiles ) {
171+ visitSuite ( projectSuite . project ( ) ! , fileSuite , this . rootItem , 'suites' ) ;
172+ if ( fileSuite . tests . length ) {
173+ const defaultDescribeItem = this . _defaultDescribeItem ( ) ;
174+ visitSuite ( projectSuite . project ( ) ! , fileSuite , defaultDescribeItem , 'tests' ) ;
175+ }
176+ } else {
177+ const fileItem = this . _fileItem ( fileSuite . location ! . file . split ( pathSeparator ) , true ) ;
178+ visitSuite ( projectSuite . project ( ) ! , fileSuite , fileItem , 'all' ) ;
179+ }
172180 }
173181 }
174182
@@ -242,6 +250,26 @@ export class TestTree {
242250 return fileItem ;
243251 }
244252
253+ private _defaultDescribeItem ( ) : GroupItem {
254+ let defaultDescribeItem = this . _treeItemById . get ( '<anonymous>' ) as GroupItem ;
255+ if ( ! defaultDescribeItem ) {
256+ defaultDescribeItem = {
257+ kind : 'group' ,
258+ subKind : 'describe' ,
259+ id : '<anonymous>' ,
260+ title : '<anonymous>' ,
261+ location : { file : '' , line : 0 , column : 0 } ,
262+ duration : 0 ,
263+ parent : this . rootItem ,
264+ children : [ ] ,
265+ status : 'none' ,
266+ hasLoadErrors : false ,
267+ } ;
268+ this . _addChild ( this . rootItem , defaultDescribeItem ) ;
269+ }
270+ return defaultDescribeItem ;
271+ }
272+
245273 sortAndPropagateStatus ( ) {
246274 sortAndPropagateStatus ( this . rootItem ) ;
247275 }
@@ -268,17 +296,6 @@ export class TestTree {
268296 this . rootItem = shortRoot ;
269297 }
270298
271- testIds ( ) : Set < string > {
272- const result = new Set < string > ( ) ;
273- const visit = ( treeItem : TreeItem ) => {
274- if ( treeItem . kind === 'case' )
275- treeItem . tests . forEach ( t => result . add ( t . id ) ) ;
276- treeItem . children . forEach ( visit ) ;
277- } ;
278- visit ( this . rootItem ) ;
279- return result ;
280- }
281-
282299 fileNames ( ) : string [ ] {
283300 const result = new Set < string > ( ) ;
284301 const visit = ( treeItem : TreeItem ) => {
@@ -305,8 +322,8 @@ export class TestTree {
305322 return this . _treeItemById . get ( id ) ;
306323 }
307324
308- collectTestIds ( treeItem ? : TreeItem ) : Set < string > {
309- return treeItem ? collectTestIds ( treeItem ) : new Set ( ) ;
325+ collectTestIds ( treeItem : TreeItem ) {
326+ return collectTestIds ( treeItem ) ;
310327 }
311328}
312329
@@ -347,18 +364,27 @@ export function sortAndPropagateStatus(treeItem: TreeItem) {
347364 treeItem . status = 'passed' ;
348365}
349366
350- export function collectTestIds ( treeItem : TreeItem ) : Set < string > {
367+ export function collectTestIds ( treeItem : TreeItem ) : { testIds : Set < string > , locations : Set < string > } {
351368 const testIds = new Set < string > ( ) ;
369+ const locations = new Set < string > ( ) ;
352370 const visit = ( treeItem : TreeItem ) => {
371+ if ( treeItem . kind !== 'test' && treeItem . kind !== 'case' ) {
372+ treeItem . children . forEach ( visit ) ;
373+ return ;
374+ }
375+
376+ let fileItem : TreeItem = treeItem ;
377+ while ( fileItem && fileItem . parent && ! ( fileItem . kind === 'group' && fileItem . subKind === 'file' ) )
378+ fileItem = fileItem . parent ;
379+ locations . add ( fileItem . location . file ) ;
380+
353381 if ( treeItem . kind === 'case' )
354- treeItem . tests . map ( t => t . id ) . forEach ( id => testIds . add ( id ) ) ;
355- else if ( treeItem . kind === 'test' )
356- testIds . add ( treeItem . id ) ;
382+ treeItem . tests . forEach ( test => testIds . add ( test . id ) ) ;
357383 else
358- treeItem . children ?. forEach ( visit ) ;
384+ testIds . add ( treeItem . id ) ;
359385 } ;
360386 visit ( treeItem ) ;
361- return testIds ;
387+ return { testIds, locations } ;
362388}
363389
364390export const statusEx = Symbol ( 'statusEx' ) ;
0 commit comments