|
108 | 108 |
|
109 | 109 | /*------------------------------------------------------------------------*/
|
110 | 110 |
|
| 111 | + /** Used to report the test module for failing tests */ |
| 112 | + var moduleName, |
| 113 | + modulePrinted; |
| 114 | + |
111 | 115 | /** Add `console.log()` support for Narwhal, Rhino, and RingoJS */
|
112 | 116 | var console = context.console || (context.console = { 'log': context.print });
|
113 | 117 |
|
| 118 | + /** Used as a horizontal rule in console output */ |
| 119 | + var hr = '----------------------------------------'; |
| 120 | + |
| 121 | + /** Used by `logInline` to clear previously logged messages */ |
| 122 | + var prevLine = ''; |
| 123 | + |
114 | 124 | /** Shorten `context.QUnit.QUnit` to `context.QUnit` */
|
115 | 125 | var QUnit = context.QUnit = context.QUnit.QUnit || context.QUnit;
|
116 | 126 |
|
117 |
| - /** Used as a horizontal rule in console output */ |
118 |
| - var hr = '----------------------------------------'; |
| 127 | + /** |
| 128 | + * Logs an inline message to standard output. |
| 129 | + * |
| 130 | + * @private |
| 131 | + * @param {string} text The text to log. |
| 132 | + */ |
| 133 | + var logInline = (function() { |
| 134 | + // exit early if not Node.js |
| 135 | + if (!(typeof process == 'object' && process && |
| 136 | + process.on && process.stdout && process.platform != 'win32')) { |
| 137 | + return function() {}; |
| 138 | + } |
| 139 | + // cleanup any inline logs when exited via `ctrl+c` |
| 140 | + process.on('SIGINT', function() { |
| 141 | + logInline(''); |
| 142 | + process.exit(); |
| 143 | + }); |
| 144 | + return function(text) { |
| 145 | + var blankLine = Array(prevLine.length + 1).join(' '); |
| 146 | + if (text.length > hr.length) { |
| 147 | + text = text.slice(0, hr.length - 3) + '...'; |
| 148 | + } |
| 149 | + prevLine = text; |
| 150 | + process.stdout.write(text + blankLine.slice(text.length) + '\r'); |
| 151 | + } |
| 152 | + }()); |
119 | 153 |
|
120 | 154 | /**
|
121 | 155 | * A logging callback triggered when all testing is completed.
|
|
133 | 167 | }
|
134 | 168 | ran = true;
|
135 | 169 |
|
| 170 | + logInline(''); |
136 | 171 | console.log(hr);
|
137 | 172 | console.log(' PASS: ' + details.passed + ' FAIL: ' + details.failed + ' TOTAL: ' + details.total);
|
138 | 173 | console.log(' Finished in ' + details.runtime + ' milliseconds.');
|
139 | 174 | console.log(hr);
|
140 | 175 |
|
141 |
| - // exit out of Narhwal, Rhino, or Ringo |
| 176 | + // exit out of Narhwal, Rhino, or RingoJS |
142 | 177 | try {
|
143 | 178 | quit();
|
144 | 179 | } catch(e) { }
|
|
186 | 221 | * @param {Object} details An object with property `name`.
|
187 | 222 | */
|
188 | 223 | QUnit.moduleStart(function(details) {
|
189 |
| - console.log(hr); |
190 |
| - console.log(details.name); |
191 |
| - console.log(hr); |
| 224 | + var newModuleName = details.name; |
| 225 | + if (moduleName != newModuleName) { |
| 226 | + moduleName = newModuleName; |
| 227 | + modulePrinted = false; |
| 228 | + } |
192 | 229 | });
|
193 | 230 |
|
194 | 231 | /**
|
|
224 | 261 | testName = details.name;
|
225 | 262 |
|
226 | 263 | if (details.failed > 0) {
|
| 264 | + logInline(''); |
| 265 | + if (!modulePrinted) { |
| 266 | + modulePrinted = true; |
| 267 | + console.log(hr); |
| 268 | + console.log(moduleName); |
| 269 | + console.log(hr); |
| 270 | + } |
227 | 271 | console.log(' FAIL - '+ testName);
|
228 | 272 | assertions.forEach(function(value) {
|
229 | 273 | console.log(' ' + value);
|
230 | 274 | });
|
231 |
| - } |
232 |
| - else { |
233 |
| - console.log(' PASS - ' + testName); |
| 275 | + } else { |
| 276 | + logInline('Testing ' + moduleName + '...'); |
234 | 277 | }
|
235 | 278 | assertions.length = 0;
|
236 | 279 | });
|
|
244 | 287 | QUnit.config.testStats = {
|
245 | 288 |
|
246 | 289 | /**
|
247 |
| - * An array of test summaries (pipe separated). |
| 290 | + * An array of test summaries. |
248 | 291 | *
|
249 | 292 | * @memberOf QUnit.config.testStats
|
250 | 293 | * @type Array
|
|
0 commit comments