44const MARKER = "<!-- test-delta -->" ;
55const NET_CASES_TO_REPORT = 20 ;
66const TEST_FILE = / \. (?: t e s t | s p e c ) \. [ c m ] ? [ j t ] s x ? $ / ;
7- const TEST_CASE = / ^ \s * (?: i t | t e s t ) (?: \. \w + ) * \s * \( / ;
7+ // `<` admits type arguments, as in `it.each<Row>(...)`, which may span lines.
8+ const TEST_CASE = / ^ \s * (?: i t | t e s t ) (?: \. \w + ) * \s * [ ( < ] / ;
9+ const isBrowserTest = ( path ) => path . includes ( ".browser.test." ) ;
810
911function kindOf ( path ) {
10- if ( path . includes ( ".browser.test." ) ) return "browser" ;
12+ if ( isBrowserTest ( path ) ) return "browser" ;
1113 if ( path . startsWith ( "apps/server/" ) || path . includes ( ".integration." ) ) return "server" ;
1214 return "unit" ;
1315}
@@ -17,11 +19,20 @@ function countTestDelta(diff) {
1719 const kinds = { browser : 0 , server : 0 , unit : 0 } ;
1820 const newBrowserFiles = [ ] ;
1921 let path = null ;
22+ // A browser test file is new when it is added, or renamed from a file that was not one.
23+ let file = null ;
24+ const flush = ( ) => {
25+ if ( file ?. isNew && isBrowserTest ( file . target ) ) newBrowserFiles . push ( file . target ) ;
26+ } ;
2027 for ( const line of diff . split ( "\n" ) ) {
2128 if ( line . startsWith ( "diff --git " ) ) {
29+ flush ( ) ;
2230 path = null ;
31+ file = { target : line . replace ( / ^ d i f f - - g i t a \/ \S + b \/ / , "" ) , isNew : false } ;
2332 continue ;
2433 }
34+ if ( line . startsWith ( "new file mode" ) && file ) file . isNew = true ;
35+ if ( line . startsWith ( "rename from " ) && file ) file . isNew = ! isBrowserTest ( line . slice ( 12 ) ) ;
2536 if ( line . startsWith ( "--- " ) ) {
2637 const source = line . slice ( 4 ) . replace ( / ^ a \/ / , "" ) ;
2738 path = TEST_FILE . test ( source ) ? source : null ;
@@ -37,9 +48,7 @@ function countTestDelta(diff) {
3748 const sign = line [ 0 ] === "+" ? 1 : line [ 0 ] === "-" ? - 1 : 0 ;
3849 if ( sign !== 0 && TEST_CASE . test ( line . slice ( 1 ) ) ) kinds [ kindOf ( path ) ] += sign ;
3950 }
40- for ( const match of diff . matchAll ( / ^ d i f f - - g i t a \/ \S + b \/ ( \S + ) \n n e w f i l e m o d e / gm) ) {
41- if ( match [ 1 ] . includes ( ".browser.test." ) ) newBrowserFiles . push ( match [ 1 ] ) ;
42- }
51+ flush ( ) ;
4352 return { kinds, net : kinds . browser + kinds . server + kinds . unit , newBrowserFiles } ;
4453}
4554
0 commit comments