@@ -101,7 +101,9 @@ module.exports = (config) => {
101
101
} ) ;
102
102
103
103
if ( process . env [ 'CIRCLECI' ] ) {
104
- const tunnelIdentifier = process . env [ 'CIRCLE_BUILD_NUM' ] ;
104
+ const instanceIndex = Number ( process . env [ 'CIRCLE_NODE_INDEX' ] ) ;
105
+ const maxParallelInstances = Number ( process . env [ 'CIRCLE_NODE_TOTAL' ] ) ;
106
+ const tunnelIdentifier = `${ process . env [ 'CIRCLE_BUILD_NUM' ] } -${ instanceIndex } ` ;
105
107
const buildIdentifier = `angular-material-${ tunnelIdentifier } ` ;
106
108
const testPlatform = process . env [ 'TEST_PLATFORM' ] ;
107
109
@@ -110,8 +112,13 @@ module.exports = (config) => {
110
112
config . browserStack . tunnelIdentifier = tunnelIdentifier ;
111
113
}
112
114
113
- // Configure Karma launch the browsers that belong to the given test platform.
114
- config . browsers = platformMap [ testPlatform ] ;
115
+ const platformBrowsers = platformMap [ testPlatform ] ;
116
+ const browserInstanceChunks = splitBrowsersIntoInstances (
117
+ platformBrowsers , maxParallelInstances ) ;
118
+
119
+ // Configure Karma to launch the browsers that belong to the given test platform
120
+ // and instance.
121
+ config . browsers = browserInstanceChunks [ instanceIndex ] ;
115
122
}
116
123
117
124
if ( process . env [ 'TRAVIS' ] ) {
@@ -150,3 +157,21 @@ module.exports = (config) => {
150
157
config . browsers = platformMap [ platform ] ;
151
158
}
152
159
} ;
160
+
161
+ /**
162
+ * Splits the specified browsers into a maximum amount of chunks. The chunk of browsers
163
+ * are being created deterministically and therefore we get reproducible tests when executing
164
+ * the same CircleCI instance multiple times.
165
+ */
166
+ function splitBrowsersIntoInstances ( browsers , maxInstances ) {
167
+ let chunks = [ ] ;
168
+ let assignedBrowsers = 0 ;
169
+
170
+ for ( let i = 0 ; i < maxInstances ; i ++ ) {
171
+ const chunkSize = Math . floor ( ( browsers . length - assignedBrowsers ) / ( maxInstances - i ) ) ;
172
+ chunks [ i ] = browsers . slice ( assignedBrowsers , assignedBrowsers + chunkSize ) ;
173
+ assignedBrowsers += chunkSize ;
174
+ }
175
+
176
+ return chunks ;
177
+ }
0 commit comments