github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/triage/node_modules/jasmine/lib/reporters/console_reporter.js (about) 1 module.exports = exports = ConsoleReporter; 2 3 var noopTimer = { 4 start: function(){}, 5 elapsed: function(){ return 0; } 6 }; 7 8 function ConsoleReporter() { 9 var print = function() {}, 10 showColors = false, 11 timer = noopTimer, 12 jasmineCorePath = null, 13 printDeprecation = function() {}, 14 specCount, 15 executableSpecCount, 16 failureCount, 17 failedSpecs = [], 18 pendingSpecs = [], 19 ansi = { 20 green: '\x1B[32m', 21 red: '\x1B[31m', 22 yellow: '\x1B[33m', 23 none: '\x1B[0m' 24 }, 25 failedSuites = [], 26 stackFilter = defaultStackFilter, 27 onComplete = function() {}; 28 29 this.setOptions = function(options) { 30 if (options.print) { 31 print = options.print; 32 } 33 showColors = options.showColors || false; 34 if (options.timer) { 35 timer = options.timer; 36 } 37 if (options.jasmineCorePath) { 38 jasmineCorePath = options.jasmineCorePath; 39 } 40 if (options.printDeprecation) { 41 printDeprecation = options.printDeprecation; 42 } 43 if (options.stackFilter) { 44 stackFilter = options.stackFilter; 45 } 46 47 if(options.onComplete) { 48 printDeprecation('Passing in an onComplete function to the ConsoleReporter is deprecated.'); 49 onComplete = options.onComplete; 50 } 51 }; 52 53 this.jasmineStarted = function(options) { 54 specCount = 0; 55 executableSpecCount = 0; 56 failureCount = 0; 57 if (options && options.order && options.order.random) { 58 print('Randomized with seed ' + options.order.seed); 59 printNewline(); 60 } 61 print('Started'); 62 printNewline(); 63 timer.start(); 64 }; 65 66 this.jasmineDone = function(result) { 67 printNewline(); 68 printNewline(); 69 if(failedSpecs.length > 0) { 70 print('Failures:'); 71 } 72 for (var i = 0; i < failedSpecs.length; i++) { 73 specFailureDetails(failedSpecs[i], i + 1); 74 } 75 76 if (pendingSpecs.length > 0) { 77 print("Pending:"); 78 } 79 for(i = 0; i < pendingSpecs.length; i++) { 80 pendingSpecDetails(pendingSpecs[i], i + 1); 81 } 82 83 if(specCount > 0) { 84 printNewline(); 85 86 if(executableSpecCount !== specCount) { 87 print('Ran ' + executableSpecCount + ' of ' + specCount + plural(' spec', specCount)); 88 printNewline(); 89 } 90 var specCounts = executableSpecCount + ' ' + plural('spec', executableSpecCount) + ', ' + 91 failureCount + ' ' + plural('failure', failureCount); 92 93 if (pendingSpecs.length) { 94 specCounts += ', ' + pendingSpecs.length + ' pending ' + plural('spec', pendingSpecs.length); 95 } 96 97 print(specCounts); 98 } else { 99 print('No specs found'); 100 } 101 102 printNewline(); 103 var seconds = timer.elapsed() / 1000; 104 print('Finished in ' + seconds + ' ' + plural('second', seconds)); 105 printNewline(); 106 107 for(i = 0; i < failedSuites.length; i++) { 108 suiteFailureDetails(failedSuites[i]); 109 } 110 111 if (result && result.failedExpectations) { 112 suiteFailureDetails(result); 113 } 114 115 if (result && result.order && result.order.random) { 116 print('Randomized with seed ' + result.order.seed); 117 printNewline(); 118 } 119 120 onComplete(failureCount === 0); 121 }; 122 123 this.specDone = function(result) { 124 specCount++; 125 126 if (result.status == 'pending') { 127 pendingSpecs.push(result); 128 executableSpecCount++; 129 print(colored('yellow', '*')); 130 return; 131 } 132 133 if (result.status == 'passed') { 134 executableSpecCount++; 135 print(colored('green', '.')); 136 return; 137 } 138 139 if (result.status == 'failed') { 140 failureCount++; 141 failedSpecs.push(result); 142 executableSpecCount++; 143 print(colored('red', 'F')); 144 } 145 }; 146 147 this.suiteDone = function(result) { 148 if (result.failedExpectations && result.failedExpectations.length > 0) { 149 failureCount++; 150 failedSuites.push(result); 151 } 152 }; 153 154 return this; 155 156 function printNewline() { 157 print('\n'); 158 } 159 160 function colored(color, str) { 161 return showColors ? (ansi[color] + str + ansi.none) : str; 162 } 163 164 function plural(str, count) { 165 return count == 1 ? str : str + 's'; 166 } 167 168 function repeat(thing, times) { 169 var arr = []; 170 for (var i = 0; i < times; i++) { 171 arr.push(thing); 172 } 173 return arr; 174 } 175 176 function indent(str, spaces) { 177 var lines = (str || '').split('\n'); 178 var newArr = []; 179 for (var i = 0; i < lines.length; i++) { 180 newArr.push(repeat(' ', spaces).join('') + lines[i]); 181 } 182 return newArr.join('\n'); 183 } 184 185 function defaultStackFilter(stack) { 186 if (!stack) { 187 return ''; 188 } 189 190 var filteredStack = stack.split('\n').filter(function(stackLine) { 191 return stackLine.indexOf(jasmineCorePath) === -1; 192 }).join('\n'); 193 return filteredStack; 194 } 195 196 function specFailureDetails(result, failedSpecNumber) { 197 printNewline(); 198 print(failedSpecNumber + ') '); 199 print(result.fullName); 200 201 for (var i = 0; i < result.failedExpectations.length; i++) { 202 var failedExpectation = result.failedExpectations[i]; 203 printNewline(); 204 print(indent('Message:', 2)); 205 printNewline(); 206 print(colored('red', indent(failedExpectation.message, 4))); 207 printNewline(); 208 print(indent('Stack:', 2)); 209 printNewline(); 210 print(indent(stackFilter(failedExpectation.stack), 4)); 211 } 212 213 printNewline(); 214 } 215 216 function suiteFailureDetails(result) { 217 for (var i = 0; i < result.failedExpectations.length; i++) { 218 printNewline(); 219 print(colored('red', 'An error was thrown in an afterAll')); 220 printNewline(); 221 print(colored('red', 'AfterAll ' + result.failedExpectations[i].message)); 222 223 } 224 printNewline(); 225 } 226 227 function pendingSpecDetails(result, pendingSpecNumber) { 228 printNewline(); 229 printNewline(); 230 print(pendingSpecNumber + ') '); 231 print(result.fullName); 232 printNewline(); 233 var pendingReason = "No reason given"; 234 if (result.pendingReason && result.pendingReason !== '') { 235 pendingReason = result.pendingReason; 236 } 237 print(indent(colored('yellow', pendingReason), 2)); 238 printNewline(); 239 } 240 }