@@ -151,24 +151,42 @@ namespace Harness.Parallel.Worker {
151151 unitTestSuiteMap . set ( suite . title , suite ) ;
152152 }
153153 }
154+ if ( ! unitTestTestMap && unitTestSuite . tests . length ) {
155+ unitTestTestMap = ts . createMap < Mocha . Test > ( ) ;
156+ for ( const test of unitTestSuite . tests ) {
157+ unitTestTestMap . set ( test . title , test ) ;
158+ }
159+ }
154160
155- if ( ! unitTestSuiteMap ) {
161+ if ( ! unitTestSuiteMap && ! unitTestTestMap ) {
156162 throw new Error ( `Asked to run unit test ${ task . file } , but no unit tests were discovered!` ) ;
157163 }
158164
159- const suite = unitTestSuiteMap . get ( task . file ) ;
160- if ( ! suite ) {
165+ let suite = unitTestSuiteMap . get ( task . file ) ;
166+ const test = unitTestTestMap . get ( task . file ) ;
167+ if ( ! suite && ! test ) {
161168 throw new Error ( `Unit test with name "${ task . file } " was asked to be run, but such a test does not exist!` ) ;
162169 }
163170
164171 const root = new Suite ( "" , new Mocha . Context ( ) ) ;
165172 root . timeout ( globalTimeout || 40_000 ) ;
166- root . addSuite ( suite ) ;
167- Object . setPrototypeOf ( suite . ctx , root . ctx ) ;
173+ if ( suite ) {
174+ root . addSuite ( suite ) ;
175+ Object . setPrototypeOf ( suite . ctx , root . ctx ) ;
176+ }
177+ else if ( test ) {
178+ const newSuite = new Suite ( "" , new Mocha . Context ( ) ) ;
179+ newSuite . addTest ( test ) ;
180+ root . addSuite ( newSuite ) ;
181+ Object . setPrototypeOf ( newSuite . ctx , root . ctx ) ;
182+ Object . setPrototypeOf ( test . ctx , root . ctx ) ;
183+ test . parent = newSuite ;
184+ suite = newSuite ;
185+ }
168186
169- runSuite ( task , suite , payload => {
170- suite . parent = unitTestSuite ;
171- Object . setPrototypeOf ( suite . ctx , unitTestSuite . ctx ) ;
187+ runSuite ( task , suite ! , payload => {
188+ suite ! . parent = unitTestSuite ;
189+ Object . setPrototypeOf ( suite ! . ctx , unitTestSuite . ctx ) ;
172190 fn ( payload ) ;
173191 } ) ;
174192 }
@@ -284,6 +302,8 @@ namespace Harness.Parallel.Worker {
284302 // The root suite for all unit tests.
285303 let unitTestSuite : Suite ;
286304 let unitTestSuiteMap : ts . Map < Mocha . Suite > ;
305+ // (Unit) Tests directly within the root suite
306+ let unitTestTestMap : ts . Map < Mocha . Test > ;
287307
288308 if ( runUnitTests ) {
289309 unitTestSuite = new Suite ( "" , new Mocha . Context ( ) ) ;
0 commit comments