Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / karma / lib / reporters / base.js
1 var util = require('util')
2
3 var helper = require('../helper')
4
5 var BaseReporter = function (formatError, reportSlow, adapter) {
6   this.adapters = [adapter || process.stdout.write.bind(process.stdout)]
7
8   this.onRunStart = function () {
9     this._browsers = []
10   }
11
12   this.onBrowserStart = function (browser) {
13     this._browsers.push(browser)
14   }
15
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)
20
21     if (results.failed) {
22       msg += util.format(this.X_FAILED, results.failed)
23     }
24
25     if (results.skipped) {
26       msg += util.format(' (skipped %d)', results.skipped)
27     }
28
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
36       }
37
38       msg += util.format(' (%s / %s)', helper.formatTimeInterval(results.totalTime),
39         helper.formatTimeInterval(results.netTime))
40     }
41
42     return msg
43   }
44
45   this.renderBrowser = this.renderBrowser.bind(this)
46
47   this.write = function () {
48     var msg = util.format.apply(null, Array.prototype.slice.call(arguments))
49
50     this.adapters.forEach(function (adapter) {
51       adapter(msg)
52     })
53   }
54
55   this.writeCommonMsg = this.write
56
57   this.onBrowserError = function (browser, error) {
58     this.writeCommonMsg(util.format(this.ERROR, browser) + formatError(error, '  '))
59   }
60
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)
65     }
66
67     if (this._browsers && this._browsers.length === 1) {
68       this.writeCommonMsg(util.format(this.LOG_SINGLE_BROWSER, type.toUpperCase(), log))
69     } else {
70       this.writeCommonMsg(util.format(this.LOG_MULTI_BROWSER, browser, type.toUpperCase(), log))
71     }
72   }
73
74   this.onSpecComplete = function (browser, result) {
75     if (result.skipped) {
76       this.specSkipped(browser, result)
77     } else if (result.success) {
78       this.specSuccess(browser, result)
79     } else {
80       this.specFailure(browser, result)
81     }
82
83     if (reportSlow && result.time > reportSlow) {
84       var specName = result.suite.join(' ') + ' ' + result.description
85       var time = helper.formatTimeInterval(result.time)
86
87       this.writeCommonMsg(util.format(this.SPEC_SLOW, browser, time, specName))
88     }
89   }
90
91   this.specSuccess = this.specSkipped = function () {}
92
93   this.specFailure = function (browser, result) {
94     var specName = result.suite.join(' ') + ' ' + result.description
95     var msg = util.format(this.SPEC_FAILURE, browser, specName)
96
97     result.log.forEach(function (log) {
98       msg += formatError(log, '\t')
99     })
100
101     this.writeCommonMsg(msg)
102   }
103
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)
108       } else {
109         this.write(this.TOTAL_FAILED, results.failed, results.success)
110       }
111     }
112   }
113
114   this.USE_COLORS = false
115
116   this.LOG_SINGLE_BROWSER = '%s: %s\n'
117   this.LOG_MULTI_BROWSER = '%s %s: %s\n'
118
119   this.SPEC_FAILURE = '%s %s FAILED' + '\n'
120   this.SPEC_SLOW = '%s SLOW %s: %s\n'
121   this.ERROR = '%s ERROR\n'
122
123   this.FINISHED_ERROR = ' ERROR'
124   this.FINISHED_SUCCESS = ' SUCCESS'
125   this.FINISHED_DISCONNECTED = ' DISCONNECTED'
126
127   this.X_FAILED = ' (%d FAILED)'
128
129   this.TOTAL_SUCCESS = 'TOTAL: %d SUCCESS\n'
130   this.TOTAL_FAILED = 'TOTAL: %d FAILED, %d SUCCESS\n'
131 }
132
133 BaseReporter.decoratorFactory = function (formatError, reportSlow) {
134   return function (self) {
135     BaseReporter.call(self, formatError, reportSlow)
136   }
137 }
138
139 BaseReporter.decoratorFactory.$inject = ['formatError', 'config.reportSlowerThan']
140
141 // PUBLISH
142 module.exports = BaseReporter