@@ -6,52 +6,72 @@ import { promisify } from 'util';
6
6
const exec = promisify ( childProcess . exec ) ;
7
7
8
8
async function run ( ) : Promise < void > {
9
- let testPaths = getTestPaths ( ) ;
10
- let failed = [ ] ;
9
+ let testPaths : string [ ] = [ ] ;
11
10
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 ) : [ ] ;
14
12
15
- if ( changedPaths . length > 0 ) {
16
- console . log ( `Detected changed test paths:
13
+ if ( changedPaths . length > 0 ) {
14
+ console . log ( `Detected changed test paths:
17
15
${ changedPaths . join ( '\n' ) }
18
16
19
17
` ) ;
20
18
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 ) ;
22
23
}
23
- } catch {
24
- console . log ( 'Could not detect changed test paths, running all tests.' ) ;
25
24
}
26
25
27
26
const cwd = path . join ( __dirname , '../' ) ;
28
27
const runCount = parseInt ( process . env . TEST_RUN_COUNT || '10' ) ;
29
28
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
+ } ) ;
33
43
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 ( ) : '' ) ;
37
46
} ) ;
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
- }
45
47
46
- console . log ( '' ) ;
47
- console . log ( '' ) ;
48
+ cp . on ( 'error' , e => {
49
+ console . error ( e ) ;
50
+ error = e ;
51
+ } ) ;
48
52
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 ) ;
51
69
process . exit ( 1 ) ;
52
- } else {
53
- console . log ( `☑️ ${ testPaths . length } test(s) passed.` ) ;
54
70
}
71
+
72
+ console . log ( '' ) ;
73
+ console . log ( '' ) ;
74
+ console . log ( `☑️ All tests passed.` ) ;
55
75
}
56
76
57
77
function getTestPaths ( ) : string [ ] {
0 commit comments