@@ -6,52 +6,72 @@ import { promisify } from 'util';
66const exec = promisify ( childProcess . exec ) ;
77
88async function run ( ) : Promise < void > {
9- let testPaths = getTestPaths ( ) ;
10- let failed = [ ] ;
9+ let testPaths : string [ ] = [ ] ;
1110
12- try {
13- const changedPaths : string [ ] = process . env . CHANGED_TEST_PATHS ? JSON . parse ( process . env . CHANGED_TEST_PATHS ) : [ ] ;
11+ const changedPaths : string [ ] = process . env . CHANGED_TEST_PATHS ? JSON . parse ( process . env . CHANGED_TEST_PATHS ) : [ ] ;
1412
15- if ( changedPaths . length > 0 ) {
16- console . log ( `Detected changed test paths:
13+ if ( changedPaths . length > 0 ) {
14+ console . log ( `Detected changed test paths:
1715${ changedPaths . join ( '\n' ) }
1816
1917` ) ;
2018
21- testPaths = testPaths . filter ( p => changedPaths . some ( changedPath => changedPath . includes ( p ) ) ) ;
19+ testPaths = getTestPaths ( ) . filter ( p => changedPaths . some ( changedPath => changedPath . includes ( p ) ) ) ;
20+ if ( testPaths . length === 0 ) {
21+ console . log ( 'Could not find matching tests, aborting...' ) ;
22+ process . exit ( 1 ) ;
2223 }
23- } catch {
24- console . log ( 'Could not detect changed test paths, running all tests.' ) ;
2524 }
2625
2726 const cwd = path . join ( __dirname , '../' ) ;
2827 const runCount = parseInt ( process . env . TEST_RUN_COUNT || '10' ) ;
2928
30- for ( const testPath of testPaths ) {
31- console . log ( `Running test: ${ testPath } ` ) ;
32- const start = Date . now ( ) ;
29+ try {
30+ await new Promise < void > ( ( resolve , reject ) => {
31+ const cp = childProcess . spawn (
32+ `yarn playwright test ${
33+ testPaths . length ? testPaths . join ( ' ' ) : './suites'
34+ } --browser='all' --reporter='line' --repeat-each ${ runCount } `,
35+ { shell : true , cwd } ,
36+ ) ;
37+
38+ let error : Error | undefined ;
39+
40+ cp . stdout . on ( 'data' , data => {
41+ console . log ( data ? ( data as object ) . toString ( ) : '' ) ;
42+ } ) ;
3343
34- try {
35- await exec ( `yarn playwright test ${ testPath } --browser='all' --repeat-each ${ runCount } ` , {
36- cwd,
44+ cp . stderr . on ( 'data' , data => {
45+ console . log ( data ? ( data as object ) . toString ( ) : '' ) ;
3746 } ) ;
38- const end = Date . now ( ) ;
39- console . log ( ` ☑️ Passed ${ runCount } times, avg. duration ${ Math . ceil ( ( end - start ) / runCount ) } ms` ) ;
40- } catch ( error ) {
41- logError ( error ) ;
42- failed . push ( testPath ) ;
43- }
44- }
4547
46- console . log ( '' ) ;
47- console . log ( '' ) ;
48+ cp . on ( 'error' , e => {
49+ console . error ( e ) ;
50+ error = e ;
51+ } ) ;
4852
49- if ( failed . length > 0 ) {
50- console . error ( `⚠️ ${ failed . length } test(s) failed.` ) ;
53+ cp . on ( 'close' , status => {
54+ const err = error || ( status !== 0 ? new Error ( `Process exited with status ${ status } ` ) : undefined ) ;
55+
56+ if ( err ) {
57+ reject ( err ) ;
58+ } else {
59+ resolve ( ) ;
60+ }
61+ } ) ;
62+ } ) ;
63+ } catch ( error ) {
64+ console . log ( '' ) ;
65+ console . log ( '' ) ;
66+
67+ console . error ( `⚠️ Some tests failed.` ) ;
68+ console . error ( error ) ;
5169 process . exit ( 1 ) ;
52- } else {
53- console . log ( `☑️ ${ testPaths . length } test(s) passed.` ) ;
5470 }
71+
72+ console . log ( '' ) ;
73+ console . log ( '' ) ;
74+ console . log ( `☑️ All tests passed.` ) ;
5575}
5676
5777function getTestPaths ( ) : string [ ] {
0 commit comments