Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee123 committed Jan 14, 2021
2 parents a9a8d50 + 9339a2b commit 98718cf
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 102 deletions.
51 changes: 49 additions & 2 deletions index.js
Expand Up @@ -16,6 +16,7 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {

this.failures = [];
this.USE_COLORS = false;
this.slowPokes = [];

// colorize output of BaseReporter functions
if (config.colors) {
Expand Down Expand Up @@ -46,11 +47,15 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
this.logFinalErrors(this.failures);
}
}
if (this.reportSlowerThan) {
this.logFinalSlow(this.slowPokes);
}
}

this.write('\n');
this.failures = [];
this.currentSuite = [];
this.slowPokes = [];
};

this.logFinalErrors = function (errors) {
Expand Down Expand Up @@ -78,6 +83,35 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
this.writeCommonMsg('\n');
};

this.logFinalSlow = function(slowPokes) {
this.writeCommonMsg('\n\n');
this.WHITESPACE = ' ';
slowPokes
.sort(function(next, prev) {
if (next.time > prev.time) {
return -1;
} else if (next.time < prev.time) {
return 1;
} else {
return 0;
}
})
.forEach(function(slowPoke, index) {
// Only show the top 5
if (index > 4) {
return;
}

index = index + 1;

if (index == 1) {
this.writeCommonMsg(('SLOW: ' + slowPokes.length + '\n\n').yellow);
this.writeCommonMsg(('5 Slowest: ' + '\n').yellow);
}
this.writeCommonMsg((index + ') ' + slowPoke.fullName + ' (' + slowPoke.time + ')' + '\n').yellow);
}, this);
};

this.currentSuite = [];
this.writeSpecMessage = function (status) {
return (function (browser, result) {
Expand All @@ -102,6 +136,10 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
var browserName = reporterCfg.showBrowser ? ' [' + browser.name + ']' : '';
var elapsedTime = reporterCfg.showSpecTiming ? ' (' + result.time + 'ms)' : '';

if (this.reportSlowerThan && result.time > config.reportSlowerThan) {
this.logSlowPoke(result);
}

if (this.USE_COLORS) {
if (result.skipped) specName = specName.cyan;
else if (!result.success) specName = specName.red;
Expand Down Expand Up @@ -146,12 +184,21 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
}
};

this.specSuccess = reporterCfg.suppressPassed ? noop : this.writeSpecMessage(this.USE_COLORS ? this.prefixes.success.green : this.prefixes.success);
this.specSkipped = reporterCfg.suppressSkipped ? noop : this.writeSpecMessage(this.USE_COLORS ? this.prefixes.skipped.cyan : this.prefixes.skipped);
this.logSlowPoke = function(result) {
this.slowPokes.push(result);
};

this.specSuccess = reporterCfg.suppressPassed
? noop
: this.writeSpecMessage(this.USE_COLORS ? this.prefixes.success.green : this.prefixes.success);
this.specSkipped = reporterCfg.suppressSkipped
? noop
: this.writeSpecMessage(this.USE_COLORS ? this.prefixes.skipped.cyan : this.prefixes.skipped);
this.specFailure = reporterCfg.suppressFailed ? noop : this.onSpecFailure;
this.suppressErrorSummary = reporterCfg.suppressErrorSummary || false;
this.showSpecTiming = reporterCfg.showSpecTiming || false;
this.showBrowser = reporterCfg.showBrowser || false;
this.reportSlowerThan = config.reportSlowerThan || false;
};

SpecReporter.$inject = ['baseReporterDecorator', 'formatError', 'config'];
Expand Down

0 comments on commit 98718cf

Please sign in to comment.