ci(aio): support sharding of example e2e tests

This commit is contained in:
Peter Bacon Darwin 2017-07-27 08:31:45 +01:00 committed by Alex Rickabaugh
parent cf6284656f
commit a5e18c4cdf
1 changed files with 16 additions and 4 deletions

View File

@ -24,6 +24,11 @@ const IGNORED_EXAMPLES = [
*
* --setup run yarn install, copy boilerplate and update webdriver
* e.g. --setup
*
* --shard to shard the specs into groups to allow you to run them in parallel
* e.g. --shard=0/2 // the even specs: 0, 2, 4, etc
* e.g. --shard=1/2 // the odd specs: 1, 3, 5, etc
* e.g. --shard=1/3 // the second of every three specs: 1, 4, 7, etc
*/
function runE2e() {
let promise = Promise.resolve();
@ -41,7 +46,7 @@ function runE2e() {
const outputFile = path.join(AIO_PATH, './protractor-results.txt');
return promise
.then(() => findAndRunE2eTests(argv.filter, outputFile))
.then(() => findAndRunE2eTests(argv.filter, outputFile, argv.shard))
.then((status) => {
reportStatus(status, outputFile);
if (status.failed.length > 0) {
@ -55,7 +60,12 @@ function runE2e() {
// Finds all of the *e2e-spec.tests under the examples folder along with the corresponding apps
// that they should run under. Then run each app/spec collection sequentially.
function findAndRunE2eTests(filter, outputFile) {
function findAndRunE2eTests(filter, outputFile, shard) {
const shardParts = shard ? shard.split('/') : [0,1];
const shardModulo = parseInt(shardParts[0], 10);
const shardDivider = parseInt(shardParts[1], 10);
// create an output file with header.
const startTime = new Date().getTime();
let header = `Doc Sample Protractor Results on ${new Date().toLocaleString()}\n`;
@ -65,7 +75,9 @@ function findAndRunE2eTests(filter, outputFile) {
// Run the tests sequentially.
const status = { passed: [], failed: [] };
return getE2eSpecPaths(EXAMPLES_PATH, filter)
.then(e2eSpecPaths => e2eSpecPaths.reduce((promise, specPath) => {
.then(e2eSpecPaths => e2eSpecPaths
.filter((paths, index) => index % shardDivider === shardModulo)
.reduce((promise, specPath) => {
return promise.then(() => {
const examplePath = path.dirname(specPath);
return runE2eTests(examplePath, outputFile).then((ok) => {