github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/triage/node_modules/jasmine-core/lib/console/console.js (about) 1 /* 2 Copyright (c) 2008-2017 Pivotal Labs 3 4 Permission is hereby granted, free of charge, to any person obtaining 5 a copy of this software and associated documentation files (the 6 "Software"), to deal in the Software without restriction, including 7 without limitation the rights to use, copy, modify, merge, publish, 8 distribute, sublicense, and/or sell copies of the Software, and to 9 permit persons to whom the Software is furnished to do so, subject to 10 the following conditions: 11 12 The above copyright notice and this permission notice shall be 13 included in all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 function getJasmineRequireObj() { 24 if (typeof module !== 'undefined' && module.exports) { 25 return exports; 26 } else { 27 window.jasmineRequire = window.jasmineRequire || {}; 28 return window.jasmineRequire; 29 } 30 } 31 32 getJasmineRequireObj().console = function(jRequire, j$) { 33 j$.ConsoleReporter = jRequire.ConsoleReporter(); 34 }; 35 36 getJasmineRequireObj().ConsoleReporter = function() { 37 38 var noopTimer = { 39 start: function(){}, 40 elapsed: function(){ return 0; } 41 }; 42 43 function ConsoleReporter(options) { 44 var print = options.print, 45 showColors = options.showColors || false, 46 onComplete = options.onComplete || function() {}, 47 timer = options.timer || noopTimer, 48 specCount, 49 failureCount, 50 failedSpecs = [], 51 pendingCount, 52 ansi = { 53 green: '\x1B[32m', 54 red: '\x1B[31m', 55 yellow: '\x1B[33m', 56 none: '\x1B[0m' 57 }, 58 failedSuites = []; 59 60 print('ConsoleReporter is deprecated and will be removed in a future version.'); 61 62 this.jasmineStarted = function() { 63 specCount = 0; 64 failureCount = 0; 65 pendingCount = 0; 66 print('Started'); 67 printNewline(); 68 timer.start(); 69 }; 70 71 this.jasmineDone = function() { 72 printNewline(); 73 for (var i = 0; i < failedSpecs.length; i++) { 74 specFailureDetails(failedSpecs[i]); 75 } 76 77 if(specCount > 0) { 78 printNewline(); 79 80 var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' + 81 failureCount + ' ' + plural('failure', failureCount); 82 83 if (pendingCount) { 84 specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount); 85 } 86 87 print(specCounts); 88 } else { 89 print('No specs found'); 90 } 91 92 printNewline(); 93 var seconds = timer.elapsed() / 1000; 94 print('Finished in ' + seconds + ' ' + plural('second', seconds)); 95 printNewline(); 96 97 for(i = 0; i < failedSuites.length; i++) { 98 suiteFailureDetails(failedSuites[i]); 99 } 100 101 onComplete(failureCount === 0); 102 }; 103 104 this.specDone = function(result) { 105 specCount++; 106 107 if (result.status == 'pending') { 108 pendingCount++; 109 print(colored('yellow', '*')); 110 return; 111 } 112 113 if (result.status == 'passed') { 114 print(colored('green', '.')); 115 return; 116 } 117 118 if (result.status == 'failed') { 119 failureCount++; 120 failedSpecs.push(result); 121 print(colored('red', 'F')); 122 } 123 }; 124 125 this.suiteDone = function(result) { 126 if (result.failedExpectations && result.failedExpectations.length > 0) { 127 failureCount++; 128 failedSuites.push(result); 129 } 130 }; 131 132 return this; 133 134 function printNewline() { 135 print('\n'); 136 } 137 138 function colored(color, str) { 139 return showColors ? (ansi[color] + str + ansi.none) : str; 140 } 141 142 function plural(str, count) { 143 return count == 1 ? str : str + 's'; 144 } 145 146 function repeat(thing, times) { 147 var arr = []; 148 for (var i = 0; i < times; i++) { 149 arr.push(thing); 150 } 151 return arr; 152 } 153 154 function indent(str, spaces) { 155 var lines = (str || '').split('\n'); 156 var newArr = []; 157 for (var i = 0; i < lines.length; i++) { 158 newArr.push(repeat(' ', spaces).join('') + lines[i]); 159 } 160 return newArr.join('\n'); 161 } 162 163 function specFailureDetails(result) { 164 printNewline(); 165 print(result.fullName); 166 167 for (var i = 0; i < result.failedExpectations.length; i++) { 168 var failedExpectation = result.failedExpectations[i]; 169 printNewline(); 170 print(indent(failedExpectation.message, 2)); 171 print(indent(failedExpectation.stack, 2)); 172 } 173 174 printNewline(); 175 } 176 177 function suiteFailureDetails(result) { 178 for (var i = 0; i < result.failedExpectations.length; i++) { 179 printNewline(); 180 print(colored('red', 'An error was thrown in an afterAll')); 181 printNewline(); 182 print(colored('red', 'AfterAll ' + result.failedExpectations[i].message)); 183 184 } 185 printNewline(); 186 } 187 } 188 189 return ConsoleReporter; 190 };