File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ interface Runner {
2121 // mechanism (e.g. Promise.race or AbortController) would not get called in
2222 // that case.
2323 runTest ( test : string , timeout ?: number ) : Promise < Pass | Fail > ;
24+ runAllTests ( tests : string [ ] , timeout ?: number ) : Promise < ( Pass | Fail ) [ ] > ;
2425 dispose ( ) : void ;
2526}
2627
@@ -154,6 +155,18 @@ ${opts.source}`;
154155 return result ;
155156 }
156157
158+ async runAllTests ( tests : string [ ] ) : Promise < ( Pass | Fail ) [ ] > {
159+ const results : ( Pass | Fail ) [ ] = [ ] ;
160+
161+ for ( const test of tests ) {
162+ // eslint-disable-next-line no-await-in-loop
163+ const result = await this . runTest ( test ) ;
164+ results . push ( result ) ;
165+ }
166+
167+ return results ;
168+ }
169+
157170 dispose ( ) {
158171 this . #testEvaluator. remove ( ) ;
159172 }
@@ -231,6 +244,18 @@ export class WorkerTestRunner implements Runner {
231244 }
232245 }
233246
247+ async runAllTests ( tests : string [ ] , timeout = 5000 ) : Promise < ( Pass | Fail ) [ ] > {
248+ const results : ( Pass | Fail ) [ ] = [ ] ;
249+
250+ for ( const test of tests ) {
251+ // eslint-disable-next-line no-await-in-loop
252+ const result = await this . runTest ( test , timeout ) ;
253+ results . push ( result ) ;
254+ }
255+
256+ return results ;
257+ }
258+
234259 dispose ( ) {
235260 this . #testEvaluator. terminate ( ) ;
236261 }
Original file line number Diff line number Diff line change @@ -373,6 +373,60 @@ for(let i = 0; i < 3; i++) {
373373
374374 expect ( result ) . toEqual ( { pass : true } ) ;
375375 } ) ;
376+
377+ it ( "should handle running multiple tests with runAllTests" , async ( ) => {
378+ const result = await page . evaluate ( async ( type ) => {
379+ const runner = await window . FCCTestRunner . createTestRunner ( {
380+ type,
381+ } ) ;
382+
383+ const tests = [
384+ "assert.equal(1, 1)" ,
385+ "assert.equal(2, 2)" ,
386+ "assert.equal(1, 2)" , // This should fail
387+ "console.log('test message'); assert.equal(3, 3)" ,
388+ ] ;
389+
390+ return runner . runAllTests ( tests ) ;
391+ } , type ) ;
392+
393+ expect ( result ) . toEqual ( [
394+ { pass : true } ,
395+ { pass : true } ,
396+ {
397+ err : {
398+ actual : 1 ,
399+ expected : 2 ,
400+ message : "expected 1 to equal 2" ,
401+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
402+ stack : expect . stringMatching (
403+ "AssertionError: expected 1 to equal 2" ,
404+ ) ,
405+ } ,
406+ } ,
407+ {
408+ pass : true ,
409+ logs : [
410+ {
411+ level : "log" ,
412+ msg : "test message" ,
413+ } ,
414+ ] ,
415+ } ,
416+ ] ) ;
417+ } ) ;
418+
419+ it ( "should handle empty array in runAllTests" , async ( ) => {
420+ const result = await page . evaluate ( async ( type ) => {
421+ const runner = await window . FCCTestRunner . createTestRunner ( {
422+ type,
423+ } ) ;
424+
425+ return runner . runAllTests ( [ ] ) ;
426+ } , type ) ;
427+
428+ expect ( result ) . toEqual ( [ ] ) ;
429+ } ) ;
376430 } ) ;
377431
378432 describe . each ( [
You can’t perform that action at this time.
0 commit comments