File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
src/test-reader/mocha-reader Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 11const { Suite, Test, Hook } = require ( "../test-object" ) ;
22const crypto = require ( "../../utils/crypto" ) ;
3+ const { computeFile } = require ( "./utils" ) ;
34
45class TreeBuilderDecorator {
56 #treeBuilder;
@@ -17,7 +18,9 @@ class TreeBuilderDecorator {
1718 }
1819
1920 addSuite ( mochaSuite ) {
20- const { id : mochaId , file } = mochaSuite ;
21+ const { id : mochaId } = mochaSuite ;
22+ const file = computeFile ( mochaSuite ) ?? "unknown-file" ;
23+
2124 const positionInFile = this . #suiteCounter. get ( file ) || 0 ;
2225 const id = mochaSuite . root ? mochaId : crypto . getShortMD5 ( file ) + positionInFile ;
2326 const suite = this . #mkTestObject( Suite , mochaSuite , { id } ) ;
Original file line number Diff line number Diff line change 1+ // When using "exports" mocha interface, "file" field is absent on suites, and available on tests only.
2+ // This helper tries to resolve "file" field for suites, drilling down to child tests and using their file field.
3+ const computeFile = mochaSuite => {
4+ if ( mochaSuite . file ) {
5+ return mochaSuite . file ;
6+ }
7+
8+ if ( mochaSuite . tests . length > 0 && mochaSuite . tests [ 0 ] . file ) {
9+ mochaSuite . file = mochaSuite . tests [ 0 ] . file ;
10+
11+ return mochaSuite . file ;
12+ }
13+
14+ for ( const childSuite of mochaSuite . suites ) {
15+ const computedFile = computeFile ( childSuite ) ;
16+ if ( computedFile ) {
17+ mochaSuite . file = computedFile ;
18+
19+ return mochaSuite . file ;
20+ }
21+ }
22+
23+ return null ;
24+ } ;
25+
26+ module . exports = {
27+ computeFile,
28+ } ;
You can’t perform that action at this time.
0 commit comments