@@ -36,11 +36,15 @@ Error.stackTraceLimit = Infinity;
36
36
* --reuse=/path Use a path instead of create a new project. That project should have been
37
37
* created, and npm installed. Ideally you want a project created by a previous
38
38
* 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.
39
42
* If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
40
43
*/
41
44
const argv = minimist ( process . argv . slice ( 2 ) , {
42
45
'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' ]
44
48
} ) ;
45
49
46
50
@@ -73,7 +77,6 @@ ConsoleLoggerStack.start(new IndentLogger('name'))
73
77
74
78
const testGlob = argv . glob || 'tests/**/*.ts' ;
75
79
let currentFileName = null ;
76
- let index = 0 ;
77
80
78
81
const e2eRoot = path . join ( __dirname , 'e2e' ) ;
79
82
const 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:
83
86
. map ( name => path . relative ( e2eRoot , name ) )
84
87
. sort ( ) ;
85
88
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
+ } ) ;
93
104
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 ) ;
100
109
101
110
102
111
/**
@@ -111,7 +120,7 @@ if (testsToRun.length == allTests.length) {
111
120
112
121
setGlobalVariable ( 'argv' , argv ) ;
113
122
114
- testsToRun . reduce ( ( previous , relativeName ) => {
123
+ testsToRun . reduce ( ( previous , relativeName , testIndex ) => {
115
124
// Make sure this is a windows compatible path.
116
125
let absoluteName = path . join ( e2eRoot , relativeName ) ;
117
126
if ( / ^ w i n / . test ( process . platform ) ) {
@@ -131,7 +140,7 @@ testsToRun.reduce((previous, relativeName) => {
131
140
let clean = true ;
132
141
let previousDir = null ;
133
142
return Promise . resolve ( )
134
- . then ( ( ) => printHeader ( currentFileName ) )
143
+ . then ( ( ) => printHeader ( currentFileName , testIndex ) )
135
144
. then ( ( ) => previousDir = process . cwd ( ) )
136
145
. then ( ( ) => ConsoleLoggerStack . push ( currentFileName ) )
137
146
. then ( ( ) => fn ( ( ) => clean = false ) )
@@ -196,9 +205,14 @@ function isTravis() {
196
205
return process . env [ 'TRAVIS' ] ;
197
206
}
198
207
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 } )...` ) ) ;
202
216
203
217
if ( isTravis ( ) ) {
204
218
console . log ( `travis_fold:start:${ encode ( testName ) } ` ) ;
0 commit comments