1 var util = require('util')
3 var helper = require('../helper')
5 var BaseReporter = function (formatError, reportSlow, adapter) {
6 this.adapters = [adapter || process.stdout.write.bind(process.stdout)]
8 this.onRunStart = function () {
12 this.onBrowserStart = function (browser) {
13 this._browsers.push(browser)
16 this.renderBrowser = function (browser) {
17 var results = browser.lastResult
18 var totalExecuted = results.success + results.failed
19 var msg = util.format('%s: Executed %d of %d', browser, totalExecuted, results.total)
22 msg += util.format(this.X_FAILED, results.failed)
25 if (results.skipped) {
26 msg += util.format(' (skipped %d)', results.skipped)
29 if (browser.isReady) {
30 if (results.disconnected) {
31 msg += this.FINISHED_DISCONNECTED
32 } else if (results.error) {
33 msg += this.FINISHED_ERROR
34 } else if (!results.failed) {
35 msg += this.FINISHED_SUCCESS
38 msg += util.format(' (%s / %s)', helper.formatTimeInterval(results.totalTime),
39 helper.formatTimeInterval(results.netTime))
45 this.renderBrowser = this.renderBrowser.bind(this)
47 this.write = function () {
48 var msg = util.format.apply(null, Array.prototype.slice.call(arguments))
50 this.adapters.forEach(function (adapter) {
55 this.writeCommonMsg = this.write
57 this.onBrowserError = function (browser, error) {
58 this.writeCommonMsg(util.format(this.ERROR, browser) + formatError(error, ' '))
61 this.onBrowserLog = function (browser, log, type) {
62 if (!helper.isString(log)) {
63 // TODO(vojta): change util to new syntax (config object)
64 log = util.inspect(log, false, undefined, this.USE_COLORS)
67 if (this._browsers && this._browsers.length === 1) {
68 this.writeCommonMsg(util.format(this.LOG_SINGLE_BROWSER, type.toUpperCase(), log))
70 this.writeCommonMsg(util.format(this.LOG_MULTI_BROWSER, browser, type.toUpperCase(), log))
74 this.onSpecComplete = function (browser, result) {
76 this.specSkipped(browser, result)
77 } else if (result.success) {
78 this.specSuccess(browser, result)
80 this.specFailure(browser, result)
83 if (reportSlow && result.time > reportSlow) {
84 var specName = result.suite.join(' ') + ' ' + result.description
85 var time = helper.formatTimeInterval(result.time)
87 this.writeCommonMsg(util.format(this.SPEC_SLOW, browser, time, specName))
91 this.specSuccess = this.specSkipped = function () {}
93 this.specFailure = function (browser, result) {
94 var specName = result.suite.join(' ') + ' ' + result.description
95 var msg = util.format(this.SPEC_FAILURE, browser, specName)
97 result.log.forEach(function (log) {
98 msg += formatError(log, '\t')
101 this.writeCommonMsg(msg)
104 this.onRunComplete = function (browsers, results) {
105 if (browsers.length > 1 && !results.error && !results.disconnected) {
106 if (!results.failed) {
107 this.write(this.TOTAL_SUCCESS, results.success)
109 this.write(this.TOTAL_FAILED, results.failed, results.success)
114 this.USE_COLORS = false
116 this.LOG_SINGLE_BROWSER = '%s: %s\n'
117 this.LOG_MULTI_BROWSER = '%s %s: %s\n'
119 this.SPEC_FAILURE = '%s %s FAILED' + '\n'
120 this.SPEC_SLOW = '%s SLOW %s: %s\n'
121 this.ERROR = '%s ERROR\n'
123 this.FINISHED_ERROR = ' ERROR'
124 this.FINISHED_SUCCESS = ' SUCCESS'
125 this.FINISHED_DISCONNECTED = ' DISCONNECTED'
127 this.X_FAILED = ' (%d FAILED)'
129 this.TOTAL_SUCCESS = 'TOTAL: %d SUCCESS\n'
130 this.TOTAL_FAILED = 'TOTAL: %d FAILED, %d SUCCESS\n'
133 BaseReporter.decoratorFactory = function (formatError, reportSlow) {
134 return function (self) {
135 BaseReporter.call(self, formatError, reportSlow)
139 BaseReporter.decoratorFactory.$inject = ['formatError', 'config.reportSlowerThan']
142 module.exports = BaseReporter