3 var SpecReporter = function(baseReporterDecorator, formatError, config) {
4 baseReporterDecorator(this);
8 // colorize output of BaseReporter functions
10 this.USE_COLORS = true;
11 this.SPEC_FAILURE = '%s %s FAILED'.red + '\n';
12 this.SPEC_SLOW = '%s SLOW %s: %s'.yellow + '\n';
13 this.ERROR = '%s ERROR'.red + '\n';
14 this.FINISHED_ERROR = ' ERROR'.red;
15 this.FINISHED_SUCCESS = ' SUCCESS'.green;
16 this.FINISHED_DISCONNECTED = ' DISCONNECTED'.red;
17 this.X_FAILED = ' (%d FAILED)'.red;
18 this.TOTAL_SUCCESS = 'TOTAL: %d SUCCESS'.green + '\n';
19 this.TOTAL_FAILED = 'TOTAL: %d FAILED, %d SUCCESS'.red + '\n';
21 this.USE_COLORS = false;
24 this.onRunComplete = function(browsers, results) {
25 // the renderBrowser function is defined in karma/reporters/Base.js
26 this.writeCommonMsg('\n' + browsers.map(this.renderBrowser).join('\n') + '\n');
28 if (browsers.length >= 1 && !results.disconnected && !results.error) {
29 if (!results.failed) {
30 this.write(this.TOTAL_SUCCESS, results.success);
32 this.write(this.TOTAL_FAILED, results.failed, results.success);
33 if (!this.suppressErrorSummary) {
34 this.logFinalErrors(this.failures);
41 this.currentSuite = [];
44 this.logFinalErrors = function(errors) {
45 this.writeCommonMsg('\n\n') ;
46 this.WHITESPACE = ' ';
48 errors.forEach(function(failure, index) {
52 this.writeCommonMsg('\n');
55 this.writeCommonMsg((index + ') ' + failure.description + '\n').red);
56 this.writeCommonMsg((this.WHITESPACE + failure.suite.join(' ') + '\n').red);
57 failure.log.forEach(function(log) {
58 this.writeCommonMsg(this.WHITESPACE + formatError(log).replace(/\\n/g, '\n').grey);
62 this.writeCommonMsg('\n') ;
65 this.currentSuite = [];
66 this.writeSpecMessage = function(status) {
67 return (function(browser, result) {
68 var suite = result.suite;
70 suite.forEach(function(value, index) {
71 if (index >= this.currentSuite.length || this.currentSuite[index] != value) {
73 this.writeCommonMsg('\n');
75 this.writeCommonMsg(indent + value + '\n');
76 this.currentSuite = [];
80 this.currentSuite = suite;
82 var specName = result.description;
83 //TODO: add timing information
86 if(result.skipped) specName = specName.cyan;
87 else if(!result.success) specName = specName.red;
90 var msg = indent + status + specName;
92 result.log.forEach(function(log) {
93 if (reporterCfg.maxLogLines) {
94 log = log.split('\n').slice(0, reporterCfg.maxLogLines).join('\n');
96 msg += '\n' + formatError(log, '\t');
99 this.writeCommonMsg(msg + '\n');
101 // other useful properties
110 this.LOG_SINGLE_BROWSER = '%s LOG: %s\n';
111 this.LOG_MULTI_BROWSER = '%s %s LOG: %s\n';
112 this.onBrowserLog = function(browser, log, type) {
113 if (this._browsers && this._browsers.length === 1) {
114 this.write(this.LOG_SINGLE_BROWSER, type.toUpperCase(), this.USE_COLORS ? log.cyan : log);
116 this.write(this.LOG_MULTI_BROWSER, browser, type.toUpperCase(), this.USE_COLORS ? log.cyan : log);
120 var reporterCfg = config.specReporter || {};
121 var prefixes = reporterCfg.prefixes || {
128 this.onSpecFailure = function(browsers, results) {
129 this.failures.push(results);
130 this.writeSpecMessage(this.USE_COLORS ? prefixes.failure.red : prefixes.failure).apply(this, arguments);
133 this.specSuccess = reporterCfg.suppressPassed ? noop : this.writeSpecMessage(this.USE_COLORS ? prefixes.success.green : prefixes.success);
134 this.specSkipped = reporterCfg.suppressSkipped ? noop : this.writeSpecMessage(this.USE_COLORS ? prefixes.skipped.cyan : prefixes.skipped);
135 this.specFailure = reporterCfg.suppressFailed ? noop : this.onSpecFailure;
136 this.suppressErrorSummary = reporterCfg.suppressErrorSummary || false;
139 SpecReporter.$inject = ['baseReporterDecorator', 'formatError', 'config'];
142 'reporter:spec': ['type', SpecReporter]