From e19e071d30c952a8836c359c2936e364614bab55 Mon Sep 17 00:00:00 2001 From: Mohammed Saqib Date: Tue, 17 Apr 2018 20:31:59 -0400 Subject: [PATCH] feat: only rerun tests from past run if we fail to find specs, and allow option to not rerun all --- README.md | 4 +++- src/index.js | 12 ++++++++---- src/parse-options.js | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c3bca04..2e40bb2 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ protractorFlake({ protractorArgs: [], // specify a different protractor config to apply after the first execution attempt // either specify a config file, or cli args (ex. --capabilities.browser=chrome) - protractorRetryConfig: 'path/to/.js' + protractorRetryConfig: 'path/to/.js', + // if no specs are found to be failing, restart past attempt specs if true + allowRestartAllSpecs: true }, function (status, output) { process.exit(status); }); diff --git a/src/index.js b/src/index.js index e3fed48..0ff00b3 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ export default function (options = {}, callback = function noop () {}) { let parser = getParser(parsedOptions.parser) let logger = new Logger(parsedOptions.color) - function handleTestEnd (status, output = '') { + function handleTestEnd (status, output = '', pastSpecs = []) { if (status === 0) { callback(status) } else { @@ -33,8 +33,12 @@ export default function (options = {}, callback = function noop () {}) { if (parsedOptions.protractorRetryConfig) { logger.log('info', `Using provided protractorRetryConfig: ${parsedOptions.protractorRetryConfig}\n`) } - if (failedSpecs.length === 0) { - logger.log('info', '\nTests failed but no specs were found. All specs will be run again.\n\n') + if (failedSpecs.length === 0 && parsedOptions.allowRestartAllSpecs) { + logger.log('info', '\nTests failed but no specs were found. Specs from past attempt will be run again.\n\n') + failedSpecs = pastSpecs + } else if (failedSpecs.length === 0 && !parsedOptions.allowRestartAllSpecs) { + logger.log('info', '\nTests failed but no specs were found. Ending.') + return } else { logger.log('info', 'Re-running the following test files:\n') logger.log('info', failedSpecs.join('\n') + '\n') @@ -83,7 +87,7 @@ export default function (options = {}, callback = function noop () {}) { }) protractor.on('exit', function (status) { - handleTestEnd(status, output) + handleTestEnd(status, output, specFiles) }) } diff --git a/src/parse-options.js b/src/parse-options.js index e33d2e5..d2b626d 100644 --- a/src/parse-options.js +++ b/src/parse-options.js @@ -15,7 +15,9 @@ const DEFAULT_OPTIONS = { parser: 'standard', // specify a different protractor config to apply after the first execution attempt // either specify a config file, or cli args (ex. --capabilities.browser=chrome) - protractorRetryConfig: undefined + protractorRetryConfig: undefined, + // if no specs are found to be failing, restart past attempt specs if true + allowRestartAllSpecs: true } function parseOptions (providedOptions) {