Last active
August 2, 2019 11:43
-
-
Save darrinholst/bd00aa0f40d5978a84c47b012215b080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SHARD_COUNT = exports.SHARD_COUNT = +(process.env.PROTRACTOR_SHARD_COUNT || 4); | |
const _ = require('lodash'); | |
const glob = require('glob'); | |
const fs = require('fs'); | |
exports.config = _.tap(_.clone(require('./protractor.conf.js').config), function (config) { | |
config.getMultiCapabilities = function () { | |
const shards = getShardedScenarios(getAllScenarios(config.capabilities.specs)); | |
return _.map(shards, function (files, i) { | |
const shardNumber = ++i; | |
return { | |
browserName: process.env.PROTRACTOR_BROWSER || 'chrome', | |
specs: files, | |
cucumberOpts: _.tap(_.clone(config.cucumberOpts), function (options) { | |
options.format = _.map(options.format, function (format) { | |
return format.replace(/\.json/, `-${shardNumber}.json`); | |
}); | |
}) | |
}; | |
}); | |
}; | |
function getAllScenarios (specs) { | |
return _.flatten(_.map(glob.sync(specs), function (filename) { | |
return _.reduce(fs.readFileSync(filename, {encoding: 'utf8'}).split('\n'), function (memo, line, i) { | |
if (line.match(/^ *Scenario:/)) memo.push(`${filename}:${i + 1}`); | |
return memo; | |
}, []); | |
})); | |
} | |
function getShardedScenarios (allScenarios) { | |
const scenariosPerShard = Math.ceil(allScenarios.length / SHARD_COUNT); | |
return _.reduce(allScenarios, function (memo, scenario) { | |
let lastShard = _.last(memo); | |
if (lastShard.length > scenariosPerShard) { | |
lastShard = []; | |
memo.push(lastShard); | |
} | |
lastShard.push(scenario); | |
return memo; | |
}, [[]]); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.config = { | |
framework: 'custom', | |
frameworkPath: 'node_modules/protractor-cucumber-framework', | |
cucumberOpts: { | |
format: ['json:./build/test-results/protractor.json', 'pretty'], | |
require: ['features/step_definitions/**/*.js', 'features/support/**/*.js'], | |
strict: true | |
}, | |
capabilities: { | |
browserName: process.env.PROTRACTOR_BROWSER || 'chrome', | |
specs: 'features/**/*.feature' | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment