Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / karma-spec-reporter / index.js
1 require('colors');
2
3 var SpecReporter = function(baseReporterDecorator, formatError, config) {
4   baseReporterDecorator(this);
5
6   this.failures = [];
7
8   // colorize output of BaseReporter functions
9   if (config.colors) {
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';
20   } else {
21     this.USE_COLORS = false;
22   }
23
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');
27
28     if (browsers.length >= 1 && !results.disconnected && !results.error) {
29       if (!results.failed) {
30         this.write(this.TOTAL_SUCCESS, results.success);
31       } else {
32         this.write(this.TOTAL_FAILED, results.failed, results.success);
33         if (!this.suppressErrorSummary) {
34           this.logFinalErrors(this.failures);
35         }
36       }
37     }
38
39     this.write("\n");
40     this.failures = [];
41     this.currentSuite = [];
42   };
43
44   this.logFinalErrors = function(errors) {
45     this.writeCommonMsg('\n\n') ;
46     this.WHITESPACE = '     ';
47
48     errors.forEach(function(failure, index) {
49       index = index + 1;
50
51       if (index > 1) {
52         this.writeCommonMsg('\n');
53       }
54
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);
59       }, this);
60     }, this);
61
62     this.writeCommonMsg('\n') ;
63   };
64
65   this.currentSuite = [];
66   this.writeSpecMessage = function(status) {
67     return (function(browser, result) {
68       var suite = result.suite;
69       var indent = "  ";
70       suite.forEach(function(value, index) {
71         if (index >= this.currentSuite.length || this.currentSuite[index] != value) {
72           if (index === 0) {
73             this.writeCommonMsg('\n');
74           }
75           this.writeCommonMsg(indent + value + '\n');
76           this.currentSuite = [];
77         }
78         indent += "  ";
79       }, this);
80       this.currentSuite = suite;
81
82       var specName = result.description;
83       //TODO: add timing information
84
85       if(this.USE_COLORS) {
86         if(result.skipped) specName = specName.cyan;
87         else if(!result.success) specName = specName.red;
88       }
89
90       var msg = indent + status + specName;
91
92       result.log.forEach(function(log) {
93         if (reporterCfg.maxLogLines) {
94           log = log.split('\n').slice(0, reporterCfg.maxLogLines).join('\n');
95         }
96         msg += '\n' + formatError(log, '\t');
97       });
98
99       this.writeCommonMsg(msg + '\n');
100
101       // other useful properties
102       browser.id;
103       browser.fullName;
104       result.time;
105       result.skipped;
106       result.success;
107     }).bind(this);
108   };
109
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);
115     } else {
116       this.write(this.LOG_MULTI_BROWSER, browser, type.toUpperCase(), this.USE_COLORS ? log.cyan : log);
117     }
118   };
119
120   var reporterCfg = config.specReporter || {};
121   var prefixes = reporterCfg.prefixes || {
122       success: '✓ ',
123       failure: '✗ ',
124       skipped: '- '
125   };
126
127   function noop(){}
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);
131   };
132
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;
137 };
138
139 SpecReporter.$inject = ['baseReporterDecorator', 'formatError', 'config'];
140
141 module.exports = {
142   'reporter:spec': ['type', SpecReporter]
143 };