github.com/kvattikuti/drone@v0.2.1-0.20140603034306-d400229a327a/cmd/droned/assets/test/lib/jasmine-2.0.0/console.js (about) 1 /* 2 Copyright (c) 2008-2013 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 59 this.jasmineStarted = function() { 60 specCount = 0; 61 failureCount = 0; 62 pendingCount = 0; 63 print("Started"); 64 printNewline(); 65 timer.start(); 66 }; 67 68 this.jasmineDone = function() { 69 printNewline(); 70 for (var i = 0; i < failedSpecs.length; i++) { 71 specFailureDetails(failedSpecs[i]); 72 } 73 74 printNewline(); 75 var specCounts = specCount + " " + plural("spec", specCount) + ", " + 76 failureCount + " " + plural("failure", failureCount); 77 78 if (pendingCount) { 79 specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount); 80 } 81 82 print(specCounts); 83 84 printNewline(); 85 var seconds = timer.elapsed() / 1000; 86 print("Finished in " + seconds + " " + plural("second", seconds)); 87 88 printNewline(); 89 90 onComplete(failureCount === 0); 91 }; 92 93 this.specDone = function(result) { 94 specCount++; 95 96 if (result.status == "pending") { 97 pendingCount++; 98 print(colored("yellow", "*")); 99 return; 100 } 101 102 if (result.status == "passed") { 103 print(colored("green", '.')); 104 return; 105 } 106 107 if (result.status == "failed") { 108 failureCount++; 109 failedSpecs.push(result); 110 print(colored("red", 'F')); 111 } 112 }; 113 114 return this; 115 116 function printNewline() { 117 print("\n"); 118 } 119 120 function colored(color, str) { 121 return showColors ? (ansi[color] + str + ansi.none) : str; 122 } 123 124 function plural(str, count) { 125 return count == 1 ? str : str + "s"; 126 } 127 128 function repeat(thing, times) { 129 var arr = []; 130 for (var i = 0; i < times; i++) { 131 arr.push(thing); 132 } 133 return arr; 134 } 135 136 function indent(str, spaces) { 137 var lines = (str || '').split("\n"); 138 var newArr = []; 139 for (var i = 0; i < lines.length; i++) { 140 newArr.push(repeat(" ", spaces).join("") + lines[i]); 141 } 142 return newArr.join("\n"); 143 } 144 145 function specFailureDetails(result) { 146 printNewline(); 147 print(result.fullName); 148 149 for (var i = 0; i < result.failedExpectations.length; i++) { 150 var failedExpectation = result.failedExpectations[i]; 151 printNewline(); 152 print(indent(failedExpectation.stack, 2)); 153 } 154 155 printNewline(); 156 } 157 } 158 159 return ConsoleReporter; 160 };