@@ -36,11 +36,15 @@ Error.stackTraceLimit = Infinity;
3636 * --reuse=/path Use a path instead of create a new project. That project should have been
3737 * created, and npm installed. Ideally you want a project created by a previous
3838 * run of e2e.
39+ * --nb-shards Total number of shards that this is part of. Default is 2 if --shard is
40+ * passed in.
41+ * --shard Index of this processes' shard.
3942 * If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
4043 */
4144const argv = minimist ( process . argv . slice ( 2 ) , {
4245 'boolean' : [ 'debug' , 'nolink' , 'nightly' , 'noproject' , 'verbose' , 'eject' , 'appveyor' ] ,
43- 'string' : [ 'glob' , 'ignore' , 'reuse' , 'ng-sha' , ]
46+ 'string' : [ 'glob' , 'ignore' , 'reuse' , 'ng-sha' , ] ,
47+ 'number' : [ 'nb-shards' , 'shard' ]
4448} ) ;
4549
4650
@@ -73,7 +77,6 @@ ConsoleLoggerStack.start(new IndentLogger('name'))
7377
7478const testGlob = argv . glob || 'tests/**/*.ts' ;
7579let currentFileName = null ;
76- let index = 0 ;
7780
7881const e2eRoot = path . join ( __dirname , 'e2e' ) ;
7982const allSetups = glob . sync ( path . join ( e2eRoot , 'setup/**/*.ts' ) , { nodir : true } )
@@ -83,20 +86,26 @@ const allTests = glob.sync(path.join(e2eRoot, testGlob), { nodir: true, ignore:
8386 . map ( name => path . relative ( e2eRoot , name ) )
8487 . sort ( ) ;
8588
86- const testsToRun = allSetups
87- . concat ( allTests
88- . filter ( name => {
89- // Check for naming tests on command line.
90- if ( argv . _ . length == 0 ) {
91- return true ;
92- }
89+ const shardId = ( 'shard' in argv ) ? argv [ 'shard' ] : null ;
90+ const nbShards = ( shardId === null ? 1 : argv [ 'nb-shards' ] ) || 2 ;
91+ const tests = allTests
92+ . filter ( name => {
93+ // Check for naming tests on command line.
94+ if ( argv . _ . length == 0 ) {
95+ return true ;
96+ }
97+
98+ return argv . _ . some ( argName => {
99+ return path . join ( process . cwd ( ) , argName ) == path . join ( __dirname , 'e2e' , name )
100+ || argName == name
101+ || argName == name . replace ( / \. t s $ / , '' ) ;
102+ } ) ;
103+ } ) ;
93104
94- return argv . _ . some ( argName => {
95- return path . join ( process . cwd ( ) , argName ) == path . join ( __dirname , 'e2e' , name )
96- || argName == name
97- || argName == name . replace ( / \. t s $ / , '' ) ;
98- } ) ;
99- } ) ) ;
105+ // Remove tests that are not part of this shard.
106+ const shardedTests = tests
107+ . filter ( ( name , i ) => ( shardId === null || ( i % nbShards ) == shardId ) ) ;
108+ const testsToRun = allSetups . concat ( shardedTests ) ;
100109
101110
102111/**
@@ -111,7 +120,7 @@ if (testsToRun.length == allTests.length) {
111120
112121setGlobalVariable ( 'argv' , argv ) ;
113122
114- testsToRun . reduce ( ( previous , relativeName ) => {
123+ testsToRun . reduce ( ( previous , relativeName , testIndex ) => {
115124 // Make sure this is a windows compatible path.
116125 let absoluteName = path . join ( e2eRoot , relativeName ) ;
117126 if ( / ^ w i n / . test ( process . platform ) ) {
@@ -131,7 +140,7 @@ testsToRun.reduce((previous, relativeName) => {
131140 let clean = true ;
132141 let previousDir = null ;
133142 return Promise . resolve ( )
134- . then ( ( ) => printHeader ( currentFileName ) )
143+ . then ( ( ) => printHeader ( currentFileName , testIndex ) )
135144 . then ( ( ) => previousDir = process . cwd ( ) )
136145 . then ( ( ) => ConsoleLoggerStack . push ( currentFileName ) )
137146 . then ( ( ) => fn ( ( ) => clean = false ) )
@@ -196,9 +205,14 @@ function isTravis() {
196205 return process . env [ 'TRAVIS' ] ;
197206}
198207
199- function printHeader ( testName ) {
200- const text = `${ ++ index } of ${ testsToRun . length } ` ;
201- console . log ( green ( `Running "${ bold ( blue ( testName ) ) } " (${ bold ( white ( text ) ) } )...` ) ) ;
208+ function printHeader ( testName : string , testIndex : number ) {
209+ const text = `${ testIndex + 1 } of ${ testsToRun . length } ` ;
210+ const fullIndex = ( testIndex < allSetups . length ? testIndex
211+ : ( testIndex - allSetups . length ) * nbShards + shardId + allSetups . length ) + 1 ;
212+ const length = tests . length + allSetups . length ;
213+ const shard = shardId === null ? ''
214+ : yellow ( ` [${ shardId } :${ nbShards } ]` + bold ( ` (${ fullIndex } /${ length } )` ) ) ;
215+ console . log ( green ( `Running "${ bold ( blue ( testName ) ) } " (${ bold ( white ( text ) ) } ${ shard } )...` ) ) ;
202216
203217 if ( isTravis ( ) ) {
204218 console . log ( `travis_fold:start:${ encode ( testName ) } ` ) ;
0 commit comments