1 | ;(function(){ |
---|
2 | |
---|
3 | // CommonJS require() |
---|
4 | |
---|
5 | function require(p){ |
---|
6 | var path = require.resolve(p) |
---|
7 | , mod = require.modules[path]; |
---|
8 | if (!mod) throw new Error('failed to require "' + p + '"'); |
---|
9 | if (!mod.exports) { |
---|
10 | mod.exports = {}; |
---|
11 | mod.call(mod.exports, mod, mod.exports, require.relative(path)); |
---|
12 | } |
---|
13 | return mod.exports; |
---|
14 | } |
---|
15 | |
---|
16 | require.modules = {}; |
---|
17 | |
---|
18 | require.resolve = function (path){ |
---|
19 | var orig = path |
---|
20 | , reg = path + '.js' |
---|
21 | , index = path + '/index.js'; |
---|
22 | return require.modules[reg] && reg |
---|
23 | || require.modules[index] && index |
---|
24 | || orig; |
---|
25 | }; |
---|
26 | |
---|
27 | require.register = function (path, fn){ |
---|
28 | require.modules[path] = fn; |
---|
29 | }; |
---|
30 | |
---|
31 | require.relative = function (parent) { |
---|
32 | return function(p){ |
---|
33 | if ('.' != p.charAt(0)) return require(p); |
---|
34 | |
---|
35 | var path = parent.split('/') |
---|
36 | , segs = p.split('/'); |
---|
37 | path.pop(); |
---|
38 | |
---|
39 | for (var i = 0; i < segs.length; i++) { |
---|
40 | var seg = segs[i]; |
---|
41 | if ('..' == seg) path.pop(); |
---|
42 | else if ('.' != seg) path.push(seg); |
---|
43 | } |
---|
44 | |
---|
45 | return require(path.join('/')); |
---|
46 | }; |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | require.register("browser/debug.js", function(module, exports, require){ |
---|
51 | |
---|
52 | module.exports = function(type){ |
---|
53 | return function(){ |
---|
54 | } |
---|
55 | }; |
---|
56 | |
---|
57 | }); // module: browser/debug.js |
---|
58 | |
---|
59 | require.register("browser/diff.js", function(module, exports, require){ |
---|
60 | /* See LICENSE file for terms of use */ |
---|
61 | |
---|
62 | /* |
---|
63 | * Text diff implementation. |
---|
64 | * |
---|
65 | * This library supports the following APIS: |
---|
66 | * JsDiff.diffChars: Character by character diff |
---|
67 | * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace |
---|
68 | * JsDiff.diffLines: Line based diff |
---|
69 | * |
---|
70 | * JsDiff.diffCss: Diff targeted at CSS content |
---|
71 | * |
---|
72 | * These methods are based on the implementation proposed in |
---|
73 | * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986). |
---|
74 | * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 |
---|
75 | */ |
---|
76 | var JsDiff = (function() { |
---|
77 | /*jshint maxparams: 5*/ |
---|
78 | function clonePath(path) { |
---|
79 | return { newPos: path.newPos, components: path.components.slice(0) }; |
---|
80 | } |
---|
81 | function removeEmpty(array) { |
---|
82 | var ret = []; |
---|
83 | for (var i = 0; i < array.length; i++) { |
---|
84 | if (array[i]) { |
---|
85 | ret.push(array[i]); |
---|
86 | } |
---|
87 | } |
---|
88 | return ret; |
---|
89 | } |
---|
90 | function escapeHTML(s) { |
---|
91 | var n = s; |
---|
92 | n = n.replace(/&/g, '&'); |
---|
93 | n = n.replace(/</g, '<'); |
---|
94 | n = n.replace(/>/g, '>'); |
---|
95 | n = n.replace(/"/g, '"'); |
---|
96 | |
---|
97 | return n; |
---|
98 | } |
---|
99 | |
---|
100 | var Diff = function(ignoreWhitespace) { |
---|
101 | this.ignoreWhitespace = ignoreWhitespace; |
---|
102 | }; |
---|
103 | Diff.prototype = { |
---|
104 | diff: function(oldString, newString) { |
---|
105 | // Handle the identity case (this is due to unrolling editLength == 0 |
---|
106 | if (newString === oldString) { |
---|
107 | return [{ value: newString }]; |
---|
108 | } |
---|
109 | if (!newString) { |
---|
110 | return [{ value: oldString, removed: true }]; |
---|
111 | } |
---|
112 | if (!oldString) { |
---|
113 | return [{ value: newString, added: true }]; |
---|
114 | } |
---|
115 | |
---|
116 | newString = this.tokenize(newString); |
---|
117 | oldString = this.tokenize(oldString); |
---|
118 | |
---|
119 | var newLen = newString.length, oldLen = oldString.length; |
---|
120 | var maxEditLength = newLen + oldLen; |
---|
121 | var bestPath = [{ newPos: -1, components: [] }]; |
---|
122 | |
---|
123 | // Seed editLength = 0 |
---|
124 | var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0); |
---|
125 | if (bestPath[0].newPos+1 >= newLen && oldPos+1 >= oldLen) { |
---|
126 | return bestPath[0].components; |
---|
127 | } |
---|
128 | |
---|
129 | for (var editLength = 1; editLength <= maxEditLength; editLength++) { |
---|
130 | for (var diagonalPath = -1*editLength; diagonalPath <= editLength; diagonalPath+=2) { |
---|
131 | var basePath; |
---|
132 | var addPath = bestPath[diagonalPath-1], |
---|
133 | removePath = bestPath[diagonalPath+1]; |
---|
134 | oldPos = (removePath ? removePath.newPos : 0) - diagonalPath; |
---|
135 | if (addPath) { |
---|
136 | // No one else is going to attempt to use this value, clear it |
---|
137 | bestPath[diagonalPath-1] = undefined; |
---|
138 | } |
---|
139 | |
---|
140 | var canAdd = addPath && addPath.newPos+1 < newLen; |
---|
141 | var canRemove = removePath && 0 <= oldPos && oldPos < oldLen; |
---|
142 | if (!canAdd && !canRemove) { |
---|
143 | bestPath[diagonalPath] = undefined; |
---|
144 | continue; |
---|
145 | } |
---|
146 | |
---|
147 | // Select the diagonal that we want to branch from. We select the prior |
---|
148 | // path whose position in the new string is the farthest from the origin |
---|
149 | // and does not pass the bounds of the diff graph |
---|
150 | if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) { |
---|
151 | basePath = clonePath(removePath); |
---|
152 | this.pushComponent(basePath.components, oldString[oldPos], undefined, true); |
---|
153 | } else { |
---|
154 | basePath = clonePath(addPath); |
---|
155 | basePath.newPos++; |
---|
156 | this.pushComponent(basePath.components, newString[basePath.newPos], true, undefined); |
---|
157 | } |
---|
158 | |
---|
159 | var oldPos = this.extractCommon(basePath, newString, oldString, diagonalPath); |
---|
160 | |
---|
161 | if (basePath.newPos+1 >= newLen && oldPos+1 >= oldLen) { |
---|
162 | return basePath.components; |
---|
163 | } else { |
---|
164 | bestPath[diagonalPath] = basePath; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | }, |
---|
169 | |
---|
170 | pushComponent: function(components, value, added, removed) { |
---|
171 | var last = components[components.length-1]; |
---|
172 | if (last && last.added === added && last.removed === removed) { |
---|
173 | // We need to clone here as the component clone operation is just |
---|
174 | // as shallow array clone |
---|
175 | components[components.length-1] = |
---|
176 | {value: this.join(last.value, value), added: added, removed: removed }; |
---|
177 | } else { |
---|
178 | components.push({value: value, added: added, removed: removed }); |
---|
179 | } |
---|
180 | }, |
---|
181 | extractCommon: function(basePath, newString, oldString, diagonalPath) { |
---|
182 | var newLen = newString.length, |
---|
183 | oldLen = oldString.length, |
---|
184 | newPos = basePath.newPos, |
---|
185 | oldPos = newPos - diagonalPath; |
---|
186 | while (newPos+1 < newLen && oldPos+1 < oldLen && this.equals(newString[newPos+1], oldString[oldPos+1])) { |
---|
187 | newPos++; |
---|
188 | oldPos++; |
---|
189 | |
---|
190 | this.pushComponent(basePath.components, newString[newPos], undefined, undefined); |
---|
191 | } |
---|
192 | basePath.newPos = newPos; |
---|
193 | return oldPos; |
---|
194 | }, |
---|
195 | |
---|
196 | equals: function(left, right) { |
---|
197 | var reWhitespace = /\S/; |
---|
198 | if (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)) { |
---|
199 | return true; |
---|
200 | } else { |
---|
201 | return left === right; |
---|
202 | } |
---|
203 | }, |
---|
204 | join: function(left, right) { |
---|
205 | return left + right; |
---|
206 | }, |
---|
207 | tokenize: function(value) { |
---|
208 | return value; |
---|
209 | } |
---|
210 | }; |
---|
211 | |
---|
212 | var CharDiff = new Diff(); |
---|
213 | |
---|
214 | var WordDiff = new Diff(true); |
---|
215 | var WordWithSpaceDiff = new Diff(); |
---|
216 | WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) { |
---|
217 | return removeEmpty(value.split(/(\s+|\b)/)); |
---|
218 | }; |
---|
219 | |
---|
220 | var CssDiff = new Diff(true); |
---|
221 | CssDiff.tokenize = function(value) { |
---|
222 | return removeEmpty(value.split(/([{}:;,]|\s+)/)); |
---|
223 | }; |
---|
224 | |
---|
225 | var LineDiff = new Diff(); |
---|
226 | LineDiff.tokenize = function(value) { |
---|
227 | return value.split(/^/m); |
---|
228 | }; |
---|
229 | |
---|
230 | return { |
---|
231 | Diff: Diff, |
---|
232 | |
---|
233 | diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); }, |
---|
234 | diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); }, |
---|
235 | diffWordsWithSpace: function(oldStr, newStr) { return WordWithSpaceDiff.diff(oldStr, newStr); }, |
---|
236 | diffLines: function(oldStr, newStr) { return LineDiff.diff(oldStr, newStr); }, |
---|
237 | |
---|
238 | diffCss: function(oldStr, newStr) { return CssDiff.diff(oldStr, newStr); }, |
---|
239 | |
---|
240 | createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) { |
---|
241 | var ret = []; |
---|
242 | |
---|
243 | ret.push('Index: ' + fileName); |
---|
244 | ret.push('==================================================================='); |
---|
245 | ret.push('--- ' + fileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader)); |
---|
246 | ret.push('+++ ' + fileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader)); |
---|
247 | |
---|
248 | var diff = LineDiff.diff(oldStr, newStr); |
---|
249 | if (!diff[diff.length-1].value) { |
---|
250 | diff.pop(); // Remove trailing newline add |
---|
251 | } |
---|
252 | diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier |
---|
253 | |
---|
254 | function contextLines(lines) { |
---|
255 | return lines.map(function(entry) { return ' ' + entry; }); |
---|
256 | } |
---|
257 | function eofNL(curRange, i, current) { |
---|
258 | var last = diff[diff.length-2], |
---|
259 | isLast = i === diff.length-2, |
---|
260 | isLastOfType = i === diff.length-3 && (current.added !== last.added || current.removed !== last.removed); |
---|
261 | |
---|
262 | // Figure out if this is the last line for the given file and missing NL |
---|
263 | if (!/\n$/.test(current.value) && (isLast || isLastOfType)) { |
---|
264 | curRange.push('\\ No newline at end of file'); |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | var oldRangeStart = 0, newRangeStart = 0, curRange = [], |
---|
269 | oldLine = 1, newLine = 1; |
---|
270 | for (var i = 0; i < diff.length; i++) { |
---|
271 | var current = diff[i], |
---|
272 | lines = current.lines || current.value.replace(/\n$/, '').split('\n'); |
---|
273 | current.lines = lines; |
---|
274 | |
---|
275 | if (current.added || current.removed) { |
---|
276 | if (!oldRangeStart) { |
---|
277 | var prev = diff[i-1]; |
---|
278 | oldRangeStart = oldLine; |
---|
279 | newRangeStart = newLine; |
---|
280 | |
---|
281 | if (prev) { |
---|
282 | curRange = contextLines(prev.lines.slice(-4)); |
---|
283 | oldRangeStart -= curRange.length; |
---|
284 | newRangeStart -= curRange.length; |
---|
285 | } |
---|
286 | } |
---|
287 | curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?'+':'-') + entry; })); |
---|
288 | eofNL(curRange, i, current); |
---|
289 | |
---|
290 | if (current.added) { |
---|
291 | newLine += lines.length; |
---|
292 | } else { |
---|
293 | oldLine += lines.length; |
---|
294 | } |
---|
295 | } else { |
---|
296 | if (oldRangeStart) { |
---|
297 | // Close out any changes that have been output (or join overlapping) |
---|
298 | if (lines.length <= 8 && i < diff.length-2) { |
---|
299 | // Overlapping |
---|
300 | curRange.push.apply(curRange, contextLines(lines)); |
---|
301 | } else { |
---|
302 | // end the range and output |
---|
303 | var contextSize = Math.min(lines.length, 4); |
---|
304 | ret.push( |
---|
305 | '@@ -' + oldRangeStart + ',' + (oldLine-oldRangeStart+contextSize) |
---|
306 | + ' +' + newRangeStart + ',' + (newLine-newRangeStart+contextSize) |
---|
307 | + ' @@'); |
---|
308 | ret.push.apply(ret, curRange); |
---|
309 | ret.push.apply(ret, contextLines(lines.slice(0, contextSize))); |
---|
310 | if (lines.length <= 4) { |
---|
311 | eofNL(ret, i, current); |
---|
312 | } |
---|
313 | |
---|
314 | oldRangeStart = 0; newRangeStart = 0; curRange = []; |
---|
315 | } |
---|
316 | } |
---|
317 | oldLine += lines.length; |
---|
318 | newLine += lines.length; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | return ret.join('\n') + '\n'; |
---|
323 | }, |
---|
324 | |
---|
325 | applyPatch: function(oldStr, uniDiff) { |
---|
326 | var diffstr = uniDiff.split('\n'); |
---|
327 | var diff = []; |
---|
328 | var remEOFNL = false, |
---|
329 | addEOFNL = false; |
---|
330 | |
---|
331 | for (var i = (diffstr[0][0]==='I'?4:0); i < diffstr.length; i++) { |
---|
332 | if(diffstr[i][0] === '@') { |
---|
333 | var meh = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/); |
---|
334 | diff.unshift({ |
---|
335 | start:meh[3], |
---|
336 | oldlength:meh[2], |
---|
337 | oldlines:[], |
---|
338 | newlength:meh[4], |
---|
339 | newlines:[] |
---|
340 | }); |
---|
341 | } else if(diffstr[i][0] === '+') { |
---|
342 | diff[0].newlines.push(diffstr[i].substr(1)); |
---|
343 | } else if(diffstr[i][0] === '-') { |
---|
344 | diff[0].oldlines.push(diffstr[i].substr(1)); |
---|
345 | } else if(diffstr[i][0] === ' ') { |
---|
346 | diff[0].newlines.push(diffstr[i].substr(1)); |
---|
347 | diff[0].oldlines.push(diffstr[i].substr(1)); |
---|
348 | } else if(diffstr[i][0] === '\\') { |
---|
349 | if (diffstr[i-1][0] === '+') { |
---|
350 | remEOFNL = true; |
---|
351 | } else if(diffstr[i-1][0] === '-') { |
---|
352 | addEOFNL = true; |
---|
353 | } |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | var str = oldStr.split('\n'); |
---|
358 | for (var i = diff.length - 1; i >= 0; i--) { |
---|
359 | var d = diff[i]; |
---|
360 | for (var j = 0; j < d.oldlength; j++) { |
---|
361 | if(str[d.start-1+j] !== d.oldlines[j]) { |
---|
362 | return false; |
---|
363 | } |
---|
364 | } |
---|
365 | Array.prototype.splice.apply(str,[d.start-1,+d.oldlength].concat(d.newlines)); |
---|
366 | } |
---|
367 | |
---|
368 | if (remEOFNL) { |
---|
369 | while (!str[str.length-1]) { |
---|
370 | str.pop(); |
---|
371 | } |
---|
372 | } else if (addEOFNL) { |
---|
373 | str.push(''); |
---|
374 | } |
---|
375 | return str.join('\n'); |
---|
376 | }, |
---|
377 | |
---|
378 | convertChangesToXML: function(changes){ |
---|
379 | var ret = []; |
---|
380 | for ( var i = 0; i < changes.length; i++) { |
---|
381 | var change = changes[i]; |
---|
382 | if (change.added) { |
---|
383 | ret.push('<ins>'); |
---|
384 | } else if (change.removed) { |
---|
385 | ret.push('<del>'); |
---|
386 | } |
---|
387 | |
---|
388 | ret.push(escapeHTML(change.value)); |
---|
389 | |
---|
390 | if (change.added) { |
---|
391 | ret.push('</ins>'); |
---|
392 | } else if (change.removed) { |
---|
393 | ret.push('</del>'); |
---|
394 | } |
---|
395 | } |
---|
396 | return ret.join(''); |
---|
397 | }, |
---|
398 | |
---|
399 | // See: http://code.google.com/p/google-diff-match-patch/wiki/API |
---|
400 | convertChangesToDMP: function(changes){ |
---|
401 | var ret = [], change; |
---|
402 | for ( var i = 0; i < changes.length; i++) { |
---|
403 | change = changes[i]; |
---|
404 | ret.push([(change.added ? 1 : change.removed ? -1 : 0), change.value]); |
---|
405 | } |
---|
406 | return ret; |
---|
407 | } |
---|
408 | }; |
---|
409 | })(); |
---|
410 | |
---|
411 | if (typeof module !== 'undefined') { |
---|
412 | module.exports = JsDiff; |
---|
413 | } |
---|
414 | |
---|
415 | }); // module: browser/diff.js |
---|
416 | |
---|
417 | require.register("browser/events.js", function(module, exports, require){ |
---|
418 | |
---|
419 | /** |
---|
420 | * Module exports. |
---|
421 | */ |
---|
422 | |
---|
423 | exports.EventEmitter = EventEmitter; |
---|
424 | |
---|
425 | /** |
---|
426 | * Check if `obj` is an array. |
---|
427 | */ |
---|
428 | |
---|
429 | function isArray(obj) { |
---|
430 | return '[object Array]' == {}.toString.call(obj); |
---|
431 | } |
---|
432 | |
---|
433 | /** |
---|
434 | * Event emitter constructor. |
---|
435 | * |
---|
436 | * @api public |
---|
437 | */ |
---|
438 | |
---|
439 | function EventEmitter(){}; |
---|
440 | |
---|
441 | /** |
---|
442 | * Adds a listener. |
---|
443 | * |
---|
444 | * @api public |
---|
445 | */ |
---|
446 | |
---|
447 | EventEmitter.prototype.on = function (name, fn) { |
---|
448 | if (!this.$events) { |
---|
449 | this.$events = {}; |
---|
450 | } |
---|
451 | |
---|
452 | if (!this.$events[name]) { |
---|
453 | this.$events[name] = fn; |
---|
454 | } else if (isArray(this.$events[name])) { |
---|
455 | this.$events[name].push(fn); |
---|
456 | } else { |
---|
457 | this.$events[name] = [this.$events[name], fn]; |
---|
458 | } |
---|
459 | |
---|
460 | return this; |
---|
461 | }; |
---|
462 | |
---|
463 | EventEmitter.prototype.addListener = EventEmitter.prototype.on; |
---|
464 | |
---|
465 | /** |
---|
466 | * Adds a volatile listener. |
---|
467 | * |
---|
468 | * @api public |
---|
469 | */ |
---|
470 | |
---|
471 | EventEmitter.prototype.once = function (name, fn) { |
---|
472 | var self = this; |
---|
473 | |
---|
474 | function on () { |
---|
475 | self.removeListener(name, on); |
---|
476 | fn.apply(this, arguments); |
---|
477 | }; |
---|
478 | |
---|
479 | on.listener = fn; |
---|
480 | this.on(name, on); |
---|
481 | |
---|
482 | return this; |
---|
483 | }; |
---|
484 | |
---|
485 | /** |
---|
486 | * Removes a listener. |
---|
487 | * |
---|
488 | * @api public |
---|
489 | */ |
---|
490 | |
---|
491 | EventEmitter.prototype.removeListener = function (name, fn) { |
---|
492 | if (this.$events && this.$events[name]) { |
---|
493 | var list = this.$events[name]; |
---|
494 | |
---|
495 | if (isArray(list)) { |
---|
496 | var pos = -1; |
---|
497 | |
---|
498 | for (var i = 0, l = list.length; i < l; i++) { |
---|
499 | if (list[i] === fn || (list[i].listener && list[i].listener === fn)) { |
---|
500 | pos = i; |
---|
501 | break; |
---|
502 | } |
---|
503 | } |
---|
504 | |
---|
505 | if (pos < 0) { |
---|
506 | return this; |
---|
507 | } |
---|
508 | |
---|
509 | list.splice(pos, 1); |
---|
510 | |
---|
511 | if (!list.length) { |
---|
512 | delete this.$events[name]; |
---|
513 | } |
---|
514 | } else if (list === fn || (list.listener && list.listener === fn)) { |
---|
515 | delete this.$events[name]; |
---|
516 | } |
---|
517 | } |
---|
518 | |
---|
519 | return this; |
---|
520 | }; |
---|
521 | |
---|
522 | /** |
---|
523 | * Removes all listeners for an event. |
---|
524 | * |
---|
525 | * @api public |
---|
526 | */ |
---|
527 | |
---|
528 | EventEmitter.prototype.removeAllListeners = function (name) { |
---|
529 | if (name === undefined) { |
---|
530 | this.$events = {}; |
---|
531 | return this; |
---|
532 | } |
---|
533 | |
---|
534 | if (this.$events && this.$events[name]) { |
---|
535 | this.$events[name] = null; |
---|
536 | } |
---|
537 | |
---|
538 | return this; |
---|
539 | }; |
---|
540 | |
---|
541 | /** |
---|
542 | * Gets all listeners for a certain event. |
---|
543 | * |
---|
544 | * @api public |
---|
545 | */ |
---|
546 | |
---|
547 | EventEmitter.prototype.listeners = function (name) { |
---|
548 | if (!this.$events) { |
---|
549 | this.$events = {}; |
---|
550 | } |
---|
551 | |
---|
552 | if (!this.$events[name]) { |
---|
553 | this.$events[name] = []; |
---|
554 | } |
---|
555 | |
---|
556 | if (!isArray(this.$events[name])) { |
---|
557 | this.$events[name] = [this.$events[name]]; |
---|
558 | } |
---|
559 | |
---|
560 | return this.$events[name]; |
---|
561 | }; |
---|
562 | |
---|
563 | /** |
---|
564 | * Emits an event. |
---|
565 | * |
---|
566 | * @api public |
---|
567 | */ |
---|
568 | |
---|
569 | EventEmitter.prototype.emit = function (name) { |
---|
570 | if (!this.$events) { |
---|
571 | return false; |
---|
572 | } |
---|
573 | |
---|
574 | var handler = this.$events[name]; |
---|
575 | |
---|
576 | if (!handler) { |
---|
577 | return false; |
---|
578 | } |
---|
579 | |
---|
580 | var args = [].slice.call(arguments, 1); |
---|
581 | |
---|
582 | if ('function' == typeof handler) { |
---|
583 | handler.apply(this, args); |
---|
584 | } else if (isArray(handler)) { |
---|
585 | var listeners = handler.slice(); |
---|
586 | |
---|
587 | for (var i = 0, l = listeners.length; i < l; i++) { |
---|
588 | listeners[i].apply(this, args); |
---|
589 | } |
---|
590 | } else { |
---|
591 | return false; |
---|
592 | } |
---|
593 | |
---|
594 | return true; |
---|
595 | }; |
---|
596 | }); // module: browser/events.js |
---|
597 | |
---|
598 | require.register("browser/fs.js", function(module, exports, require){ |
---|
599 | |
---|
600 | }); // module: browser/fs.js |
---|
601 | |
---|
602 | require.register("browser/path.js", function(module, exports, require){ |
---|
603 | |
---|
604 | }); // module: browser/path.js |
---|
605 | |
---|
606 | require.register("browser/progress.js", function(module, exports, require){ |
---|
607 | |
---|
608 | /** |
---|
609 | * Expose `Progress`. |
---|
610 | */ |
---|
611 | |
---|
612 | module.exports = Progress; |
---|
613 | |
---|
614 | /** |
---|
615 | * Initialize a new `Progress` indicator. |
---|
616 | */ |
---|
617 | |
---|
618 | function Progress() { |
---|
619 | this.percent = 0; |
---|
620 | this.size(0); |
---|
621 | this.fontSize(11); |
---|
622 | this.font('helvetica, arial, sans-serif'); |
---|
623 | } |
---|
624 | |
---|
625 | /** |
---|
626 | * Set progress size to `n`. |
---|
627 | * |
---|
628 | * @param {Number} n |
---|
629 | * @return {Progress} for chaining |
---|
630 | * @api public |
---|
631 | */ |
---|
632 | |
---|
633 | Progress.prototype.size = function(n){ |
---|
634 | this._size = n; |
---|
635 | return this; |
---|
636 | }; |
---|
637 | |
---|
638 | /** |
---|
639 | * Set text to `str`. |
---|
640 | * |
---|
641 | * @param {String} str |
---|
642 | * @return {Progress} for chaining |
---|
643 | * @api public |
---|
644 | */ |
---|
645 | |
---|
646 | Progress.prototype.text = function(str){ |
---|
647 | this._text = str; |
---|
648 | return this; |
---|
649 | }; |
---|
650 | |
---|
651 | /** |
---|
652 | * Set font size to `n`. |
---|
653 | * |
---|
654 | * @param {Number} n |
---|
655 | * @return {Progress} for chaining |
---|
656 | * @api public |
---|
657 | */ |
---|
658 | |
---|
659 | Progress.prototype.fontSize = function(n){ |
---|
660 | this._fontSize = n; |
---|
661 | return this; |
---|
662 | }; |
---|
663 | |
---|
664 | /** |
---|
665 | * Set font `family`. |
---|
666 | * |
---|
667 | * @param {String} family |
---|
668 | * @return {Progress} for chaining |
---|
669 | */ |
---|
670 | |
---|
671 | Progress.prototype.font = function(family){ |
---|
672 | this._font = family; |
---|
673 | return this; |
---|
674 | }; |
---|
675 | |
---|
676 | /** |
---|
677 | * Update percentage to `n`. |
---|
678 | * |
---|
679 | * @param {Number} n |
---|
680 | * @return {Progress} for chaining |
---|
681 | */ |
---|
682 | |
---|
683 | Progress.prototype.update = function(n){ |
---|
684 | this.percent = n; |
---|
685 | return this; |
---|
686 | }; |
---|
687 | |
---|
688 | /** |
---|
689 | * Draw on `ctx`. |
---|
690 | * |
---|
691 | * @param {CanvasRenderingContext2d} ctx |
---|
692 | * @return {Progress} for chaining |
---|
693 | */ |
---|
694 | |
---|
695 | Progress.prototype.draw = function(ctx){ |
---|
696 | var percent = Math.min(this.percent, 100) |
---|
697 | , size = this._size |
---|
698 | , half = size / 2 |
---|
699 | , x = half |
---|
700 | , y = half |
---|
701 | , rad = half - 1 |
---|
702 | , fontSize = this._fontSize; |
---|
703 | |
---|
704 | ctx.font = fontSize + 'px ' + this._font; |
---|
705 | |
---|
706 | var angle = Math.PI * 2 * (percent / 100); |
---|
707 | ctx.clearRect(0, 0, size, size); |
---|
708 | |
---|
709 | // outer circle |
---|
710 | ctx.strokeStyle = '#9f9f9f'; |
---|
711 | ctx.beginPath(); |
---|
712 | ctx.arc(x, y, rad, 0, angle, false); |
---|
713 | ctx.stroke(); |
---|
714 | |
---|
715 | // inner circle |
---|
716 | ctx.strokeStyle = '#eee'; |
---|
717 | ctx.beginPath(); |
---|
718 | ctx.arc(x, y, rad - 1, 0, angle, true); |
---|
719 | ctx.stroke(); |
---|
720 | |
---|
721 | // text |
---|
722 | var text = this._text || (percent | 0) + '%' |
---|
723 | , w = ctx.measureText(text).width; |
---|
724 | |
---|
725 | ctx.fillText( |
---|
726 | text |
---|
727 | , x - w / 2 + 1 |
---|
728 | , y + fontSize / 2 - 1); |
---|
729 | |
---|
730 | return this; |
---|
731 | }; |
---|
732 | |
---|
733 | }); // module: browser/progress.js |
---|
734 | |
---|
735 | require.register("browser/tty.js", function(module, exports, require){ |
---|
736 | |
---|
737 | exports.isatty = function(){ |
---|
738 | return true; |
---|
739 | }; |
---|
740 | |
---|
741 | exports.getWindowSize = function(){ |
---|
742 | if ('innerHeight' in global) { |
---|
743 | return [global.innerHeight, global.innerWidth]; |
---|
744 | } else { |
---|
745 | // In a Web Worker, the DOM Window is not available. |
---|
746 | return [640, 480]; |
---|
747 | } |
---|
748 | }; |
---|
749 | |
---|
750 | }); // module: browser/tty.js |
---|
751 | |
---|
752 | require.register("context.js", function(module, exports, require){ |
---|
753 | |
---|
754 | /** |
---|
755 | * Expose `Context`. |
---|
756 | */ |
---|
757 | |
---|
758 | module.exports = Context; |
---|
759 | |
---|
760 | /** |
---|
761 | * Initialize a new `Context`. |
---|
762 | * |
---|
763 | * @api private |
---|
764 | */ |
---|
765 | |
---|
766 | function Context(){} |
---|
767 | |
---|
768 | /** |
---|
769 | * Set or get the context `Runnable` to `runnable`. |
---|
770 | * |
---|
771 | * @param {Runnable} runnable |
---|
772 | * @return {Context} |
---|
773 | * @api private |
---|
774 | */ |
---|
775 | |
---|
776 | Context.prototype.runnable = function(runnable){ |
---|
777 | if (0 == arguments.length) return this._runnable; |
---|
778 | this.test = this._runnable = runnable; |
---|
779 | return this; |
---|
780 | }; |
---|
781 | |
---|
782 | /** |
---|
783 | * Set test timeout `ms`. |
---|
784 | * |
---|
785 | * @param {Number} ms |
---|
786 | * @return {Context} self |
---|
787 | * @api private |
---|
788 | */ |
---|
789 | |
---|
790 | Context.prototype.timeout = function(ms){ |
---|
791 | this.runnable().timeout(ms); |
---|
792 | return this; |
---|
793 | }; |
---|
794 | |
---|
795 | /** |
---|
796 | * Set test slowness threshold `ms`. |
---|
797 | * |
---|
798 | * @param {Number} ms |
---|
799 | * @return {Context} self |
---|
800 | * @api private |
---|
801 | */ |
---|
802 | |
---|
803 | Context.prototype.slow = function(ms){ |
---|
804 | this.runnable().slow(ms); |
---|
805 | return this; |
---|
806 | }; |
---|
807 | |
---|
808 | /** |
---|
809 | * Inspect the context void of `._runnable`. |
---|
810 | * |
---|
811 | * @return {String} |
---|
812 | * @api private |
---|
813 | */ |
---|
814 | |
---|
815 | Context.prototype.inspect = function(){ |
---|
816 | return JSON.stringify(this, function(key, val){ |
---|
817 | if ('_runnable' == key) return; |
---|
818 | if ('test' == key) return; |
---|
819 | return val; |
---|
820 | }, 2); |
---|
821 | }; |
---|
822 | |
---|
823 | }); // module: context.js |
---|
824 | |
---|
825 | require.register("hook.js", function(module, exports, require){ |
---|
826 | |
---|
827 | /** |
---|
828 | * Module dependencies. |
---|
829 | */ |
---|
830 | |
---|
831 | var Runnable = require('./runnable'); |
---|
832 | |
---|
833 | /** |
---|
834 | * Expose `Hook`. |
---|
835 | */ |
---|
836 | |
---|
837 | module.exports = Hook; |
---|
838 | |
---|
839 | /** |
---|
840 | * Initialize a new `Hook` with the given `title` and callback `fn`. |
---|
841 | * |
---|
842 | * @param {String} title |
---|
843 | * @param {Function} fn |
---|
844 | * @api private |
---|
845 | */ |
---|
846 | |
---|
847 | function Hook(title, fn) { |
---|
848 | Runnable.call(this, title, fn); |
---|
849 | this.type = 'hook'; |
---|
850 | } |
---|
851 | |
---|
852 | /** |
---|
853 | * Inherit from `Runnable.prototype`. |
---|
854 | */ |
---|
855 | |
---|
856 | function F(){}; |
---|
857 | F.prototype = Runnable.prototype; |
---|
858 | Hook.prototype = new F; |
---|
859 | Hook.prototype.constructor = Hook; |
---|
860 | |
---|
861 | |
---|
862 | /** |
---|
863 | * Get or set the test `err`. |
---|
864 | * |
---|
865 | * @param {Error} err |
---|
866 | * @return {Error} |
---|
867 | * @api public |
---|
868 | */ |
---|
869 | |
---|
870 | Hook.prototype.error = function(err){ |
---|
871 | if (0 == arguments.length) { |
---|
872 | var err = this._error; |
---|
873 | this._error = null; |
---|
874 | return err; |
---|
875 | } |
---|
876 | |
---|
877 | this._error = err; |
---|
878 | }; |
---|
879 | |
---|
880 | }); // module: hook.js |
---|
881 | |
---|
882 | require.register("interfaces/bdd.js", function(module, exports, require){ |
---|
883 | |
---|
884 | /** |
---|
885 | * Module dependencies. |
---|
886 | */ |
---|
887 | |
---|
888 | var Suite = require('../suite') |
---|
889 | , Test = require('../test') |
---|
890 | , utils = require('../utils'); |
---|
891 | |
---|
892 | /** |
---|
893 | * BDD-style interface: |
---|
894 | * |
---|
895 | * describe('Array', function(){ |
---|
896 | * describe('#indexOf()', function(){ |
---|
897 | * it('should return -1 when not present', function(){ |
---|
898 | * |
---|
899 | * }); |
---|
900 | * |
---|
901 | * it('should return the index when present', function(){ |
---|
902 | * |
---|
903 | * }); |
---|
904 | * }); |
---|
905 | * }); |
---|
906 | * |
---|
907 | */ |
---|
908 | |
---|
909 | module.exports = function(suite){ |
---|
910 | var suites = [suite]; |
---|
911 | |
---|
912 | suite.on('pre-require', function(context, file, mocha){ |
---|
913 | |
---|
914 | /** |
---|
915 | * Execute before running tests. |
---|
916 | */ |
---|
917 | |
---|
918 | context.before = function(fn){ |
---|
919 | suites[0].beforeAll(fn); |
---|
920 | }; |
---|
921 | |
---|
922 | /** |
---|
923 | * Execute after running tests. |
---|
924 | */ |
---|
925 | |
---|
926 | context.after = function(fn){ |
---|
927 | suites[0].afterAll(fn); |
---|
928 | }; |
---|
929 | |
---|
930 | /** |
---|
931 | * Execute before each test case. |
---|
932 | */ |
---|
933 | |
---|
934 | context.beforeEach = function(fn){ |
---|
935 | suites[0].beforeEach(fn); |
---|
936 | }; |
---|
937 | |
---|
938 | /** |
---|
939 | * Execute after each test case. |
---|
940 | */ |
---|
941 | |
---|
942 | context.afterEach = function(fn){ |
---|
943 | suites[0].afterEach(fn); |
---|
944 | }; |
---|
945 | |
---|
946 | /** |
---|
947 | * Describe a "suite" with the given `title` |
---|
948 | * and callback `fn` containing nested suites |
---|
949 | * and/or tests. |
---|
950 | */ |
---|
951 | |
---|
952 | context.describe = context.context = function(title, fn){ |
---|
953 | var suite = Suite.create(suites[0], title); |
---|
954 | suites.unshift(suite); |
---|
955 | fn.call(suite); |
---|
956 | suites.shift(); |
---|
957 | return suite; |
---|
958 | }; |
---|
959 | |
---|
960 | /** |
---|
961 | * Pending describe. |
---|
962 | */ |
---|
963 | |
---|
964 | context.xdescribe = |
---|
965 | context.xcontext = |
---|
966 | context.describe.skip = function(title, fn){ |
---|
967 | var suite = Suite.create(suites[0], title); |
---|
968 | suite.pending = true; |
---|
969 | suites.unshift(suite); |
---|
970 | fn.call(suite); |
---|
971 | suites.shift(); |
---|
972 | }; |
---|
973 | |
---|
974 | /** |
---|
975 | * Exclusive suite. |
---|
976 | */ |
---|
977 | |
---|
978 | context.describe.only = function(title, fn){ |
---|
979 | var suite = context.describe(title, fn); |
---|
980 | mocha.grep(suite.fullTitle()); |
---|
981 | return suite; |
---|
982 | }; |
---|
983 | |
---|
984 | /** |
---|
985 | * Describe a specification or test-case |
---|
986 | * with the given `title` and callback `fn` |
---|
987 | * acting as a thunk. |
---|
988 | */ |
---|
989 | |
---|
990 | context.it = context.specify = function(title, fn){ |
---|
991 | var suite = suites[0]; |
---|
992 | if (suite.pending) var fn = null; |
---|
993 | var test = new Test(title, fn); |
---|
994 | suite.addTest(test); |
---|
995 | return test; |
---|
996 | }; |
---|
997 | |
---|
998 | /** |
---|
999 | * Exclusive test-case. |
---|
1000 | */ |
---|
1001 | |
---|
1002 | context.it.only = function(title, fn){ |
---|
1003 | var test = context.it(title, fn); |
---|
1004 | var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$'; |
---|
1005 | mocha.grep(new RegExp(reString)); |
---|
1006 | return test; |
---|
1007 | }; |
---|
1008 | |
---|
1009 | /** |
---|
1010 | * Pending test case. |
---|
1011 | */ |
---|
1012 | |
---|
1013 | context.xit = |
---|
1014 | context.xspecify = |
---|
1015 | context.it.skip = function(title){ |
---|
1016 | context.it(title); |
---|
1017 | }; |
---|
1018 | }); |
---|
1019 | }; |
---|
1020 | |
---|
1021 | }); // module: interfaces/bdd.js |
---|
1022 | |
---|
1023 | require.register("interfaces/exports.js", function(module, exports, require){ |
---|
1024 | |
---|
1025 | /** |
---|
1026 | * Module dependencies. |
---|
1027 | */ |
---|
1028 | |
---|
1029 | var Suite = require('../suite') |
---|
1030 | , Test = require('../test'); |
---|
1031 | |
---|
1032 | /** |
---|
1033 | * TDD-style interface: |
---|
1034 | * |
---|
1035 | * exports.Array = { |
---|
1036 | * '#indexOf()': { |
---|
1037 | * 'should return -1 when the value is not present': function(){ |
---|
1038 | * |
---|
1039 | * }, |
---|
1040 | * |
---|
1041 | * 'should return the correct index when the value is present': function(){ |
---|
1042 | * |
---|
1043 | * } |
---|
1044 | * } |
---|
1045 | * }; |
---|
1046 | * |
---|
1047 | */ |
---|
1048 | |
---|
1049 | module.exports = function(suite){ |
---|
1050 | var suites = [suite]; |
---|
1051 | |
---|
1052 | suite.on('require', visit); |
---|
1053 | |
---|
1054 | function visit(obj) { |
---|
1055 | var suite; |
---|
1056 | for (var key in obj) { |
---|
1057 | if ('function' == typeof obj[key]) { |
---|
1058 | var fn = obj[key]; |
---|
1059 | switch (key) { |
---|
1060 | case 'before': |
---|
1061 | suites[0].beforeAll(fn); |
---|
1062 | break; |
---|
1063 | case 'after': |
---|
1064 | suites[0].afterAll(fn); |
---|
1065 | break; |
---|
1066 | case 'beforeEach': |
---|
1067 | suites[0].beforeEach(fn); |
---|
1068 | break; |
---|
1069 | case 'afterEach': |
---|
1070 | suites[0].afterEach(fn); |
---|
1071 | break; |
---|
1072 | default: |
---|
1073 | suites[0].addTest(new Test(key, fn)); |
---|
1074 | } |
---|
1075 | } else { |
---|
1076 | var suite = Suite.create(suites[0], key); |
---|
1077 | suites.unshift(suite); |
---|
1078 | visit(obj[key]); |
---|
1079 | suites.shift(); |
---|
1080 | } |
---|
1081 | } |
---|
1082 | } |
---|
1083 | }; |
---|
1084 | |
---|
1085 | }); // module: interfaces/exports.js |
---|
1086 | |
---|
1087 | require.register("interfaces/index.js", function(module, exports, require){ |
---|
1088 | |
---|
1089 | exports.bdd = require('./bdd'); |
---|
1090 | exports.tdd = require('./tdd'); |
---|
1091 | exports.qunit = require('./qunit'); |
---|
1092 | exports.exports = require('./exports'); |
---|
1093 | |
---|
1094 | }); // module: interfaces/index.js |
---|
1095 | |
---|
1096 | require.register("interfaces/qunit.js", function(module, exports, require){ |
---|
1097 | |
---|
1098 | /** |
---|
1099 | * Module dependencies. |
---|
1100 | */ |
---|
1101 | |
---|
1102 | var Suite = require('../suite') |
---|
1103 | , Test = require('../test') |
---|
1104 | , utils = require('../utils'); |
---|
1105 | |
---|
1106 | /** |
---|
1107 | * QUnit-style interface: |
---|
1108 | * |
---|
1109 | * suite('Array'); |
---|
1110 | * |
---|
1111 | * test('#length', function(){ |
---|
1112 | * var arr = [1,2,3]; |
---|
1113 | * ok(arr.length == 3); |
---|
1114 | * }); |
---|
1115 | * |
---|
1116 | * test('#indexOf()', function(){ |
---|
1117 | * var arr = [1,2,3]; |
---|
1118 | * ok(arr.indexOf(1) == 0); |
---|
1119 | * ok(arr.indexOf(2) == 1); |
---|
1120 | * ok(arr.indexOf(3) == 2); |
---|
1121 | * }); |
---|
1122 | * |
---|
1123 | * suite('String'); |
---|
1124 | * |
---|
1125 | * test('#length', function(){ |
---|
1126 | * ok('foo'.length == 3); |
---|
1127 | * }); |
---|
1128 | * |
---|
1129 | */ |
---|
1130 | |
---|
1131 | module.exports = function(suite){ |
---|
1132 | var suites = [suite]; |
---|
1133 | |
---|
1134 | suite.on('pre-require', function(context, file, mocha){ |
---|
1135 | |
---|
1136 | /** |
---|
1137 | * Execute before running tests. |
---|
1138 | */ |
---|
1139 | |
---|
1140 | context.before = function(fn){ |
---|
1141 | suites[0].beforeAll(fn); |
---|
1142 | }; |
---|
1143 | |
---|
1144 | /** |
---|
1145 | * Execute after running tests. |
---|
1146 | */ |
---|
1147 | |
---|
1148 | context.after = function(fn){ |
---|
1149 | suites[0].afterAll(fn); |
---|
1150 | }; |
---|
1151 | |
---|
1152 | /** |
---|
1153 | * Execute before each test case. |
---|
1154 | */ |
---|
1155 | |
---|
1156 | context.beforeEach = function(fn){ |
---|
1157 | suites[0].beforeEach(fn); |
---|
1158 | }; |
---|
1159 | |
---|
1160 | /** |
---|
1161 | * Execute after each test case. |
---|
1162 | */ |
---|
1163 | |
---|
1164 | context.afterEach = function(fn){ |
---|
1165 | suites[0].afterEach(fn); |
---|
1166 | }; |
---|
1167 | |
---|
1168 | /** |
---|
1169 | * Describe a "suite" with the given `title`. |
---|
1170 | */ |
---|
1171 | |
---|
1172 | context.suite = function(title){ |
---|
1173 | if (suites.length > 1) suites.shift(); |
---|
1174 | var suite = Suite.create(suites[0], title); |
---|
1175 | suites.unshift(suite); |
---|
1176 | return suite; |
---|
1177 | }; |
---|
1178 | |
---|
1179 | /** |
---|
1180 | * Exclusive test-case. |
---|
1181 | */ |
---|
1182 | |
---|
1183 | context.suite.only = function(title, fn){ |
---|
1184 | var suite = context.suite(title, fn); |
---|
1185 | mocha.grep(suite.fullTitle()); |
---|
1186 | }; |
---|
1187 | |
---|
1188 | /** |
---|
1189 | * Describe a specification or test-case |
---|
1190 | * with the given `title` and callback `fn` |
---|
1191 | * acting as a thunk. |
---|
1192 | */ |
---|
1193 | |
---|
1194 | context.test = function(title, fn){ |
---|
1195 | var test = new Test(title, fn); |
---|
1196 | suites[0].addTest(test); |
---|
1197 | return test; |
---|
1198 | }; |
---|
1199 | |
---|
1200 | /** |
---|
1201 | * Exclusive test-case. |
---|
1202 | */ |
---|
1203 | |
---|
1204 | context.test.only = function(title, fn){ |
---|
1205 | var test = context.test(title, fn); |
---|
1206 | var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$'; |
---|
1207 | mocha.grep(new RegExp(reString)); |
---|
1208 | }; |
---|
1209 | |
---|
1210 | /** |
---|
1211 | * Pending test case. |
---|
1212 | */ |
---|
1213 | |
---|
1214 | context.test.skip = function(title){ |
---|
1215 | context.test(title); |
---|
1216 | }; |
---|
1217 | }); |
---|
1218 | }; |
---|
1219 | |
---|
1220 | }); // module: interfaces/qunit.js |
---|
1221 | |
---|
1222 | require.register("interfaces/tdd.js", function(module, exports, require){ |
---|
1223 | |
---|
1224 | /** |
---|
1225 | * Module dependencies. |
---|
1226 | */ |
---|
1227 | |
---|
1228 | var Suite = require('../suite') |
---|
1229 | , Test = require('../test') |
---|
1230 | , utils = require('../utils');; |
---|
1231 | |
---|
1232 | /** |
---|
1233 | * TDD-style interface: |
---|
1234 | * |
---|
1235 | * suite('Array', function(){ |
---|
1236 | * suite('#indexOf()', function(){ |
---|
1237 | * suiteSetup(function(){ |
---|
1238 | * |
---|
1239 | * }); |
---|
1240 | * |
---|
1241 | * test('should return -1 when not present', function(){ |
---|
1242 | * |
---|
1243 | * }); |
---|
1244 | * |
---|
1245 | * test('should return the index when present', function(){ |
---|
1246 | * |
---|
1247 | * }); |
---|
1248 | * |
---|
1249 | * suiteTeardown(function(){ |
---|
1250 | * |
---|
1251 | * }); |
---|
1252 | * }); |
---|
1253 | * }); |
---|
1254 | * |
---|
1255 | */ |
---|
1256 | |
---|
1257 | module.exports = function(suite){ |
---|
1258 | var suites = [suite]; |
---|
1259 | |
---|
1260 | suite.on('pre-require', function(context, file, mocha){ |
---|
1261 | |
---|
1262 | /** |
---|
1263 | * Execute before each test case. |
---|
1264 | */ |
---|
1265 | |
---|
1266 | context.setup = function(fn){ |
---|
1267 | suites[0].beforeEach(fn); |
---|
1268 | }; |
---|
1269 | |
---|
1270 | /** |
---|
1271 | * Execute after each test case. |
---|
1272 | */ |
---|
1273 | |
---|
1274 | context.teardown = function(fn){ |
---|
1275 | suites[0].afterEach(fn); |
---|
1276 | }; |
---|
1277 | |
---|
1278 | /** |
---|
1279 | * Execute before the suite. |
---|
1280 | */ |
---|
1281 | |
---|
1282 | context.suiteSetup = function(fn){ |
---|
1283 | suites[0].beforeAll(fn); |
---|
1284 | }; |
---|
1285 | |
---|
1286 | /** |
---|
1287 | * Execute after the suite. |
---|
1288 | */ |
---|
1289 | |
---|
1290 | context.suiteTeardown = function(fn){ |
---|
1291 | suites[0].afterAll(fn); |
---|
1292 | }; |
---|
1293 | |
---|
1294 | /** |
---|
1295 | * Describe a "suite" with the given `title` |
---|
1296 | * and callback `fn` containing nested suites |
---|
1297 | * and/or tests. |
---|
1298 | */ |
---|
1299 | |
---|
1300 | context.suite = function(title, fn){ |
---|
1301 | var suite = Suite.create(suites[0], title); |
---|
1302 | suites.unshift(suite); |
---|
1303 | fn.call(suite); |
---|
1304 | suites.shift(); |
---|
1305 | return suite; |
---|
1306 | }; |
---|
1307 | |
---|
1308 | /** |
---|
1309 | * Pending suite. |
---|
1310 | */ |
---|
1311 | context.suite.skip = function(title, fn) { |
---|
1312 | var suite = Suite.create(suites[0], title); |
---|
1313 | suite.pending = true; |
---|
1314 | suites.unshift(suite); |
---|
1315 | fn.call(suite); |
---|
1316 | suites.shift(); |
---|
1317 | }; |
---|
1318 | |
---|
1319 | /** |
---|
1320 | * Exclusive test-case. |
---|
1321 | */ |
---|
1322 | |
---|
1323 | context.suite.only = function(title, fn){ |
---|
1324 | var suite = context.suite(title, fn); |
---|
1325 | mocha.grep(suite.fullTitle()); |
---|
1326 | }; |
---|
1327 | |
---|
1328 | /** |
---|
1329 | * Describe a specification or test-case |
---|
1330 | * with the given `title` and callback `fn` |
---|
1331 | * acting as a thunk. |
---|
1332 | */ |
---|
1333 | |
---|
1334 | context.test = function(title, fn){ |
---|
1335 | var suite = suites[0]; |
---|
1336 | if (suite.pending) var fn = null; |
---|
1337 | var test = new Test(title, fn); |
---|
1338 | suite.addTest(test); |
---|
1339 | return test; |
---|
1340 | }; |
---|
1341 | |
---|
1342 | /** |
---|
1343 | * Exclusive test-case. |
---|
1344 | */ |
---|
1345 | |
---|
1346 | context.test.only = function(title, fn){ |
---|
1347 | var test = context.test(title, fn); |
---|
1348 | var reString = '^' + utils.escapeRegexp(test.fullTitle()) + '$'; |
---|
1349 | mocha.grep(new RegExp(reString)); |
---|
1350 | }; |
---|
1351 | |
---|
1352 | /** |
---|
1353 | * Pending test case. |
---|
1354 | */ |
---|
1355 | |
---|
1356 | context.test.skip = function(title){ |
---|
1357 | context.test(title); |
---|
1358 | }; |
---|
1359 | }); |
---|
1360 | }; |
---|
1361 | |
---|
1362 | }); // module: interfaces/tdd.js |
---|
1363 | |
---|
1364 | require.register("mocha.js", function(module, exports, require){ |
---|
1365 | /*! |
---|
1366 | * mocha |
---|
1367 | * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca> |
---|
1368 | * MIT Licensed |
---|
1369 | */ |
---|
1370 | |
---|
1371 | /** |
---|
1372 | * Module dependencies. |
---|
1373 | */ |
---|
1374 | |
---|
1375 | var path = require('browser/path') |
---|
1376 | , utils = require('./utils'); |
---|
1377 | |
---|
1378 | /** |
---|
1379 | * Expose `Mocha`. |
---|
1380 | */ |
---|
1381 | |
---|
1382 | exports = module.exports = Mocha; |
---|
1383 | |
---|
1384 | /** |
---|
1385 | * Expose internals. |
---|
1386 | */ |
---|
1387 | |
---|
1388 | exports.utils = utils; |
---|
1389 | exports.interfaces = require('./interfaces'); |
---|
1390 | exports.reporters = require('./reporters'); |
---|
1391 | exports.Runnable = require('./runnable'); |
---|
1392 | exports.Context = require('./context'); |
---|
1393 | exports.Runner = require('./runner'); |
---|
1394 | exports.Suite = require('./suite'); |
---|
1395 | exports.Hook = require('./hook'); |
---|
1396 | exports.Test = require('./test'); |
---|
1397 | |
---|
1398 | /** |
---|
1399 | * Return image `name` path. |
---|
1400 | * |
---|
1401 | * @param {String} name |
---|
1402 | * @return {String} |
---|
1403 | * @api private |
---|
1404 | */ |
---|
1405 | |
---|
1406 | function image(name) { |
---|
1407 | return __dirname + '/../images/' + name + '.png'; |
---|
1408 | } |
---|
1409 | |
---|
1410 | /** |
---|
1411 | * Setup mocha with `options`. |
---|
1412 | * |
---|
1413 | * Options: |
---|
1414 | * |
---|
1415 | * - `ui` name "bdd", "tdd", "exports" etc |
---|
1416 | * - `reporter` reporter instance, defaults to `mocha.reporters.Dot` |
---|
1417 | * - `globals` array of accepted globals |
---|
1418 | * - `timeout` timeout in milliseconds |
---|
1419 | * - `bail` bail on the first test failure |
---|
1420 | * - `slow` milliseconds to wait before considering a test slow |
---|
1421 | * - `ignoreLeaks` ignore global leaks |
---|
1422 | * - `grep` string or regexp to filter tests with |
---|
1423 | * |
---|
1424 | * @param {Object} options |
---|
1425 | * @api public |
---|
1426 | */ |
---|
1427 | |
---|
1428 | function Mocha(options) { |
---|
1429 | options = options || {}; |
---|
1430 | this.files = []; |
---|
1431 | this.options = options; |
---|
1432 | this.grep(options.grep); |
---|
1433 | this.suite = new exports.Suite('', new exports.Context); |
---|
1434 | this.ui(options.ui); |
---|
1435 | this.bail(options.bail); |
---|
1436 | this.reporter(options.reporter); |
---|
1437 | if (null != options.timeout) this.timeout(options.timeout); |
---|
1438 | this.useColors(options.useColors) |
---|
1439 | if (options.slow) this.slow(options.slow); |
---|
1440 | } |
---|
1441 | |
---|
1442 | /** |
---|
1443 | * Enable or disable bailing on the first failure. |
---|
1444 | * |
---|
1445 | * @param {Boolean} [bail] |
---|
1446 | * @api public |
---|
1447 | */ |
---|
1448 | |
---|
1449 | Mocha.prototype.bail = function(bail){ |
---|
1450 | if (0 == arguments.length) bail = true; |
---|
1451 | this.suite.bail(bail); |
---|
1452 | return this; |
---|
1453 | }; |
---|
1454 | |
---|
1455 | /** |
---|
1456 | * Add test `file`. |
---|
1457 | * |
---|
1458 | * @param {String} file |
---|
1459 | * @api public |
---|
1460 | */ |
---|
1461 | |
---|
1462 | Mocha.prototype.addFile = function(file){ |
---|
1463 | this.files.push(file); |
---|
1464 | return this; |
---|
1465 | }; |
---|
1466 | |
---|
1467 | /** |
---|
1468 | * Set reporter to `reporter`, defaults to "dot". |
---|
1469 | * |
---|
1470 | * @param {String|Function} reporter name or constructor |
---|
1471 | * @api public |
---|
1472 | */ |
---|
1473 | |
---|
1474 | Mocha.prototype.reporter = function(reporter){ |
---|
1475 | if ('function' == typeof reporter) { |
---|
1476 | this._reporter = reporter; |
---|
1477 | } else { |
---|
1478 | reporter = reporter || 'dot'; |
---|
1479 | var _reporter; |
---|
1480 | try { _reporter = require('./reporters/' + reporter); } catch (err) {}; |
---|
1481 | if (!_reporter) try { _reporter = require(reporter); } catch (err) {}; |
---|
1482 | if (!_reporter && reporter === 'teamcity') |
---|
1483 | console.warn('The Teamcity reporter was moved to a package named ' + |
---|
1484 | 'mocha-teamcity-reporter ' + |
---|
1485 | '(https://npmjs.org/package/mocha-teamcity-reporter).'); |
---|
1486 | if (!_reporter) throw new Error('invalid reporter "' + reporter + '"'); |
---|
1487 | this._reporter = _reporter; |
---|
1488 | } |
---|
1489 | return this; |
---|
1490 | }; |
---|
1491 | |
---|
1492 | /** |
---|
1493 | * Set test UI `name`, defaults to "bdd". |
---|
1494 | * |
---|
1495 | * @param {String} bdd |
---|
1496 | * @api public |
---|
1497 | */ |
---|
1498 | |
---|
1499 | Mocha.prototype.ui = function(name){ |
---|
1500 | name = name || 'bdd'; |
---|
1501 | this._ui = exports.interfaces[name]; |
---|
1502 | if (!this._ui) try { this._ui = require(name); } catch (err) {}; |
---|
1503 | if (!this._ui) throw new Error('invalid interface "' + name + '"'); |
---|
1504 | this._ui = this._ui(this.suite); |
---|
1505 | return this; |
---|
1506 | }; |
---|
1507 | |
---|
1508 | /** |
---|
1509 | * Load registered files. |
---|
1510 | * |
---|
1511 | * @api private |
---|
1512 | */ |
---|
1513 | |
---|
1514 | Mocha.prototype.loadFiles = function(fn){ |
---|
1515 | var self = this; |
---|
1516 | var suite = this.suite; |
---|
1517 | var pending = this.files.length; |
---|
1518 | this.files.forEach(function(file){ |
---|
1519 | file = path.resolve(file); |
---|
1520 | suite.emit('pre-require', global, file, self); |
---|
1521 | suite.emit('require', require(file), file, self); |
---|
1522 | suite.emit('post-require', global, file, self); |
---|
1523 | --pending || (fn && fn()); |
---|
1524 | }); |
---|
1525 | }; |
---|
1526 | |
---|
1527 | /** |
---|
1528 | * Enable growl support. |
---|
1529 | * |
---|
1530 | * @api private |
---|
1531 | */ |
---|
1532 | |
---|
1533 | Mocha.prototype._growl = function(runner, reporter) { |
---|
1534 | var notify = require('growl'); |
---|
1535 | |
---|
1536 | runner.on('end', function(){ |
---|
1537 | var stats = reporter.stats; |
---|
1538 | if (stats.failures) { |
---|
1539 | var msg = stats.failures + ' of ' + runner.total + ' tests failed'; |
---|
1540 | notify(msg, { name: 'mocha', title: 'Failed', image: image('error') }); |
---|
1541 | } else { |
---|
1542 | notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', { |
---|
1543 | name: 'mocha' |
---|
1544 | , title: 'Passed' |
---|
1545 | , image: image('ok') |
---|
1546 | }); |
---|
1547 | } |
---|
1548 | }); |
---|
1549 | }; |
---|
1550 | |
---|
1551 | /** |
---|
1552 | * Add regexp to grep, if `re` is a string it is escaped. |
---|
1553 | * |
---|
1554 | * @param {RegExp|String} re |
---|
1555 | * @return {Mocha} |
---|
1556 | * @api public |
---|
1557 | */ |
---|
1558 | |
---|
1559 | Mocha.prototype.grep = function(re){ |
---|
1560 | this.options.grep = 'string' == typeof re |
---|
1561 | ? new RegExp(utils.escapeRegexp(re)) |
---|
1562 | : re; |
---|
1563 | return this; |
---|
1564 | }; |
---|
1565 | |
---|
1566 | /** |
---|
1567 | * Invert `.grep()` matches. |
---|
1568 | * |
---|
1569 | * @return {Mocha} |
---|
1570 | * @api public |
---|
1571 | */ |
---|
1572 | |
---|
1573 | Mocha.prototype.invert = function(){ |
---|
1574 | this.options.invert = true; |
---|
1575 | return this; |
---|
1576 | }; |
---|
1577 | |
---|
1578 | /** |
---|
1579 | * Ignore global leaks. |
---|
1580 | * |
---|
1581 | * @param {Boolean} ignore |
---|
1582 | * @return {Mocha} |
---|
1583 | * @api public |
---|
1584 | */ |
---|
1585 | |
---|
1586 | Mocha.prototype.ignoreLeaks = function(ignore){ |
---|
1587 | this.options.ignoreLeaks = !!ignore; |
---|
1588 | return this; |
---|
1589 | }; |
---|
1590 | |
---|
1591 | /** |
---|
1592 | * Enable global leak checking. |
---|
1593 | * |
---|
1594 | * @return {Mocha} |
---|
1595 | * @api public |
---|
1596 | */ |
---|
1597 | |
---|
1598 | Mocha.prototype.checkLeaks = function(){ |
---|
1599 | this.options.ignoreLeaks = false; |
---|
1600 | return this; |
---|
1601 | }; |
---|
1602 | |
---|
1603 | /** |
---|
1604 | * Enable growl support. |
---|
1605 | * |
---|
1606 | * @return {Mocha} |
---|
1607 | * @api public |
---|
1608 | */ |
---|
1609 | |
---|
1610 | Mocha.prototype.growl = function(){ |
---|
1611 | this.options.growl = true; |
---|
1612 | return this; |
---|
1613 | }; |
---|
1614 | |
---|
1615 | /** |
---|
1616 | * Ignore `globals` array or string. |
---|
1617 | * |
---|
1618 | * @param {Array|String} globals |
---|
1619 | * @return {Mocha} |
---|
1620 | * @api public |
---|
1621 | */ |
---|
1622 | |
---|
1623 | Mocha.prototype.globals = function(globals){ |
---|
1624 | this.options.globals = (this.options.globals || []).concat(globals); |
---|
1625 | return this; |
---|
1626 | }; |
---|
1627 | |
---|
1628 | /** |
---|
1629 | * Emit color output. |
---|
1630 | * |
---|
1631 | * @param {Boolean} colors |
---|
1632 | * @return {Mocha} |
---|
1633 | * @api public |
---|
1634 | */ |
---|
1635 | |
---|
1636 | Mocha.prototype.useColors = function(colors){ |
---|
1637 | this.options.useColors = arguments.length && colors != undefined |
---|
1638 | ? colors |
---|
1639 | : true; |
---|
1640 | return this; |
---|
1641 | }; |
---|
1642 | |
---|
1643 | /** |
---|
1644 | * Set the timeout in milliseconds. |
---|
1645 | * |
---|
1646 | * @param {Number} timeout |
---|
1647 | * @return {Mocha} |
---|
1648 | * @api public |
---|
1649 | */ |
---|
1650 | |
---|
1651 | Mocha.prototype.timeout = function(timeout){ |
---|
1652 | this.suite.timeout(timeout); |
---|
1653 | return this; |
---|
1654 | }; |
---|
1655 | |
---|
1656 | /** |
---|
1657 | * Set slowness threshold in milliseconds. |
---|
1658 | * |
---|
1659 | * @param {Number} slow |
---|
1660 | * @return {Mocha} |
---|
1661 | * @api public |
---|
1662 | */ |
---|
1663 | |
---|
1664 | Mocha.prototype.slow = function(slow){ |
---|
1665 | this.suite.slow(slow); |
---|
1666 | return this; |
---|
1667 | }; |
---|
1668 | |
---|
1669 | /** |
---|
1670 | * Makes all tests async (accepting a callback) |
---|
1671 | * |
---|
1672 | * @return {Mocha} |
---|
1673 | * @api public |
---|
1674 | */ |
---|
1675 | |
---|
1676 | Mocha.prototype.asyncOnly = function(){ |
---|
1677 | this.options.asyncOnly = true; |
---|
1678 | return this; |
---|
1679 | }; |
---|
1680 | |
---|
1681 | /** |
---|
1682 | * Run tests and invoke `fn()` when complete. |
---|
1683 | * |
---|
1684 | * @param {Function} fn |
---|
1685 | * @return {Runner} |
---|
1686 | * @api public |
---|
1687 | */ |
---|
1688 | |
---|
1689 | Mocha.prototype.run = function(fn){ |
---|
1690 | if (this.files.length) this.loadFiles(); |
---|
1691 | var suite = this.suite; |
---|
1692 | var options = this.options; |
---|
1693 | var runner = new exports.Runner(suite); |
---|
1694 | var reporter = new this._reporter(runner); |
---|
1695 | runner.ignoreLeaks = false !== options.ignoreLeaks; |
---|
1696 | runner.asyncOnly = options.asyncOnly; |
---|
1697 | if (options.grep) runner.grep(options.grep, options.invert); |
---|
1698 | if (options.globals) runner.globals(options.globals); |
---|
1699 | if (options.growl) this._growl(runner, reporter); |
---|
1700 | exports.reporters.Base.useColors = options.useColors; |
---|
1701 | return runner.run(fn); |
---|
1702 | }; |
---|
1703 | |
---|
1704 | }); // module: mocha.js |
---|
1705 | |
---|
1706 | require.register("ms.js", function(module, exports, require){ |
---|
1707 | /** |
---|
1708 | * Helpers. |
---|
1709 | */ |
---|
1710 | |
---|
1711 | var s = 1000; |
---|
1712 | var m = s * 60; |
---|
1713 | var h = m * 60; |
---|
1714 | var d = h * 24; |
---|
1715 | var y = d * 365.25; |
---|
1716 | |
---|
1717 | /** |
---|
1718 | * Parse or format the given `val`. |
---|
1719 | * |
---|
1720 | * Options: |
---|
1721 | * |
---|
1722 | * - `long` verbose formatting [false] |
---|
1723 | * |
---|
1724 | * @param {String|Number} val |
---|
1725 | * @param {Object} options |
---|
1726 | * @return {String|Number} |
---|
1727 | * @api public |
---|
1728 | */ |
---|
1729 | |
---|
1730 | module.exports = function(val, options){ |
---|
1731 | options = options || {}; |
---|
1732 | if ('string' == typeof val) return parse(val); |
---|
1733 | return options.long |
---|
1734 | ? long(val) |
---|
1735 | : short(val); |
---|
1736 | }; |
---|
1737 | |
---|
1738 | /** |
---|
1739 | * Parse the given `str` and return milliseconds. |
---|
1740 | * |
---|
1741 | * @param {String} str |
---|
1742 | * @return {Number} |
---|
1743 | * @api private |
---|
1744 | */ |
---|
1745 | |
---|
1746 | function parse(str) { |
---|
1747 | var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str); |
---|
1748 | if (!match) return; |
---|
1749 | var n = parseFloat(match[1]); |
---|
1750 | var type = (match[2] || 'ms').toLowerCase(); |
---|
1751 | switch (type) { |
---|
1752 | case 'years': |
---|
1753 | case 'year': |
---|
1754 | case 'y': |
---|
1755 | return n * y; |
---|
1756 | case 'days': |
---|
1757 | case 'day': |
---|
1758 | case 'd': |
---|
1759 | return n * d; |
---|
1760 | case 'hours': |
---|
1761 | case 'hour': |
---|
1762 | case 'h': |
---|
1763 | return n * h; |
---|
1764 | case 'minutes': |
---|
1765 | case 'minute': |
---|
1766 | case 'm': |
---|
1767 | return n * m; |
---|
1768 | case 'seconds': |
---|
1769 | case 'second': |
---|
1770 | case 's': |
---|
1771 | return n * s; |
---|
1772 | case 'ms': |
---|
1773 | return n; |
---|
1774 | } |
---|
1775 | } |
---|
1776 | |
---|
1777 | /** |
---|
1778 | * Short format for `ms`. |
---|
1779 | * |
---|
1780 | * @param {Number} ms |
---|
1781 | * @return {String} |
---|
1782 | * @api private |
---|
1783 | */ |
---|
1784 | |
---|
1785 | function short(ms) { |
---|
1786 | if (ms >= d) return Math.round(ms / d) + 'd'; |
---|
1787 | if (ms >= h) return Math.round(ms / h) + 'h'; |
---|
1788 | if (ms >= m) return Math.round(ms / m) + 'm'; |
---|
1789 | if (ms >= s) return Math.round(ms / s) + 's'; |
---|
1790 | return ms + 'ms'; |
---|
1791 | } |
---|
1792 | |
---|
1793 | /** |
---|
1794 | * Long format for `ms`. |
---|
1795 | * |
---|
1796 | * @param {Number} ms |
---|
1797 | * @return {String} |
---|
1798 | * @api private |
---|
1799 | */ |
---|
1800 | |
---|
1801 | function long(ms) { |
---|
1802 | return plural(ms, d, 'day') |
---|
1803 | || plural(ms, h, 'hour') |
---|
1804 | || plural(ms, m, 'minute') |
---|
1805 | || plural(ms, s, 'second') |
---|
1806 | || ms + ' ms'; |
---|
1807 | } |
---|
1808 | |
---|
1809 | /** |
---|
1810 | * Pluralization helper. |
---|
1811 | */ |
---|
1812 | |
---|
1813 | function plural(ms, n, name) { |
---|
1814 | if (ms < n) return; |
---|
1815 | if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name; |
---|
1816 | return Math.ceil(ms / n) + ' ' + name + 's'; |
---|
1817 | } |
---|
1818 | |
---|
1819 | }); // module: ms.js |
---|
1820 | |
---|
1821 | require.register("reporters/base.js", function(module, exports, require){ |
---|
1822 | |
---|
1823 | /** |
---|
1824 | * Module dependencies. |
---|
1825 | */ |
---|
1826 | |
---|
1827 | var tty = require('browser/tty') |
---|
1828 | , diff = require('browser/diff') |
---|
1829 | , ms = require('../ms'); |
---|
1830 | |
---|
1831 | /** |
---|
1832 | * Save timer references to avoid Sinon interfering (see GH-237). |
---|
1833 | */ |
---|
1834 | |
---|
1835 | var Date = global.Date |
---|
1836 | , setTimeout = global.setTimeout |
---|
1837 | , setInterval = global.setInterval |
---|
1838 | , clearTimeout = global.clearTimeout |
---|
1839 | , clearInterval = global.clearInterval; |
---|
1840 | |
---|
1841 | /** |
---|
1842 | * Check if both stdio streams are associated with a tty. |
---|
1843 | */ |
---|
1844 | |
---|
1845 | var isatty = tty.isatty(1) && tty.isatty(2); |
---|
1846 | |
---|
1847 | /** |
---|
1848 | * Expose `Base`. |
---|
1849 | */ |
---|
1850 | |
---|
1851 | exports = module.exports = Base; |
---|
1852 | |
---|
1853 | /** |
---|
1854 | * Enable coloring by default. |
---|
1855 | */ |
---|
1856 | |
---|
1857 | exports.useColors = isatty || (process.env.MOCHA_COLORS !== undefined); |
---|
1858 | |
---|
1859 | /** |
---|
1860 | * Inline diffs instead of +/- |
---|
1861 | */ |
---|
1862 | |
---|
1863 | exports.inlineDiffs = false; |
---|
1864 | |
---|
1865 | /** |
---|
1866 | * Default color map. |
---|
1867 | */ |
---|
1868 | |
---|
1869 | exports.colors = { |
---|
1870 | 'pass': 90 |
---|
1871 | , 'fail': 31 |
---|
1872 | , 'bright pass': 92 |
---|
1873 | , 'bright fail': 91 |
---|
1874 | , 'bright yellow': 93 |
---|
1875 | , 'pending': 36 |
---|
1876 | , 'suite': 0 |
---|
1877 | , 'error title': 0 |
---|
1878 | , 'error message': 31 |
---|
1879 | , 'error stack': 90 |
---|
1880 | , 'checkmark': 32 |
---|
1881 | , 'fast': 90 |
---|
1882 | , 'medium': 33 |
---|
1883 | , 'slow': 31 |
---|
1884 | , 'green': 32 |
---|
1885 | , 'light': 90 |
---|
1886 | , 'diff gutter': 90 |
---|
1887 | , 'diff added': 42 |
---|
1888 | , 'diff removed': 41 |
---|
1889 | }; |
---|
1890 | |
---|
1891 | /** |
---|
1892 | * Default symbol map. |
---|
1893 | */ |
---|
1894 | |
---|
1895 | exports.symbols = { |
---|
1896 | ok: 'â', |
---|
1897 | err: 'â', |
---|
1898 | dot: 'â€' |
---|
1899 | }; |
---|
1900 | |
---|
1901 | // With node.js on Windows: use symbols available in terminal default fonts |
---|
1902 | if ('win32' == process.platform) { |
---|
1903 | exports.symbols.ok = '\u221A'; |
---|
1904 | exports.symbols.err = '\u00D7'; |
---|
1905 | exports.symbols.dot = '.'; |
---|
1906 | } |
---|
1907 | |
---|
1908 | /** |
---|
1909 | * Color `str` with the given `type`, |
---|
1910 | * allowing colors to be disabled, |
---|
1911 | * as well as user-defined color |
---|
1912 | * schemes. |
---|
1913 | * |
---|
1914 | * @param {String} type |
---|
1915 | * @param {String} str |
---|
1916 | * @return {String} |
---|
1917 | * @api private |
---|
1918 | */ |
---|
1919 | |
---|
1920 | var color = exports.color = function(type, str) { |
---|
1921 | if (!exports.useColors) return str; |
---|
1922 | return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m'; |
---|
1923 | }; |
---|
1924 | |
---|
1925 | /** |
---|
1926 | * Expose term window size, with some |
---|
1927 | * defaults for when stderr is not a tty. |
---|
1928 | */ |
---|
1929 | |
---|
1930 | exports.window = { |
---|
1931 | width: isatty |
---|
1932 | ? process.stdout.getWindowSize |
---|
1933 | ? process.stdout.getWindowSize(1)[0] |
---|
1934 | : tty.getWindowSize()[1] |
---|
1935 | : 75 |
---|
1936 | }; |
---|
1937 | |
---|
1938 | /** |
---|
1939 | * Expose some basic cursor interactions |
---|
1940 | * that are common among reporters. |
---|
1941 | */ |
---|
1942 | |
---|
1943 | exports.cursor = { |
---|
1944 | hide: function(){ |
---|
1945 | isatty && process.stdout.write('\u001b[?25l'); |
---|
1946 | }, |
---|
1947 | |
---|
1948 | show: function(){ |
---|
1949 | isatty && process.stdout.write('\u001b[?25h'); |
---|
1950 | }, |
---|
1951 | |
---|
1952 | deleteLine: function(){ |
---|
1953 | isatty && process.stdout.write('\u001b[2K'); |
---|
1954 | }, |
---|
1955 | |
---|
1956 | beginningOfLine: function(){ |
---|
1957 | isatty && process.stdout.write('\u001b[0G'); |
---|
1958 | }, |
---|
1959 | |
---|
1960 | CR: function(){ |
---|
1961 | if (isatty) { |
---|
1962 | exports.cursor.deleteLine(); |
---|
1963 | exports.cursor.beginningOfLine(); |
---|
1964 | } else { |
---|
1965 | process.stdout.write('\n'); |
---|
1966 | } |
---|
1967 | } |
---|
1968 | }; |
---|
1969 | |
---|
1970 | /** |
---|
1971 | * Outut the given `failures` as a list. |
---|
1972 | * |
---|
1973 | * @param {Array} failures |
---|
1974 | * @api public |
---|
1975 | */ |
---|
1976 | |
---|
1977 | exports.list = function(failures){ |
---|
1978 | console.error(); |
---|
1979 | failures.forEach(function(test, i){ |
---|
1980 | // format |
---|
1981 | var fmt = color('error title', ' %s) %s:\n') |
---|
1982 | + color('error message', ' %s') |
---|
1983 | + color('error stack', '\n%s\n'); |
---|
1984 | |
---|
1985 | // msg |
---|
1986 | var err = test.err |
---|
1987 | , message = err.message || '' |
---|
1988 | , stack = err.stack || message |
---|
1989 | , index = stack.indexOf(message) + message.length |
---|
1990 | , msg = stack.slice(0, index) |
---|
1991 | , actual = err.actual |
---|
1992 | , expected = err.expected |
---|
1993 | , escape = true; |
---|
1994 | |
---|
1995 | // uncaught |
---|
1996 | if (err.uncaught) { |
---|
1997 | msg = 'Uncaught ' + msg; |
---|
1998 | } |
---|
1999 | |
---|
2000 | // explicitly show diff |
---|
2001 | if (err.showDiff && sameType(actual, expected)) { |
---|
2002 | escape = false; |
---|
2003 | err.actual = actual = stringify(actual); |
---|
2004 | err.expected = expected = stringify(expected); |
---|
2005 | } |
---|
2006 | |
---|
2007 | // actual / expected diff |
---|
2008 | if ('string' == typeof actual && 'string' == typeof expected) { |
---|
2009 | fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n'); |
---|
2010 | var match = message.match(/^([^:]+): expected/); |
---|
2011 | msg = match ? '\n ' + color('error message', match[1]) : ''; |
---|
2012 | |
---|
2013 | if (exports.inlineDiffs) { |
---|
2014 | msg += inlineDiff(err, escape); |
---|
2015 | } else { |
---|
2016 | msg += unifiedDiff(err, escape); |
---|
2017 | } |
---|
2018 | } |
---|
2019 | |
---|
2020 | // indent stack trace without msg |
---|
2021 | stack = stack.slice(index ? index + 1 : index) |
---|
2022 | .replace(/^/gm, ' '); |
---|
2023 | |
---|
2024 | console.error(fmt, (i + 1), test.fullTitle(), msg, stack); |
---|
2025 | }); |
---|
2026 | }; |
---|
2027 | |
---|
2028 | /** |
---|
2029 | * Initialize a new `Base` reporter. |
---|
2030 | * |
---|
2031 | * All other reporters generally |
---|
2032 | * inherit from this reporter, providing |
---|
2033 | * stats such as test duration, number |
---|
2034 | * of tests passed / failed etc. |
---|
2035 | * |
---|
2036 | * @param {Runner} runner |
---|
2037 | * @api public |
---|
2038 | */ |
---|
2039 | |
---|
2040 | function Base(runner) { |
---|
2041 | var self = this |
---|
2042 | , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 } |
---|
2043 | , failures = this.failures = []; |
---|
2044 | |
---|
2045 | if (!runner) return; |
---|
2046 | this.runner = runner; |
---|
2047 | |
---|
2048 | runner.stats = stats; |
---|
2049 | |
---|
2050 | runner.on('start', function(){ |
---|
2051 | stats.start = new Date; |
---|
2052 | }); |
---|
2053 | |
---|
2054 | runner.on('suite', function(suite){ |
---|
2055 | stats.suites = stats.suites || 0; |
---|
2056 | suite.root || stats.suites++; |
---|
2057 | }); |
---|
2058 | |
---|
2059 | runner.on('test end', function(test){ |
---|
2060 | stats.tests = stats.tests || 0; |
---|
2061 | stats.tests++; |
---|
2062 | }); |
---|
2063 | |
---|
2064 | runner.on('pass', function(test){ |
---|
2065 | stats.passes = stats.passes || 0; |
---|
2066 | |
---|
2067 | var medium = test.slow() / 2; |
---|
2068 | test.speed = test.duration > test.slow() |
---|
2069 | ? 'slow' |
---|
2070 | : test.duration > medium |
---|
2071 | ? 'medium' |
---|
2072 | : 'fast'; |
---|
2073 | |
---|
2074 | stats.passes++; |
---|
2075 | }); |
---|
2076 | |
---|
2077 | runner.on('fail', function(test, err){ |
---|
2078 | stats.failures = stats.failures || 0; |
---|
2079 | stats.failures++; |
---|
2080 | test.err = err; |
---|
2081 | failures.push(test); |
---|
2082 | }); |
---|
2083 | |
---|
2084 | runner.on('end', function(){ |
---|
2085 | stats.end = new Date; |
---|
2086 | stats.duration = new Date - stats.start; |
---|
2087 | }); |
---|
2088 | |
---|
2089 | runner.on('pending', function(){ |
---|
2090 | stats.pending++; |
---|
2091 | }); |
---|
2092 | } |
---|
2093 | |
---|
2094 | /** |
---|
2095 | * Output common epilogue used by many of |
---|
2096 | * the bundled reporters. |
---|
2097 | * |
---|
2098 | * @api public |
---|
2099 | */ |
---|
2100 | |
---|
2101 | Base.prototype.epilogue = function(){ |
---|
2102 | var stats = this.stats; |
---|
2103 | var tests; |
---|
2104 | var fmt; |
---|
2105 | |
---|
2106 | console.log(); |
---|
2107 | |
---|
2108 | // passes |
---|
2109 | fmt = color('bright pass', ' ') |
---|
2110 | + color('green', ' %d passing') |
---|
2111 | + color('light', ' (%s)'); |
---|
2112 | |
---|
2113 | console.log(fmt, |
---|
2114 | stats.passes || 0, |
---|
2115 | ms(stats.duration)); |
---|
2116 | |
---|
2117 | // pending |
---|
2118 | if (stats.pending) { |
---|
2119 | fmt = color('pending', ' ') |
---|
2120 | + color('pending', ' %d pending'); |
---|
2121 | |
---|
2122 | console.log(fmt, stats.pending); |
---|
2123 | } |
---|
2124 | |
---|
2125 | // failures |
---|
2126 | if (stats.failures) { |
---|
2127 | fmt = color('fail', ' %d failing'); |
---|
2128 | |
---|
2129 | console.error(fmt, |
---|
2130 | stats.failures); |
---|
2131 | |
---|
2132 | Base.list(this.failures); |
---|
2133 | console.error(); |
---|
2134 | } |
---|
2135 | |
---|
2136 | console.log(); |
---|
2137 | }; |
---|
2138 | |
---|
2139 | /** |
---|
2140 | * Pad the given `str` to `len`. |
---|
2141 | * |
---|
2142 | * @param {String} str |
---|
2143 | * @param {String} len |
---|
2144 | * @return {String} |
---|
2145 | * @api private |
---|
2146 | */ |
---|
2147 | |
---|
2148 | function pad(str, len) { |
---|
2149 | str = String(str); |
---|
2150 | return Array(len - str.length + 1).join(' ') + str; |
---|
2151 | } |
---|
2152 | |
---|
2153 | |
---|
2154 | /** |
---|
2155 | * Returns an inline diff between 2 strings with coloured ANSI output |
---|
2156 | * |
---|
2157 | * @param {Error} Error with actual/expected |
---|
2158 | * @return {String} Diff |
---|
2159 | * @api private |
---|
2160 | */ |
---|
2161 | |
---|
2162 | function inlineDiff(err, escape) { |
---|
2163 | var msg = errorDiff(err, 'WordsWithSpace', escape); |
---|
2164 | |
---|
2165 | // linenos |
---|
2166 | var lines = msg.split('\n'); |
---|
2167 | if (lines.length > 4) { |
---|
2168 | var width = String(lines.length).length; |
---|
2169 | msg = lines.map(function(str, i){ |
---|
2170 | return pad(++i, width) + ' |' + ' ' + str; |
---|
2171 | }).join('\n'); |
---|
2172 | } |
---|
2173 | |
---|
2174 | // legend |
---|
2175 | msg = '\n' |
---|
2176 | + color('diff removed', 'actual') |
---|
2177 | + ' ' |
---|
2178 | + color('diff added', 'expected') |
---|
2179 | + '\n\n' |
---|
2180 | + msg |
---|
2181 | + '\n'; |
---|
2182 | |
---|
2183 | // indent |
---|
2184 | msg = msg.replace(/^/gm, ' '); |
---|
2185 | return msg; |
---|
2186 | } |
---|
2187 | |
---|
2188 | /** |
---|
2189 | * Returns a unified diff between 2 strings |
---|
2190 | * |
---|
2191 | * @param {Error} Error with actual/expected |
---|
2192 | * @return {String} Diff |
---|
2193 | * @api private |
---|
2194 | */ |
---|
2195 | |
---|
2196 | function unifiedDiff(err, escape) { |
---|
2197 | var indent = ' '; |
---|
2198 | function cleanUp(line) { |
---|
2199 | if (escape) { |
---|
2200 | line = escapeInvisibles(line); |
---|
2201 | } |
---|
2202 | if (line[0] === '+') return indent + colorLines('diff added', line); |
---|
2203 | if (line[0] === '-') return indent + colorLines('diff removed', line); |
---|
2204 | if (line.match(/\@\@/)) return null; |
---|
2205 | if (line.match(/\\ No newline/)) return null; |
---|
2206 | else return indent + line; |
---|
2207 | } |
---|
2208 | function notBlank(line) { |
---|
2209 | return line != null; |
---|
2210 | } |
---|
2211 | msg = diff.createPatch('string', err.actual, err.expected); |
---|
2212 | var lines = msg.split('\n').splice(4); |
---|
2213 | return '\n ' |
---|
2214 | + colorLines('diff added', '+ expected') + ' ' |
---|
2215 | + colorLines('diff removed', '- actual') |
---|
2216 | + '\n\n' |
---|
2217 | + lines.map(cleanUp).filter(notBlank).join('\n'); |
---|
2218 | } |
---|
2219 | |
---|
2220 | /** |
---|
2221 | * Return a character diff for `err`. |
---|
2222 | * |
---|
2223 | * @param {Error} err |
---|
2224 | * @return {String} |
---|
2225 | * @api private |
---|
2226 | */ |
---|
2227 | |
---|
2228 | function errorDiff(err, type, escape) { |
---|
2229 | var actual = escape ? escapeInvisibles(err.actual) : err.actual; |
---|
2230 | var expected = escape ? escapeInvisibles(err.expected) : err.expected; |
---|
2231 | return diff['diff' + type](actual, expected).map(function(str){ |
---|
2232 | if (str.added) return colorLines('diff added', str.value); |
---|
2233 | if (str.removed) return colorLines('diff removed', str.value); |
---|
2234 | return str.value; |
---|
2235 | }).join(''); |
---|
2236 | } |
---|
2237 | |
---|
2238 | /** |
---|
2239 | * Returns a string with all invisible characters in plain text |
---|
2240 | * |
---|
2241 | * @param {String} line |
---|
2242 | * @return {String} |
---|
2243 | * @api private |
---|
2244 | */ |
---|
2245 | function escapeInvisibles(line) { |
---|
2246 | return line.replace(/\t/g, '<tab>') |
---|
2247 | .replace(/\r/g, '<CR>') |
---|
2248 | .replace(/\n/g, '<LF>\n'); |
---|
2249 | } |
---|
2250 | |
---|
2251 | /** |
---|
2252 | * Color lines for `str`, using the color `name`. |
---|
2253 | * |
---|
2254 | * @param {String} name |
---|
2255 | * @param {String} str |
---|
2256 | * @return {String} |
---|
2257 | * @api private |
---|
2258 | */ |
---|
2259 | |
---|
2260 | function colorLines(name, str) { |
---|
2261 | return str.split('\n').map(function(str){ |
---|
2262 | return color(name, str); |
---|
2263 | }).join('\n'); |
---|
2264 | } |
---|
2265 | |
---|
2266 | /** |
---|
2267 | * Stringify `obj`. |
---|
2268 | * |
---|
2269 | * @param {Mixed} obj |
---|
2270 | * @return {String} |
---|
2271 | * @api private |
---|
2272 | */ |
---|
2273 | |
---|
2274 | function stringify(obj) { |
---|
2275 | if (obj instanceof RegExp) return obj.toString(); |
---|
2276 | return JSON.stringify(obj, null, 2); |
---|
2277 | } |
---|
2278 | |
---|
2279 | /** |
---|
2280 | * Check that a / b have the same type. |
---|
2281 | * |
---|
2282 | * @param {Object} a |
---|
2283 | * @param {Object} b |
---|
2284 | * @return {Boolean} |
---|
2285 | * @api private |
---|
2286 | */ |
---|
2287 | |
---|
2288 | function sameType(a, b) { |
---|
2289 | a = Object.prototype.toString.call(a); |
---|
2290 | b = Object.prototype.toString.call(b); |
---|
2291 | return a == b; |
---|
2292 | } |
---|
2293 | |
---|
2294 | |
---|
2295 | |
---|
2296 | }); // module: reporters/base.js |
---|
2297 | |
---|
2298 | require.register("reporters/doc.js", function(module, exports, require){ |
---|
2299 | |
---|
2300 | /** |
---|
2301 | * Module dependencies. |
---|
2302 | */ |
---|
2303 | |
---|
2304 | var Base = require('./base') |
---|
2305 | , utils = require('../utils'); |
---|
2306 | |
---|
2307 | /** |
---|
2308 | * Expose `Doc`. |
---|
2309 | */ |
---|
2310 | |
---|
2311 | exports = module.exports = Doc; |
---|
2312 | |
---|
2313 | /** |
---|
2314 | * Initialize a new `Doc` reporter. |
---|
2315 | * |
---|
2316 | * @param {Runner} runner |
---|
2317 | * @api public |
---|
2318 | */ |
---|
2319 | |
---|
2320 | function Doc(runner) { |
---|
2321 | Base.call(this, runner); |
---|
2322 | |
---|
2323 | var self = this |
---|
2324 | , stats = this.stats |
---|
2325 | , total = runner.total |
---|
2326 | , indents = 2; |
---|
2327 | |
---|
2328 | function indent() { |
---|
2329 | return Array(indents).join(' '); |
---|
2330 | } |
---|
2331 | |
---|
2332 | runner.on('suite', function(suite){ |
---|
2333 | if (suite.root) return; |
---|
2334 | ++indents; |
---|
2335 | console.log('%s<section class="suite">', indent()); |
---|
2336 | ++indents; |
---|
2337 | console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title)); |
---|
2338 | console.log('%s<dl>', indent()); |
---|
2339 | }); |
---|
2340 | |
---|
2341 | runner.on('suite end', function(suite){ |
---|
2342 | if (suite.root) return; |
---|
2343 | console.log('%s</dl>', indent()); |
---|
2344 | --indents; |
---|
2345 | console.log('%s</section>', indent()); |
---|
2346 | --indents; |
---|
2347 | }); |
---|
2348 | |
---|
2349 | runner.on('pass', function(test){ |
---|
2350 | console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title)); |
---|
2351 | var code = utils.escape(utils.clean(test.fn.toString())); |
---|
2352 | console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code); |
---|
2353 | }); |
---|
2354 | } |
---|
2355 | |
---|
2356 | }); // module: reporters/doc.js |
---|
2357 | |
---|
2358 | require.register("reporters/dot.js", function(module, exports, require){ |
---|
2359 | |
---|
2360 | /** |
---|
2361 | * Module dependencies. |
---|
2362 | */ |
---|
2363 | |
---|
2364 | var Base = require('./base') |
---|
2365 | , color = Base.color; |
---|
2366 | |
---|
2367 | /** |
---|
2368 | * Expose `Dot`. |
---|
2369 | */ |
---|
2370 | |
---|
2371 | exports = module.exports = Dot; |
---|
2372 | |
---|
2373 | /** |
---|
2374 | * Initialize a new `Dot` matrix test reporter. |
---|
2375 | * |
---|
2376 | * @param {Runner} runner |
---|
2377 | * @api public |
---|
2378 | */ |
---|
2379 | |
---|
2380 | function Dot(runner) { |
---|
2381 | Base.call(this, runner); |
---|
2382 | |
---|
2383 | var self = this |
---|
2384 | , stats = this.stats |
---|
2385 | , width = Base.window.width * .75 | 0 |
---|
2386 | , n = 0; |
---|
2387 | |
---|
2388 | runner.on('start', function(){ |
---|
2389 | process.stdout.write('\n '); |
---|
2390 | }); |
---|
2391 | |
---|
2392 | runner.on('pending', function(test){ |
---|
2393 | process.stdout.write(color('pending', Base.symbols.dot)); |
---|
2394 | }); |
---|
2395 | |
---|
2396 | runner.on('pass', function(test){ |
---|
2397 | if (++n % width == 0) process.stdout.write('\n '); |
---|
2398 | if ('slow' == test.speed) { |
---|
2399 | process.stdout.write(color('bright yellow', Base.symbols.dot)); |
---|
2400 | } else { |
---|
2401 | process.stdout.write(color(test.speed, Base.symbols.dot)); |
---|
2402 | } |
---|
2403 | }); |
---|
2404 | |
---|
2405 | runner.on('fail', function(test, err){ |
---|
2406 | if (++n % width == 0) process.stdout.write('\n '); |
---|
2407 | process.stdout.write(color('fail', Base.symbols.dot)); |
---|
2408 | }); |
---|
2409 | |
---|
2410 | runner.on('end', function(){ |
---|
2411 | console.log(); |
---|
2412 | self.epilogue(); |
---|
2413 | }); |
---|
2414 | } |
---|
2415 | |
---|
2416 | /** |
---|
2417 | * Inherit from `Base.prototype`. |
---|
2418 | */ |
---|
2419 | |
---|
2420 | function F(){}; |
---|
2421 | F.prototype = Base.prototype; |
---|
2422 | Dot.prototype = new F; |
---|
2423 | Dot.prototype.constructor = Dot; |
---|
2424 | |
---|
2425 | }); // module: reporters/dot.js |
---|
2426 | |
---|
2427 | require.register("reporters/html-cov.js", function(module, exports, require){ |
---|
2428 | |
---|
2429 | /** |
---|
2430 | * Module dependencies. |
---|
2431 | */ |
---|
2432 | |
---|
2433 | var JSONCov = require('./json-cov') |
---|
2434 | , fs = require('browser/fs'); |
---|
2435 | |
---|
2436 | /** |
---|
2437 | * Expose `HTMLCov`. |
---|
2438 | */ |
---|
2439 | |
---|
2440 | exports = module.exports = HTMLCov; |
---|
2441 | |
---|
2442 | /** |
---|
2443 | * Initialize a new `JsCoverage` reporter. |
---|
2444 | * |
---|
2445 | * @param {Runner} runner |
---|
2446 | * @api public |
---|
2447 | */ |
---|
2448 | |
---|
2449 | function HTMLCov(runner) { |
---|
2450 | var jade = require('jade') |
---|
2451 | , file = __dirname + '/templates/coverage.jade' |
---|
2452 | , str = fs.readFileSync(file, 'utf8') |
---|
2453 | , fn = jade.compile(str, { filename: file }) |
---|
2454 | , self = this; |
---|
2455 | |
---|
2456 | JSONCov.call(this, runner, false); |
---|
2457 | |
---|
2458 | runner.on('end', function(){ |
---|
2459 | process.stdout.write(fn({ |
---|
2460 | cov: self.cov |
---|
2461 | , coverageClass: coverageClass |
---|
2462 | })); |
---|
2463 | }); |
---|
2464 | } |
---|
2465 | |
---|
2466 | /** |
---|
2467 | * Return coverage class for `n`. |
---|
2468 | * |
---|
2469 | * @return {String} |
---|
2470 | * @api private |
---|
2471 | */ |
---|
2472 | |
---|
2473 | function coverageClass(n) { |
---|
2474 | if (n >= 75) return 'high'; |
---|
2475 | if (n >= 50) return 'medium'; |
---|
2476 | if (n >= 25) return 'low'; |
---|
2477 | return 'terrible'; |
---|
2478 | } |
---|
2479 | }); // module: reporters/html-cov.js |
---|
2480 | |
---|
2481 | require.register("reporters/html.js", function(module, exports, require){ |
---|
2482 | |
---|
2483 | /** |
---|
2484 | * Module dependencies. |
---|
2485 | */ |
---|
2486 | |
---|
2487 | var Base = require('./base') |
---|
2488 | , utils = require('../utils') |
---|
2489 | , Progress = require('../browser/progress') |
---|
2490 | , escape = utils.escape; |
---|
2491 | |
---|
2492 | /** |
---|
2493 | * Save timer references to avoid Sinon interfering (see GH-237). |
---|
2494 | */ |
---|
2495 | |
---|
2496 | var Date = global.Date |
---|
2497 | , setTimeout = global.setTimeout |
---|
2498 | , setInterval = global.setInterval |
---|
2499 | , clearTimeout = global.clearTimeout |
---|
2500 | , clearInterval = global.clearInterval; |
---|
2501 | |
---|
2502 | /** |
---|
2503 | * Expose `HTML`. |
---|
2504 | */ |
---|
2505 | |
---|
2506 | exports = module.exports = HTML; |
---|
2507 | |
---|
2508 | /** |
---|
2509 | * Stats template. |
---|
2510 | */ |
---|
2511 | |
---|
2512 | var statsTemplate = '<ul id="mocha-stats">' |
---|
2513 | + '<li class="progress"><canvas width="40" height="40"></canvas></li>' |
---|
2514 | + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>' |
---|
2515 | + '<li class="failures"><a href="#">failures:</a> <em>0</em></li>' |
---|
2516 | + '<li class="duration">duration: <em>0</em>s</li>' |
---|
2517 | + '</ul>'; |
---|
2518 | |
---|
2519 | /** |
---|
2520 | * Initialize a new `HTML` reporter. |
---|
2521 | * |
---|
2522 | * @param {Runner} runner |
---|
2523 | * @api public |
---|
2524 | */ |
---|
2525 | |
---|
2526 | function HTML(runner, root) { |
---|
2527 | Base.call(this, runner); |
---|
2528 | |
---|
2529 | var self = this |
---|
2530 | , stats = this.stats |
---|
2531 | , total = runner.total |
---|
2532 | , stat = fragment(statsTemplate) |
---|
2533 | , items = stat.getElementsByTagName('li') |
---|
2534 | , passes = items[1].getElementsByTagName('em')[0] |
---|
2535 | , passesLink = items[1].getElementsByTagName('a')[0] |
---|
2536 | , failures = items[2].getElementsByTagName('em')[0] |
---|
2537 | , failuresLink = items[2].getElementsByTagName('a')[0] |
---|
2538 | , duration = items[3].getElementsByTagName('em')[0] |
---|
2539 | , canvas = stat.getElementsByTagName('canvas')[0] |
---|
2540 | , report = fragment('<ul id="mocha-report"></ul>') |
---|
2541 | , stack = [report] |
---|
2542 | , progress |
---|
2543 | , ctx |
---|
2544 | |
---|
2545 | root = root || document.getElementById('mocha'); |
---|
2546 | |
---|
2547 | if (canvas.getContext) { |
---|
2548 | var ratio = window.devicePixelRatio || 1; |
---|
2549 | canvas.style.width = canvas.width; |
---|
2550 | canvas.style.height = canvas.height; |
---|
2551 | canvas.width *= ratio; |
---|
2552 | canvas.height *= ratio; |
---|
2553 | ctx = canvas.getContext('2d'); |
---|
2554 | ctx.scale(ratio, ratio); |
---|
2555 | progress = new Progress; |
---|
2556 | } |
---|
2557 | |
---|
2558 | if (!root) return error('#mocha div missing, add it to your document'); |
---|
2559 | |
---|
2560 | // pass toggle |
---|
2561 | on(passesLink, 'click', function(){ |
---|
2562 | unhide(); |
---|
2563 | var name = /pass/.test(report.className) ? '' : ' pass'; |
---|
2564 | report.className = report.className.replace(/fail|pass/g, '') + name; |
---|
2565 | if (report.className.trim()) hideSuitesWithout('test pass'); |
---|
2566 | }); |
---|
2567 | |
---|
2568 | // failure toggle |
---|
2569 | on(failuresLink, 'click', function(){ |
---|
2570 | unhide(); |
---|
2571 | var name = /fail/.test(report.className) ? '' : ' fail'; |
---|
2572 | report.className = report.className.replace(/fail|pass/g, '') + name; |
---|
2573 | if (report.className.trim()) hideSuitesWithout('test fail'); |
---|
2574 | }); |
---|
2575 | |
---|
2576 | root.appendChild(stat); |
---|
2577 | root.appendChild(report); |
---|
2578 | |
---|
2579 | if (progress) progress.size(40); |
---|
2580 | |
---|
2581 | runner.on('suite', function(suite){ |
---|
2582 | if (suite.root) return; |
---|
2583 | |
---|
2584 | // suite |
---|
2585 | var url = self.suiteURL(suite); |
---|
2586 | var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title)); |
---|
2587 | |
---|
2588 | // container |
---|
2589 | stack[0].appendChild(el); |
---|
2590 | stack.unshift(document.createElement('ul')); |
---|
2591 | el.appendChild(stack[0]); |
---|
2592 | }); |
---|
2593 | |
---|
2594 | runner.on('suite end', function(suite){ |
---|
2595 | if (suite.root) return; |
---|
2596 | stack.shift(); |
---|
2597 | }); |
---|
2598 | |
---|
2599 | runner.on('fail', function(test, err){ |
---|
2600 | if ('hook' == test.type) runner.emit('test end', test); |
---|
2601 | }); |
---|
2602 | |
---|
2603 | runner.on('test end', function(test){ |
---|
2604 | // TODO: add to stats |
---|
2605 | var percent = stats.tests / this.total * 100 | 0; |
---|
2606 | if (progress) progress.update(percent).draw(ctx); |
---|
2607 | |
---|
2608 | // update stats |
---|
2609 | var ms = new Date - stats.start; |
---|
2610 | text(passes, stats.passes); |
---|
2611 | text(failures, stats.failures); |
---|
2612 | text(duration, (ms / 1000).toFixed(2)); |
---|
2613 | |
---|
2614 | // test |
---|
2615 | if ('passed' == test.state) { |
---|
2616 | var url = self.testURL(test); |
---|
2617 | var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">â£</a></h2></li>', test.speed, test.title, test.duration, url); |
---|
2618 | } else if (test.pending) { |
---|
2619 | var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title); |
---|
2620 | } else { |
---|
2621 | var el = fragment('<li class="test fail"><h2>%e <a href="?grep=%e" class="replay">â£</a></h2></li>', test.title, encodeURIComponent(test.fullTitle())); |
---|
2622 | var str = test.err.stack || test.err.toString(); |
---|
2623 | |
---|
2624 | // FF / Opera do not add the message |
---|
2625 | if (!~str.indexOf(test.err.message)) { |
---|
2626 | str = test.err.message + '\n' + str; |
---|
2627 | } |
---|
2628 | |
---|
2629 | // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we |
---|
2630 | // check for the result of the stringifying. |
---|
2631 | if ('[object Error]' == str) str = test.err.message; |
---|
2632 | |
---|
2633 | // Safari doesn't give you a stack. Let's at least provide a source line. |
---|
2634 | if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) { |
---|
2635 | str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")"; |
---|
2636 | } |
---|
2637 | |
---|
2638 | el.appendChild(fragment('<pre class="error">%e</pre>', str)); |
---|
2639 | } |
---|
2640 | |
---|
2641 | // toggle code |
---|
2642 | // TODO: defer |
---|
2643 | if (!test.pending) { |
---|
2644 | var h2 = el.getElementsByTagName('h2')[0]; |
---|
2645 | |
---|
2646 | on(h2, 'click', function(){ |
---|
2647 | pre.style.display = 'none' == pre.style.display |
---|
2648 | ? 'block' |
---|
2649 | : 'none'; |
---|
2650 | }); |
---|
2651 | |
---|
2652 | var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString())); |
---|
2653 | el.appendChild(pre); |
---|
2654 | pre.style.display = 'none'; |
---|
2655 | } |
---|
2656 | |
---|
2657 | // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack. |
---|
2658 | if (stack[0]) stack[0].appendChild(el); |
---|
2659 | }); |
---|
2660 | } |
---|
2661 | |
---|
2662 | /** |
---|
2663 | * Provide suite URL |
---|
2664 | * |
---|
2665 | * @param {Object} [suite] |
---|
2666 | */ |
---|
2667 | |
---|
2668 | HTML.prototype.suiteURL = function(suite){ |
---|
2669 | return '?grep=' + encodeURIComponent(suite.fullTitle()); |
---|
2670 | }; |
---|
2671 | |
---|
2672 | /** |
---|
2673 | * Provide test URL |
---|
2674 | * |
---|
2675 | * @param {Object} [test] |
---|
2676 | */ |
---|
2677 | |
---|
2678 | HTML.prototype.testURL = function(test){ |
---|
2679 | return '?grep=' + encodeURIComponent(test.fullTitle()); |
---|
2680 | }; |
---|
2681 | |
---|
2682 | /** |
---|
2683 | * Display error `msg`. |
---|
2684 | */ |
---|
2685 | |
---|
2686 | function error(msg) { |
---|
2687 | document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg)); |
---|
2688 | } |
---|
2689 | |
---|
2690 | /** |
---|
2691 | * Return a DOM fragment from `html`. |
---|
2692 | */ |
---|
2693 | |
---|
2694 | function fragment(html) { |
---|
2695 | var args = arguments |
---|
2696 | , div = document.createElement('div') |
---|
2697 | , i = 1; |
---|
2698 | |
---|
2699 | div.innerHTML = html.replace(/%([se])/g, function(_, type){ |
---|
2700 | switch (type) { |
---|
2701 | case 's': return String(args[i++]); |
---|
2702 | case 'e': return escape(args[i++]); |
---|
2703 | } |
---|
2704 | }); |
---|
2705 | |
---|
2706 | return div.firstChild; |
---|
2707 | } |
---|
2708 | |
---|
2709 | /** |
---|
2710 | * Check for suites that do not have elements |
---|
2711 | * with `classname`, and hide them. |
---|
2712 | */ |
---|
2713 | |
---|
2714 | function hideSuitesWithout(classname) { |
---|
2715 | var suites = document.getElementsByClassName('suite'); |
---|
2716 | for (var i = 0; i < suites.length; i++) { |
---|
2717 | var els = suites[i].getElementsByClassName(classname); |
---|
2718 | if (0 == els.length) suites[i].className += ' hidden'; |
---|
2719 | } |
---|
2720 | } |
---|
2721 | |
---|
2722 | /** |
---|
2723 | * Unhide .hidden suites. |
---|
2724 | */ |
---|
2725 | |
---|
2726 | function unhide() { |
---|
2727 | var els = document.getElementsByClassName('suite hidden'); |
---|
2728 | for (var i = 0; i < els.length; ++i) { |
---|
2729 | els[i].className = els[i].className.replace('suite hidden', 'suite'); |
---|
2730 | } |
---|
2731 | } |
---|
2732 | |
---|
2733 | /** |
---|
2734 | * Set `el` text to `str`. |
---|
2735 | */ |
---|
2736 | |
---|
2737 | function text(el, str) { |
---|
2738 | if (el.textContent) { |
---|
2739 | el.textContent = str; |
---|
2740 | } else { |
---|
2741 | el.innerText = str; |
---|
2742 | } |
---|
2743 | } |
---|
2744 | |
---|
2745 | /** |
---|
2746 | * Listen on `event` with callback `fn`. |
---|
2747 | */ |
---|
2748 | |
---|
2749 | function on(el, event, fn) { |
---|
2750 | if (el.addEventListener) { |
---|
2751 | el.addEventListener(event, fn, false); |
---|
2752 | } else { |
---|
2753 | el.attachEvent('on' + event, fn); |
---|
2754 | } |
---|
2755 | } |
---|
2756 | |
---|
2757 | }); // module: reporters/html.js |
---|
2758 | |
---|
2759 | require.register("reporters/index.js", function(module, exports, require){ |
---|
2760 | |
---|
2761 | exports.Base = require('./base'); |
---|
2762 | exports.Dot = require('./dot'); |
---|
2763 | exports.Doc = require('./doc'); |
---|
2764 | exports.TAP = require('./tap'); |
---|
2765 | exports.JSON = require('./json'); |
---|
2766 | exports.HTML = require('./html'); |
---|
2767 | exports.List = require('./list'); |
---|
2768 | exports.Min = require('./min'); |
---|
2769 | exports.Spec = require('./spec'); |
---|
2770 | exports.Nyan = require('./nyan'); |
---|
2771 | exports.XUnit = require('./xunit'); |
---|
2772 | exports.Markdown = require('./markdown'); |
---|
2773 | exports.Progress = require('./progress'); |
---|
2774 | exports.Landing = require('./landing'); |
---|
2775 | exports.JSONCov = require('./json-cov'); |
---|
2776 | exports.HTMLCov = require('./html-cov'); |
---|
2777 | exports.JSONStream = require('./json-stream'); |
---|
2778 | |
---|
2779 | }); // module: reporters/index.js |
---|
2780 | |
---|
2781 | require.register("reporters/json-cov.js", function(module, exports, require){ |
---|
2782 | |
---|
2783 | /** |
---|
2784 | * Module dependencies. |
---|
2785 | */ |
---|
2786 | |
---|
2787 | var Base = require('./base'); |
---|
2788 | |
---|
2789 | /** |
---|
2790 | * Expose `JSONCov`. |
---|
2791 | */ |
---|
2792 | |
---|
2793 | exports = module.exports = JSONCov; |
---|
2794 | |
---|
2795 | /** |
---|
2796 | * Initialize a new `JsCoverage` reporter. |
---|
2797 | * |
---|
2798 | * @param {Runner} runner |
---|
2799 | * @param {Boolean} output |
---|
2800 | * @api public |
---|
2801 | */ |
---|
2802 | |
---|
2803 | function JSONCov(runner, output) { |
---|
2804 | var self = this |
---|
2805 | , output = 1 == arguments.length ? true : output; |
---|
2806 | |
---|
2807 | Base.call(this, runner); |
---|
2808 | |
---|
2809 | var tests = [] |
---|
2810 | , failures = [] |
---|
2811 | , passes = []; |
---|
2812 | |
---|
2813 | runner.on('test end', function(test){ |
---|
2814 | tests.push(test); |
---|
2815 | }); |
---|
2816 | |
---|
2817 | runner.on('pass', function(test){ |
---|
2818 | passes.push(test); |
---|
2819 | }); |
---|
2820 | |
---|
2821 | runner.on('fail', function(test){ |
---|
2822 | failures.push(test); |
---|
2823 | }); |
---|
2824 | |
---|
2825 | runner.on('end', function(){ |
---|
2826 | var cov = global._$jscoverage || {}; |
---|
2827 | var result = self.cov = map(cov); |
---|
2828 | result.stats = self.stats; |
---|
2829 | result.tests = tests.map(clean); |
---|
2830 | result.failures = failures.map(clean); |
---|
2831 | result.passes = passes.map(clean); |
---|
2832 | if (!output) return; |
---|
2833 | process.stdout.write(JSON.stringify(result, null, 2 )); |
---|
2834 | }); |
---|
2835 | } |
---|
2836 | |
---|
2837 | /** |
---|
2838 | * Map jscoverage data to a JSON structure |
---|
2839 | * suitable for reporting. |
---|
2840 | * |
---|
2841 | * @param {Object} cov |
---|
2842 | * @return {Object} |
---|
2843 | * @api private |
---|
2844 | */ |
---|
2845 | |
---|
2846 | function map(cov) { |
---|
2847 | var ret = { |
---|
2848 | instrumentation: 'node-jscoverage' |
---|
2849 | , sloc: 0 |
---|
2850 | , hits: 0 |
---|
2851 | , misses: 0 |
---|
2852 | , coverage: 0 |
---|
2853 | , files: [] |
---|
2854 | }; |
---|
2855 | |
---|
2856 | for (var filename in cov) { |
---|
2857 | var data = coverage(filename, cov[filename]); |
---|
2858 | ret.files.push(data); |
---|
2859 | ret.hits += data.hits; |
---|
2860 | ret.misses += data.misses; |
---|
2861 | ret.sloc += data.sloc; |
---|
2862 | } |
---|
2863 | |
---|
2864 | ret.files.sort(function(a, b) { |
---|
2865 | return a.filename.localeCompare(b.filename); |
---|
2866 | }); |
---|
2867 | |
---|
2868 | if (ret.sloc > 0) { |
---|
2869 | ret.coverage = (ret.hits / ret.sloc) * 100; |
---|
2870 | } |
---|
2871 | |
---|
2872 | return ret; |
---|
2873 | }; |
---|
2874 | |
---|
2875 | /** |
---|
2876 | * Map jscoverage data for a single source file |
---|
2877 | * to a JSON structure suitable for reporting. |
---|
2878 | * |
---|
2879 | * @param {String} filename name of the source file |
---|
2880 | * @param {Object} data jscoverage coverage data |
---|
2881 | * @return {Object} |
---|
2882 | * @api private |
---|
2883 | */ |
---|
2884 | |
---|
2885 | function coverage(filename, data) { |
---|
2886 | var ret = { |
---|
2887 | filename: filename, |
---|
2888 | coverage: 0, |
---|
2889 | hits: 0, |
---|
2890 | misses: 0, |
---|
2891 | sloc: 0, |
---|
2892 | source: {} |
---|
2893 | }; |
---|
2894 | |
---|
2895 | data.source.forEach(function(line, num){ |
---|
2896 | num++; |
---|
2897 | |
---|
2898 | if (data[num] === 0) { |
---|
2899 | ret.misses++; |
---|
2900 | ret.sloc++; |
---|
2901 | } else if (data[num] !== undefined) { |
---|
2902 | ret.hits++; |
---|
2903 | ret.sloc++; |
---|
2904 | } |
---|
2905 | |
---|
2906 | ret.source[num] = { |
---|
2907 | source: line |
---|
2908 | , coverage: data[num] === undefined |
---|
2909 | ? '' |
---|
2910 | : data[num] |
---|
2911 | }; |
---|
2912 | }); |
---|
2913 | |
---|
2914 | ret.coverage = ret.hits / ret.sloc * 100; |
---|
2915 | |
---|
2916 | return ret; |
---|
2917 | } |
---|
2918 | |
---|
2919 | /** |
---|
2920 | * Return a plain-object representation of `test` |
---|
2921 | * free of cyclic properties etc. |
---|
2922 | * |
---|
2923 | * @param {Object} test |
---|
2924 | * @return {Object} |
---|
2925 | * @api private |
---|
2926 | */ |
---|
2927 | |
---|
2928 | function clean(test) { |
---|
2929 | return { |
---|
2930 | title: test.title |
---|
2931 | , fullTitle: test.fullTitle() |
---|
2932 | , duration: test.duration |
---|
2933 | } |
---|
2934 | } |
---|
2935 | |
---|
2936 | }); // module: reporters/json-cov.js |
---|
2937 | |
---|
2938 | require.register("reporters/json-stream.js", function(module, exports, require){ |
---|
2939 | |
---|
2940 | /** |
---|
2941 | * Module dependencies. |
---|
2942 | */ |
---|
2943 | |
---|
2944 | var Base = require('./base') |
---|
2945 | , color = Base.color; |
---|
2946 | |
---|
2947 | /** |
---|
2948 | * Expose `List`. |
---|
2949 | */ |
---|
2950 | |
---|
2951 | exports = module.exports = List; |
---|
2952 | |
---|
2953 | /** |
---|
2954 | * Initialize a new `List` test reporter. |
---|
2955 | * |
---|
2956 | * @param {Runner} runner |
---|
2957 | * @api public |
---|
2958 | */ |
---|
2959 | |
---|
2960 | function List(runner) { |
---|
2961 | Base.call(this, runner); |
---|
2962 | |
---|
2963 | var self = this |
---|
2964 | , stats = this.stats |
---|
2965 | , total = runner.total; |
---|
2966 | |
---|
2967 | runner.on('start', function(){ |
---|
2968 | console.log(JSON.stringify(['start', { total: total }])); |
---|
2969 | }); |
---|
2970 | |
---|
2971 | runner.on('pass', function(test){ |
---|
2972 | console.log(JSON.stringify(['pass', clean(test)])); |
---|
2973 | }); |
---|
2974 | |
---|
2975 | runner.on('fail', function(test, err){ |
---|
2976 | console.log(JSON.stringify(['fail', clean(test)])); |
---|
2977 | }); |
---|
2978 | |
---|
2979 | runner.on('end', function(){ |
---|
2980 | process.stdout.write(JSON.stringify(['end', self.stats])); |
---|
2981 | }); |
---|
2982 | } |
---|
2983 | |
---|
2984 | /** |
---|
2985 | * Return a plain-object representation of `test` |
---|
2986 | * free of cyclic properties etc. |
---|
2987 | * |
---|
2988 | * @param {Object} test |
---|
2989 | * @return {Object} |
---|
2990 | * @api private |
---|
2991 | */ |
---|
2992 | |
---|
2993 | function clean(test) { |
---|
2994 | return { |
---|
2995 | title: test.title |
---|
2996 | , fullTitle: test.fullTitle() |
---|
2997 | , duration: test.duration |
---|
2998 | } |
---|
2999 | } |
---|
3000 | }); // module: reporters/json-stream.js |
---|
3001 | |
---|
3002 | require.register("reporters/json.js", function(module, exports, require){ |
---|
3003 | |
---|
3004 | /** |
---|
3005 | * Module dependencies. |
---|
3006 | */ |
---|
3007 | |
---|
3008 | var Base = require('./base') |
---|
3009 | , cursor = Base.cursor |
---|
3010 | , color = Base.color; |
---|
3011 | |
---|
3012 | /** |
---|
3013 | * Expose `JSON`. |
---|
3014 | */ |
---|
3015 | |
---|
3016 | exports = module.exports = JSONReporter; |
---|
3017 | |
---|
3018 | /** |
---|
3019 | * Initialize a new `JSON` reporter. |
---|
3020 | * |
---|
3021 | * @param {Runner} runner |
---|
3022 | * @api public |
---|
3023 | */ |
---|
3024 | |
---|
3025 | function JSONReporter(runner) { |
---|
3026 | var self = this; |
---|
3027 | Base.call(this, runner); |
---|
3028 | |
---|
3029 | var tests = [] |
---|
3030 | , failures = [] |
---|
3031 | , passes = []; |
---|
3032 | |
---|
3033 | runner.on('test end', function(test){ |
---|
3034 | tests.push(test); |
---|
3035 | }); |
---|
3036 | |
---|
3037 | runner.on('pass', function(test){ |
---|
3038 | passes.push(test); |
---|
3039 | }); |
---|
3040 | |
---|
3041 | runner.on('fail', function(test){ |
---|
3042 | failures.push(test); |
---|
3043 | }); |
---|
3044 | |
---|
3045 | runner.on('end', function(){ |
---|
3046 | var obj = { |
---|
3047 | stats: self.stats |
---|
3048 | , tests: tests.map(clean) |
---|
3049 | , failures: failures.map(clean) |
---|
3050 | , passes: passes.map(clean) |
---|
3051 | }; |
---|
3052 | |
---|
3053 | process.stdout.write(JSON.stringify(obj, null, 2)); |
---|
3054 | }); |
---|
3055 | } |
---|
3056 | |
---|
3057 | /** |
---|
3058 | * Return a plain-object representation of `test` |
---|
3059 | * free of cyclic properties etc. |
---|
3060 | * |
---|
3061 | * @param {Object} test |
---|
3062 | * @return {Object} |
---|
3063 | * @api private |
---|
3064 | */ |
---|
3065 | |
---|
3066 | function clean(test) { |
---|
3067 | return { |
---|
3068 | title: test.title |
---|
3069 | , fullTitle: test.fullTitle() |
---|
3070 | , duration: test.duration |
---|
3071 | } |
---|
3072 | } |
---|
3073 | }); // module: reporters/json.js |
---|
3074 | |
---|
3075 | require.register("reporters/landing.js", function(module, exports, require){ |
---|
3076 | |
---|
3077 | /** |
---|
3078 | * Module dependencies. |
---|
3079 | */ |
---|
3080 | |
---|
3081 | var Base = require('./base') |
---|
3082 | , cursor = Base.cursor |
---|
3083 | , color = Base.color; |
---|
3084 | |
---|
3085 | /** |
---|
3086 | * Expose `Landing`. |
---|
3087 | */ |
---|
3088 | |
---|
3089 | exports = module.exports = Landing; |
---|
3090 | |
---|
3091 | /** |
---|
3092 | * Airplane color. |
---|
3093 | */ |
---|
3094 | |
---|
3095 | Base.colors.plane = 0; |
---|
3096 | |
---|
3097 | /** |
---|
3098 | * Airplane crash color. |
---|
3099 | */ |
---|
3100 | |
---|
3101 | Base.colors['plane crash'] = 31; |
---|
3102 | |
---|
3103 | /** |
---|
3104 | * Runway color. |
---|
3105 | */ |
---|
3106 | |
---|
3107 | Base.colors.runway = 90; |
---|
3108 | |
---|
3109 | /** |
---|
3110 | * Initialize a new `Landing` reporter. |
---|
3111 | * |
---|
3112 | * @param {Runner} runner |
---|
3113 | * @api public |
---|
3114 | */ |
---|
3115 | |
---|
3116 | function Landing(runner) { |
---|
3117 | Base.call(this, runner); |
---|
3118 | |
---|
3119 | var self = this |
---|
3120 | , stats = this.stats |
---|
3121 | , width = Base.window.width * .75 | 0 |
---|
3122 | , total = runner.total |
---|
3123 | , stream = process.stdout |
---|
3124 | , plane = color('plane', 'â') |
---|
3125 | , crashed = -1 |
---|
3126 | , n = 0; |
---|
3127 | |
---|
3128 | function runway() { |
---|
3129 | var buf = Array(width).join('-'); |
---|
3130 | return ' ' + color('runway', buf); |
---|
3131 | } |
---|
3132 | |
---|
3133 | runner.on('start', function(){ |
---|
3134 | stream.write('\n '); |
---|
3135 | cursor.hide(); |
---|
3136 | }); |
---|
3137 | |
---|
3138 | runner.on('test end', function(test){ |
---|
3139 | // check if the plane crashed |
---|
3140 | var col = -1 == crashed |
---|
3141 | ? width * ++n / total | 0 |
---|
3142 | : crashed; |
---|
3143 | |
---|
3144 | // show the crash |
---|
3145 | if ('failed' == test.state) { |
---|
3146 | plane = color('plane crash', 'â'); |
---|
3147 | crashed = col; |
---|
3148 | } |
---|
3149 | |
---|
3150 | // render landing strip |
---|
3151 | stream.write('\u001b[4F\n\n'); |
---|
3152 | stream.write(runway()); |
---|
3153 | stream.write('\n '); |
---|
3154 | stream.write(color('runway', Array(col).join('â
'))); |
---|
3155 | stream.write(plane) |
---|
3156 | stream.write(color('runway', Array(width - col).join('â
') + '\n')); |
---|
3157 | stream.write(runway()); |
---|
3158 | stream.write('\u001b[0m'); |
---|
3159 | }); |
---|
3160 | |
---|
3161 | runner.on('end', function(){ |
---|
3162 | cursor.show(); |
---|
3163 | console.log(); |
---|
3164 | self.epilogue(); |
---|
3165 | }); |
---|
3166 | } |
---|
3167 | |
---|
3168 | /** |
---|
3169 | * Inherit from `Base.prototype`. |
---|
3170 | */ |
---|
3171 | |
---|
3172 | function F(){}; |
---|
3173 | F.prototype = Base.prototype; |
---|
3174 | Landing.prototype = new F; |
---|
3175 | Landing.prototype.constructor = Landing; |
---|
3176 | |
---|
3177 | }); // module: reporters/landing.js |
---|
3178 | |
---|
3179 | require.register("reporters/list.js", function(module, exports, require){ |
---|
3180 | |
---|
3181 | /** |
---|
3182 | * Module dependencies. |
---|
3183 | */ |
---|
3184 | |
---|
3185 | var Base = require('./base') |
---|
3186 | , cursor = Base.cursor |
---|
3187 | , color = Base.color; |
---|
3188 | |
---|
3189 | /** |
---|
3190 | * Expose `List`. |
---|
3191 | */ |
---|
3192 | |
---|
3193 | exports = module.exports = List; |
---|
3194 | |
---|
3195 | /** |
---|
3196 | * Initialize a new `List` test reporter. |
---|
3197 | * |
---|
3198 | * @param {Runner} runner |
---|
3199 | * @api public |
---|
3200 | */ |
---|
3201 | |
---|
3202 | function List(runner) { |
---|
3203 | Base.call(this, runner); |
---|
3204 | |
---|
3205 | var self = this |
---|
3206 | , stats = this.stats |
---|
3207 | , n = 0; |
---|
3208 | |
---|
3209 | runner.on('start', function(){ |
---|
3210 | console.log(); |
---|
3211 | }); |
---|
3212 | |
---|
3213 | runner.on('test', function(test){ |
---|
3214 | process.stdout.write(color('pass', ' ' + test.fullTitle() + ': ')); |
---|
3215 | }); |
---|
3216 | |
---|
3217 | runner.on('pending', function(test){ |
---|
3218 | var fmt = color('checkmark', ' -') |
---|
3219 | + color('pending', ' %s'); |
---|
3220 | console.log(fmt, test.fullTitle()); |
---|
3221 | }); |
---|
3222 | |
---|
3223 | runner.on('pass', function(test){ |
---|
3224 | var fmt = color('checkmark', ' '+Base.symbols.dot) |
---|
3225 | + color('pass', ' %s: ') |
---|
3226 | + color(test.speed, '%dms'); |
---|
3227 | cursor.CR(); |
---|
3228 | console.log(fmt, test.fullTitle(), test.duration); |
---|
3229 | }); |
---|
3230 | |
---|
3231 | runner.on('fail', function(test, err){ |
---|
3232 | cursor.CR(); |
---|
3233 | console.log(color('fail', ' %d) %s'), ++n, test.fullTitle()); |
---|
3234 | }); |
---|
3235 | |
---|
3236 | runner.on('end', self.epilogue.bind(self)); |
---|
3237 | } |
---|
3238 | |
---|
3239 | /** |
---|
3240 | * Inherit from `Base.prototype`. |
---|
3241 | */ |
---|
3242 | |
---|
3243 | function F(){}; |
---|
3244 | F.prototype = Base.prototype; |
---|
3245 | List.prototype = new F; |
---|
3246 | List.prototype.constructor = List; |
---|
3247 | |
---|
3248 | |
---|
3249 | }); // module: reporters/list.js |
---|
3250 | |
---|
3251 | require.register("reporters/markdown.js", function(module, exports, require){ |
---|
3252 | /** |
---|
3253 | * Module dependencies. |
---|
3254 | */ |
---|
3255 | |
---|
3256 | var Base = require('./base') |
---|
3257 | , utils = require('../utils'); |
---|
3258 | |
---|
3259 | /** |
---|
3260 | * Expose `Markdown`. |
---|
3261 | */ |
---|
3262 | |
---|
3263 | exports = module.exports = Markdown; |
---|
3264 | |
---|
3265 | /** |
---|
3266 | * Initialize a new `Markdown` reporter. |
---|
3267 | * |
---|
3268 | * @param {Runner} runner |
---|
3269 | * @api public |
---|
3270 | */ |
---|
3271 | |
---|
3272 | function Markdown(runner) { |
---|
3273 | Base.call(this, runner); |
---|
3274 | |
---|
3275 | var self = this |
---|
3276 | , stats = this.stats |
---|
3277 | , level = 0 |
---|
3278 | , buf = ''; |
---|
3279 | |
---|
3280 | function title(str) { |
---|
3281 | return Array(level).join('#') + ' ' + str; |
---|
3282 | } |
---|
3283 | |
---|
3284 | function indent() { |
---|
3285 | return Array(level).join(' '); |
---|
3286 | } |
---|
3287 | |
---|
3288 | function mapTOC(suite, obj) { |
---|
3289 | var ret = obj; |
---|
3290 | obj = obj[suite.title] = obj[suite.title] || { suite: suite }; |
---|
3291 | suite.suites.forEach(function(suite){ |
---|
3292 | mapTOC(suite, obj); |
---|
3293 | }); |
---|
3294 | return ret; |
---|
3295 | } |
---|
3296 | |
---|
3297 | function stringifyTOC(obj, level) { |
---|
3298 | ++level; |
---|
3299 | var buf = ''; |
---|
3300 | var link; |
---|
3301 | for (var key in obj) { |
---|
3302 | if ('suite' == key) continue; |
---|
3303 | if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n'; |
---|
3304 | if (key) buf += Array(level).join(' ') + link; |
---|
3305 | buf += stringifyTOC(obj[key], level); |
---|
3306 | } |
---|
3307 | --level; |
---|
3308 | return buf; |
---|
3309 | } |
---|
3310 | |
---|
3311 | function generateTOC(suite) { |
---|
3312 | var obj = mapTOC(suite, {}); |
---|
3313 | return stringifyTOC(obj, 0); |
---|
3314 | } |
---|
3315 | |
---|
3316 | generateTOC(runner.suite); |
---|
3317 | |
---|
3318 | runner.on('suite', function(suite){ |
---|
3319 | ++level; |
---|
3320 | var slug = utils.slug(suite.fullTitle()); |
---|
3321 | buf += '<a name="' + slug + '"></a>' + '\n'; |
---|
3322 | buf += title(suite.title) + '\n'; |
---|
3323 | }); |
---|
3324 | |
---|
3325 | runner.on('suite end', function(suite){ |
---|
3326 | --level; |
---|
3327 | }); |
---|
3328 | |
---|
3329 | runner.on('pass', function(test){ |
---|
3330 | var code = utils.clean(test.fn.toString()); |
---|
3331 | buf += test.title + '.\n'; |
---|
3332 | buf += '\n```js\n'; |
---|
3333 | buf += code + '\n'; |
---|
3334 | buf += '```\n\n'; |
---|
3335 | }); |
---|
3336 | |
---|
3337 | runner.on('end', function(){ |
---|
3338 | process.stdout.write('# TOC\n'); |
---|
3339 | process.stdout.write(generateTOC(runner.suite)); |
---|
3340 | process.stdout.write(buf); |
---|
3341 | }); |
---|
3342 | } |
---|
3343 | }); // module: reporters/markdown.js |
---|
3344 | |
---|
3345 | require.register("reporters/min.js", function(module, exports, require){ |
---|
3346 | |
---|
3347 | /** |
---|
3348 | * Module dependencies. |
---|
3349 | */ |
---|
3350 | |
---|
3351 | var Base = require('./base'); |
---|
3352 | |
---|
3353 | /** |
---|
3354 | * Expose `Min`. |
---|
3355 | */ |
---|
3356 | |
---|
3357 | exports = module.exports = Min; |
---|
3358 | |
---|
3359 | /** |
---|
3360 | * Initialize a new `Min` minimal test reporter (best used with --watch). |
---|
3361 | * |
---|
3362 | * @param {Runner} runner |
---|
3363 | * @api public |
---|
3364 | */ |
---|
3365 | |
---|
3366 | function Min(runner) { |
---|
3367 | Base.call(this, runner); |
---|
3368 | |
---|
3369 | runner.on('start', function(){ |
---|
3370 | // clear screen |
---|
3371 | process.stdout.write('\u001b[2J'); |
---|
3372 | // set cursor position |
---|
3373 | process.stdout.write('\u001b[1;3H'); |
---|
3374 | }); |
---|
3375 | |
---|
3376 | runner.on('end', this.epilogue.bind(this)); |
---|
3377 | } |
---|
3378 | |
---|
3379 | /** |
---|
3380 | * Inherit from `Base.prototype`. |
---|
3381 | */ |
---|
3382 | |
---|
3383 | function F(){}; |
---|
3384 | F.prototype = Base.prototype; |
---|
3385 | Min.prototype = new F; |
---|
3386 | Min.prototype.constructor = Min; |
---|
3387 | |
---|
3388 | |
---|
3389 | }); // module: reporters/min.js |
---|
3390 | |
---|
3391 | require.register("reporters/nyan.js", function(module, exports, require){ |
---|
3392 | /** |
---|
3393 | * Module dependencies. |
---|
3394 | */ |
---|
3395 | |
---|
3396 | var Base = require('./base') |
---|
3397 | , color = Base.color; |
---|
3398 | |
---|
3399 | /** |
---|
3400 | * Expose `Dot`. |
---|
3401 | */ |
---|
3402 | |
---|
3403 | exports = module.exports = NyanCat; |
---|
3404 | |
---|
3405 | /** |
---|
3406 | * Initialize a new `Dot` matrix test reporter. |
---|
3407 | * |
---|
3408 | * @param {Runner} runner |
---|
3409 | * @api public |
---|
3410 | */ |
---|
3411 | |
---|
3412 | function NyanCat(runner) { |
---|
3413 | Base.call(this, runner); |
---|
3414 | var self = this |
---|
3415 | , stats = this.stats |
---|
3416 | , width = Base.window.width * .75 | 0 |
---|
3417 | , rainbowColors = this.rainbowColors = self.generateColors() |
---|
3418 | , colorIndex = this.colorIndex = 0 |
---|
3419 | , numerOfLines = this.numberOfLines = 4 |
---|
3420 | , trajectories = this.trajectories = [[], [], [], []] |
---|
3421 | , nyanCatWidth = this.nyanCatWidth = 11 |
---|
3422 | , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth) |
---|
3423 | , scoreboardWidth = this.scoreboardWidth = 5 |
---|
3424 | , tick = this.tick = 0 |
---|
3425 | , n = 0; |
---|
3426 | |
---|
3427 | runner.on('start', function(){ |
---|
3428 | Base.cursor.hide(); |
---|
3429 | self.draw(); |
---|
3430 | }); |
---|
3431 | |
---|
3432 | runner.on('pending', function(test){ |
---|
3433 | self.draw(); |
---|
3434 | }); |
---|
3435 | |
---|
3436 | runner.on('pass', function(test){ |
---|
3437 | self.draw(); |
---|
3438 | }); |
---|
3439 | |
---|
3440 | runner.on('fail', function(test, err){ |
---|
3441 | self.draw(); |
---|
3442 | }); |
---|
3443 | |
---|
3444 | runner.on('end', function(){ |
---|
3445 | Base.cursor.show(); |
---|
3446 | for (var i = 0; i < self.numberOfLines; i++) write('\n'); |
---|
3447 | self.epilogue(); |
---|
3448 | }); |
---|
3449 | } |
---|
3450 | |
---|
3451 | /** |
---|
3452 | * Draw the nyan cat |
---|
3453 | * |
---|
3454 | * @api private |
---|
3455 | */ |
---|
3456 | |
---|
3457 | NyanCat.prototype.draw = function(){ |
---|
3458 | this.appendRainbow(); |
---|
3459 | this.drawScoreboard(); |
---|
3460 | this.drawRainbow(); |
---|
3461 | this.drawNyanCat(); |
---|
3462 | this.tick = !this.tick; |
---|
3463 | }; |
---|
3464 | |
---|
3465 | /** |
---|
3466 | * Draw the "scoreboard" showing the number |
---|
3467 | * of passes, failures and pending tests. |
---|
3468 | * |
---|
3469 | * @api private |
---|
3470 | */ |
---|
3471 | |
---|
3472 | NyanCat.prototype.drawScoreboard = function(){ |
---|
3473 | var stats = this.stats; |
---|
3474 | var colors = Base.colors; |
---|
3475 | |
---|
3476 | function draw(color, n) { |
---|
3477 | write(' '); |
---|
3478 | write('\u001b[' + color + 'm' + n + '\u001b[0m'); |
---|
3479 | write('\n'); |
---|
3480 | } |
---|
3481 | |
---|
3482 | draw(colors.green, stats.passes); |
---|
3483 | draw(colors.fail, stats.failures); |
---|
3484 | draw(colors.pending, stats.pending); |
---|
3485 | write('\n'); |
---|
3486 | |
---|
3487 | this.cursorUp(this.numberOfLines); |
---|
3488 | }; |
---|
3489 | |
---|
3490 | /** |
---|
3491 | * Append the rainbow. |
---|
3492 | * |
---|
3493 | * @api private |
---|
3494 | */ |
---|
3495 | |
---|
3496 | NyanCat.prototype.appendRainbow = function(){ |
---|
3497 | var segment = this.tick ? '_' : '-'; |
---|
3498 | var rainbowified = this.rainbowify(segment); |
---|
3499 | |
---|
3500 | for (var index = 0; index < this.numberOfLines; index++) { |
---|
3501 | var trajectory = this.trajectories[index]; |
---|
3502 | if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift(); |
---|
3503 | trajectory.push(rainbowified); |
---|
3504 | } |
---|
3505 | }; |
---|
3506 | |
---|
3507 | /** |
---|
3508 | * Draw the rainbow. |
---|
3509 | * |
---|
3510 | * @api private |
---|
3511 | */ |
---|
3512 | |
---|
3513 | NyanCat.prototype.drawRainbow = function(){ |
---|
3514 | var self = this; |
---|
3515 | |
---|
3516 | this.trajectories.forEach(function(line, index) { |
---|
3517 | write('\u001b[' + self.scoreboardWidth + 'C'); |
---|
3518 | write(line.join('')); |
---|
3519 | write('\n'); |
---|
3520 | }); |
---|
3521 | |
---|
3522 | this.cursorUp(this.numberOfLines); |
---|
3523 | }; |
---|
3524 | |
---|
3525 | /** |
---|
3526 | * Draw the nyan cat |
---|
3527 | * |
---|
3528 | * @api private |
---|
3529 | */ |
---|
3530 | |
---|
3531 | NyanCat.prototype.drawNyanCat = function() { |
---|
3532 | var self = this; |
---|
3533 | var startWidth = this.scoreboardWidth + this.trajectories[0].length; |
---|
3534 | var color = '\u001b[' + startWidth + 'C'; |
---|
3535 | var padding = ''; |
---|
3536 | |
---|
3537 | write(color); |
---|
3538 | write('_,------,'); |
---|
3539 | write('\n'); |
---|
3540 | |
---|
3541 | write(color); |
---|
3542 | padding = self.tick ? ' ' : ' '; |
---|
3543 | write('_|' + padding + '/\\_/\\ '); |
---|
3544 | write('\n'); |
---|
3545 | |
---|
3546 | write(color); |
---|
3547 | padding = self.tick ? '_' : '__'; |
---|
3548 | var tail = self.tick ? '~' : '^'; |
---|
3549 | var face; |
---|
3550 | write(tail + '|' + padding + this.face() + ' '); |
---|
3551 | write('\n'); |
---|
3552 | |
---|
3553 | write(color); |
---|
3554 | padding = self.tick ? ' ' : ' '; |
---|
3555 | write(padding + '"" "" '); |
---|
3556 | write('\n'); |
---|
3557 | |
---|
3558 | this.cursorUp(this.numberOfLines); |
---|
3559 | }; |
---|
3560 | |
---|
3561 | /** |
---|
3562 | * Draw nyan cat face. |
---|
3563 | * |
---|
3564 | * @return {String} |
---|
3565 | * @api private |
---|
3566 | */ |
---|
3567 | |
---|
3568 | NyanCat.prototype.face = function() { |
---|
3569 | var stats = this.stats; |
---|
3570 | if (stats.failures) { |
---|
3571 | return '( x .x)'; |
---|
3572 | } else if (stats.pending) { |
---|
3573 | return '( o .o)'; |
---|
3574 | } else if(stats.passes) { |
---|
3575 | return '( ^ .^)'; |
---|
3576 | } else { |
---|
3577 | return '( - .-)'; |
---|
3578 | } |
---|
3579 | } |
---|
3580 | |
---|
3581 | /** |
---|
3582 | * Move cursor up `n`. |
---|
3583 | * |
---|
3584 | * @param {Number} n |
---|
3585 | * @api private |
---|
3586 | */ |
---|
3587 | |
---|
3588 | NyanCat.prototype.cursorUp = function(n) { |
---|
3589 | write('\u001b[' + n + 'A'); |
---|
3590 | }; |
---|
3591 | |
---|
3592 | /** |
---|
3593 | * Move cursor down `n`. |
---|
3594 | * |
---|
3595 | * @param {Number} n |
---|
3596 | * @api private |
---|
3597 | */ |
---|
3598 | |
---|
3599 | NyanCat.prototype.cursorDown = function(n) { |
---|
3600 | write('\u001b[' + n + 'B'); |
---|
3601 | }; |
---|
3602 | |
---|
3603 | /** |
---|
3604 | * Generate rainbow colors. |
---|
3605 | * |
---|
3606 | * @return {Array} |
---|
3607 | * @api private |
---|
3608 | */ |
---|
3609 | |
---|
3610 | NyanCat.prototype.generateColors = function(){ |
---|
3611 | var colors = []; |
---|
3612 | |
---|
3613 | for (var i = 0; i < (6 * 7); i++) { |
---|
3614 | var pi3 = Math.floor(Math.PI / 3); |
---|
3615 | var n = (i * (1.0 / 6)); |
---|
3616 | var r = Math.floor(3 * Math.sin(n) + 3); |
---|
3617 | var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3); |
---|
3618 | var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3); |
---|
3619 | colors.push(36 * r + 6 * g + b + 16); |
---|
3620 | } |
---|
3621 | |
---|
3622 | return colors; |
---|
3623 | }; |
---|
3624 | |
---|
3625 | /** |
---|
3626 | * Apply rainbow to the given `str`. |
---|
3627 | * |
---|
3628 | * @param {String} str |
---|
3629 | * @return {String} |
---|
3630 | * @api private |
---|
3631 | */ |
---|
3632 | |
---|
3633 | NyanCat.prototype.rainbowify = function(str){ |
---|
3634 | var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length]; |
---|
3635 | this.colorIndex += 1; |
---|
3636 | return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m'; |
---|
3637 | }; |
---|
3638 | |
---|
3639 | /** |
---|
3640 | * Stdout helper. |
---|
3641 | */ |
---|
3642 | |
---|
3643 | function write(string) { |
---|
3644 | process.stdout.write(string); |
---|
3645 | } |
---|
3646 | |
---|
3647 | /** |
---|
3648 | * Inherit from `Base.prototype`. |
---|
3649 | */ |
---|
3650 | |
---|
3651 | function F(){}; |
---|
3652 | F.prototype = Base.prototype; |
---|
3653 | NyanCat.prototype = new F; |
---|
3654 | NyanCat.prototype.constructor = NyanCat; |
---|
3655 | |
---|
3656 | |
---|
3657 | }); // module: reporters/nyan.js |
---|
3658 | |
---|
3659 | require.register("reporters/progress.js", function(module, exports, require){ |
---|
3660 | |
---|
3661 | /** |
---|
3662 | * Module dependencies. |
---|
3663 | */ |
---|
3664 | |
---|
3665 | var Base = require('./base') |
---|
3666 | , cursor = Base.cursor |
---|
3667 | , color = Base.color; |
---|
3668 | |
---|
3669 | /** |
---|
3670 | * Expose `Progress`. |
---|
3671 | */ |
---|
3672 | |
---|
3673 | exports = module.exports = Progress; |
---|
3674 | |
---|
3675 | /** |
---|
3676 | * General progress bar color. |
---|
3677 | */ |
---|
3678 | |
---|
3679 | Base.colors.progress = 90; |
---|
3680 | |
---|
3681 | /** |
---|
3682 | * Initialize a new `Progress` bar test reporter. |
---|
3683 | * |
---|
3684 | * @param {Runner} runner |
---|
3685 | * @param {Object} options |
---|
3686 | * @api public |
---|
3687 | */ |
---|
3688 | |
---|
3689 | function Progress(runner, options) { |
---|
3690 | Base.call(this, runner); |
---|
3691 | |
---|
3692 | var self = this |
---|
3693 | , options = options || {} |
---|
3694 | , stats = this.stats |
---|
3695 | , width = Base.window.width * .50 | 0 |
---|
3696 | , total = runner.total |
---|
3697 | , complete = 0 |
---|
3698 | , max = Math.max; |
---|
3699 | |
---|
3700 | // default chars |
---|
3701 | options.open = options.open || '['; |
---|
3702 | options.complete = options.complete || 'â¬'; |
---|
3703 | options.incomplete = options.incomplete || Base.symbols.dot; |
---|
3704 | options.close = options.close || ']'; |
---|
3705 | options.verbose = false; |
---|
3706 | |
---|
3707 | // tests started |
---|
3708 | runner.on('start', function(){ |
---|
3709 | console.log(); |
---|
3710 | cursor.hide(); |
---|
3711 | }); |
---|
3712 | |
---|
3713 | // tests complete |
---|
3714 | runner.on('test end', function(){ |
---|
3715 | complete++; |
---|
3716 | var incomplete = total - complete |
---|
3717 | , percent = complete / total |
---|
3718 | , n = width * percent | 0 |
---|
3719 | , i = width - n; |
---|
3720 | |
---|
3721 | cursor.CR(); |
---|
3722 | process.stdout.write('\u001b[J'); |
---|
3723 | process.stdout.write(color('progress', ' ' + options.open)); |
---|
3724 | process.stdout.write(Array(n).join(options.complete)); |
---|
3725 | process.stdout.write(Array(i).join(options.incomplete)); |
---|
3726 | process.stdout.write(color('progress', options.close)); |
---|
3727 | if (options.verbose) { |
---|
3728 | process.stdout.write(color('progress', ' ' + complete + ' of ' + total)); |
---|
3729 | } |
---|
3730 | }); |
---|
3731 | |
---|
3732 | // tests are complete, output some stats |
---|
3733 | // and the failures if any |
---|
3734 | runner.on('end', function(){ |
---|
3735 | cursor.show(); |
---|
3736 | console.log(); |
---|
3737 | self.epilogue(); |
---|
3738 | }); |
---|
3739 | } |
---|
3740 | |
---|
3741 | /** |
---|
3742 | * Inherit from `Base.prototype`. |
---|
3743 | */ |
---|
3744 | |
---|
3745 | function F(){}; |
---|
3746 | F.prototype = Base.prototype; |
---|
3747 | Progress.prototype = new F; |
---|
3748 | Progress.prototype.constructor = Progress; |
---|
3749 | |
---|
3750 | |
---|
3751 | }); // module: reporters/progress.js |
---|
3752 | |
---|
3753 | require.register("reporters/spec.js", function(module, exports, require){ |
---|
3754 | |
---|
3755 | /** |
---|
3756 | * Module dependencies. |
---|
3757 | */ |
---|
3758 | |
---|
3759 | var Base = require('./base') |
---|
3760 | , cursor = Base.cursor |
---|
3761 | , color = Base.color; |
---|
3762 | |
---|
3763 | /** |
---|
3764 | * Expose `Spec`. |
---|
3765 | */ |
---|
3766 | |
---|
3767 | exports = module.exports = Spec; |
---|
3768 | |
---|
3769 | /** |
---|
3770 | * Initialize a new `Spec` test reporter. |
---|
3771 | * |
---|
3772 | * @param {Runner} runner |
---|
3773 | * @api public |
---|
3774 | */ |
---|
3775 | |
---|
3776 | function Spec(runner) { |
---|
3777 | Base.call(this, runner); |
---|
3778 | |
---|
3779 | var self = this |
---|
3780 | , stats = this.stats |
---|
3781 | , indents = 0 |
---|
3782 | , n = 0; |
---|
3783 | |
---|
3784 | function indent() { |
---|
3785 | return Array(indents).join(' ') |
---|
3786 | } |
---|
3787 | |
---|
3788 | runner.on('start', function(){ |
---|
3789 | console.log(); |
---|
3790 | }); |
---|
3791 | |
---|
3792 | runner.on('suite', function(suite){ |
---|
3793 | ++indents; |
---|
3794 | console.log(color('suite', '%s%s'), indent(), suite.title); |
---|
3795 | }); |
---|
3796 | |
---|
3797 | runner.on('suite end', function(suite){ |
---|
3798 | --indents; |
---|
3799 | if (1 == indents) console.log(); |
---|
3800 | }); |
---|
3801 | |
---|
3802 | runner.on('test', function(test){ |
---|
3803 | process.stdout.write(indent() + color('pass', ' ⊠' + test.title + ': ')); |
---|
3804 | }); |
---|
3805 | |
---|
3806 | runner.on('pending', function(test){ |
---|
3807 | var fmt = indent() + color('pending', ' - %s'); |
---|
3808 | console.log(fmt, test.title); |
---|
3809 | }); |
---|
3810 | |
---|
3811 | runner.on('pass', function(test){ |
---|
3812 | if ('fast' == test.speed) { |
---|
3813 | var fmt = indent() |
---|
3814 | + color('checkmark', ' ' + Base.symbols.ok) |
---|
3815 | + color('pass', ' %s '); |
---|
3816 | cursor.CR(); |
---|
3817 | console.log(fmt, test.title); |
---|
3818 | } else { |
---|
3819 | var fmt = indent() |
---|
3820 | + color('checkmark', ' ' + Base.symbols.ok) |
---|
3821 | + color('pass', ' %s ') |
---|
3822 | + color(test.speed, '(%dms)'); |
---|
3823 | cursor.CR(); |
---|
3824 | console.log(fmt, test.title, test.duration); |
---|
3825 | } |
---|
3826 | }); |
---|
3827 | |
---|
3828 | runner.on('fail', function(test, err){ |
---|
3829 | cursor.CR(); |
---|
3830 | console.log(indent() + color('fail', ' %d) %s'), ++n, test.title); |
---|
3831 | }); |
---|
3832 | |
---|
3833 | runner.on('end', self.epilogue.bind(self)); |
---|
3834 | } |
---|
3835 | |
---|
3836 | /** |
---|
3837 | * Inherit from `Base.prototype`. |
---|
3838 | */ |
---|
3839 | |
---|
3840 | function F(){}; |
---|
3841 | F.prototype = Base.prototype; |
---|
3842 | Spec.prototype = new F; |
---|
3843 | Spec.prototype.constructor = Spec; |
---|
3844 | |
---|
3845 | |
---|
3846 | }); // module: reporters/spec.js |
---|
3847 | |
---|
3848 | require.register("reporters/tap.js", function(module, exports, require){ |
---|
3849 | |
---|
3850 | /** |
---|
3851 | * Module dependencies. |
---|
3852 | */ |
---|
3853 | |
---|
3854 | var Base = require('./base') |
---|
3855 | , cursor = Base.cursor |
---|
3856 | , color = Base.color; |
---|
3857 | |
---|
3858 | /** |
---|
3859 | * Expose `TAP`. |
---|
3860 | */ |
---|
3861 | |
---|
3862 | exports = module.exports = TAP; |
---|
3863 | |
---|
3864 | /** |
---|
3865 | * Initialize a new `TAP` reporter. |
---|
3866 | * |
---|
3867 | * @param {Runner} runner |
---|
3868 | * @api public |
---|
3869 | */ |
---|
3870 | |
---|
3871 | function TAP(runner) { |
---|
3872 | Base.call(this, runner); |
---|
3873 | |
---|
3874 | var self = this |
---|
3875 | , stats = this.stats |
---|
3876 | , n = 1 |
---|
3877 | , passes = 0 |
---|
3878 | , failures = 0; |
---|
3879 | |
---|
3880 | runner.on('start', function(){ |
---|
3881 | var total = runner.grepTotal(runner.suite); |
---|
3882 | console.log('%d..%d', 1, total); |
---|
3883 | }); |
---|
3884 | |
---|
3885 | runner.on('test end', function(){ |
---|
3886 | ++n; |
---|
3887 | }); |
---|
3888 | |
---|
3889 | runner.on('pending', function(test){ |
---|
3890 | console.log('ok %d %s # SKIP -', n, title(test)); |
---|
3891 | }); |
---|
3892 | |
---|
3893 | runner.on('pass', function(test){ |
---|
3894 | passes++; |
---|
3895 | console.log('ok %d %s', n, title(test)); |
---|
3896 | }); |
---|
3897 | |
---|
3898 | runner.on('fail', function(test, err){ |
---|
3899 | failures++; |
---|
3900 | console.log('not ok %d %s', n, title(test)); |
---|
3901 | if (err.stack) console.log(err.stack.replace(/^/gm, ' ')); |
---|
3902 | }); |
---|
3903 | |
---|
3904 | runner.on('end', function(){ |
---|
3905 | console.log('# tests ' + (passes + failures)); |
---|
3906 | console.log('# pass ' + passes); |
---|
3907 | console.log('# fail ' + failures); |
---|
3908 | }); |
---|
3909 | } |
---|
3910 | |
---|
3911 | /** |
---|
3912 | * Return a TAP-safe title of `test` |
---|
3913 | * |
---|
3914 | * @param {Object} test |
---|
3915 | * @return {String} |
---|
3916 | * @api private |
---|
3917 | */ |
---|
3918 | |
---|
3919 | function title(test) { |
---|
3920 | return test.fullTitle().replace(/#/g, ''); |
---|
3921 | } |
---|
3922 | |
---|
3923 | }); // module: reporters/tap.js |
---|
3924 | |
---|
3925 | require.register("reporters/xunit.js", function(module, exports, require){ |
---|
3926 | |
---|
3927 | /** |
---|
3928 | * Module dependencies. |
---|
3929 | */ |
---|
3930 | |
---|
3931 | var Base = require('./base') |
---|
3932 | , utils = require('../utils') |
---|
3933 | , escape = utils.escape; |
---|
3934 | |
---|
3935 | /** |
---|
3936 | * Save timer references to avoid Sinon interfering (see GH-237). |
---|
3937 | */ |
---|
3938 | |
---|
3939 | var Date = global.Date |
---|
3940 | , setTimeout = global.setTimeout |
---|
3941 | , setInterval = global.setInterval |
---|
3942 | , clearTimeout = global.clearTimeout |
---|
3943 | , clearInterval = global.clearInterval; |
---|
3944 | |
---|
3945 | /** |
---|
3946 | * Expose `XUnit`. |
---|
3947 | */ |
---|
3948 | |
---|
3949 | exports = module.exports = XUnit; |
---|
3950 | |
---|
3951 | /** |
---|
3952 | * Initialize a new `XUnit` reporter. |
---|
3953 | * |
---|
3954 | * @param {Runner} runner |
---|
3955 | * @api public |
---|
3956 | */ |
---|
3957 | |
---|
3958 | function XUnit(runner) { |
---|
3959 | Base.call(this, runner); |
---|
3960 | var stats = this.stats |
---|
3961 | , tests = [] |
---|
3962 | , self = this; |
---|
3963 | |
---|
3964 | runner.on('pass', function(test){ |
---|
3965 | tests.push(test); |
---|
3966 | }); |
---|
3967 | |
---|
3968 | runner.on('fail', function(test){ |
---|
3969 | tests.push(test); |
---|
3970 | }); |
---|
3971 | |
---|
3972 | runner.on('end', function(){ |
---|
3973 | console.log(tag('testsuite', { |
---|
3974 | name: 'Mocha Tests' |
---|
3975 | , tests: stats.tests |
---|
3976 | , failures: stats.failures |
---|
3977 | , errors: stats.failures |
---|
3978 | , skipped: stats.tests - stats.failures - stats.passes |
---|
3979 | , timestamp: (new Date).toUTCString() |
---|
3980 | , time: (stats.duration / 1000) || 0 |
---|
3981 | }, false)); |
---|
3982 | |
---|
3983 | tests.forEach(test); |
---|
3984 | console.log('</testsuite>'); |
---|
3985 | }); |
---|
3986 | } |
---|
3987 | |
---|
3988 | /** |
---|
3989 | * Inherit from `Base.prototype`. |
---|
3990 | */ |
---|
3991 | |
---|
3992 | function F(){}; |
---|
3993 | F.prototype = Base.prototype; |
---|
3994 | XUnit.prototype = new F; |
---|
3995 | XUnit.prototype.constructor = XUnit; |
---|
3996 | |
---|
3997 | |
---|
3998 | /** |
---|
3999 | * Output tag for the given `test.` |
---|
4000 | */ |
---|
4001 | |
---|
4002 | function test(test) { |
---|
4003 | var attrs = { |
---|
4004 | classname: test.parent.fullTitle() |
---|
4005 | , name: test.title |
---|
4006 | , time: test.duration / 1000 |
---|
4007 | }; |
---|
4008 | |
---|
4009 | if ('failed' == test.state) { |
---|
4010 | var err = test.err; |
---|
4011 | attrs.message = escape(err.message); |
---|
4012 | console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack)))); |
---|
4013 | } else if (test.pending) { |
---|
4014 | console.log(tag('testcase', attrs, false, tag('skipped', {}, true))); |
---|
4015 | } else { |
---|
4016 | console.log(tag('testcase', attrs, true) ); |
---|
4017 | } |
---|
4018 | } |
---|
4019 | |
---|
4020 | /** |
---|
4021 | * HTML tag helper. |
---|
4022 | */ |
---|
4023 | |
---|
4024 | function tag(name, attrs, close, content) { |
---|
4025 | var end = close ? '/>' : '>' |
---|
4026 | , pairs = [] |
---|
4027 | , tag; |
---|
4028 | |
---|
4029 | for (var key in attrs) { |
---|
4030 | pairs.push(key + '="' + escape(attrs[key]) + '"'); |
---|
4031 | } |
---|
4032 | |
---|
4033 | tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end; |
---|
4034 | if (content) tag += content + '</' + name + end; |
---|
4035 | return tag; |
---|
4036 | } |
---|
4037 | |
---|
4038 | /** |
---|
4039 | * Return cdata escaped CDATA `str`. |
---|
4040 | */ |
---|
4041 | |
---|
4042 | function cdata(str) { |
---|
4043 | return '<![CDATA[' + escape(str) + ']]>'; |
---|
4044 | } |
---|
4045 | |
---|
4046 | }); // module: reporters/xunit.js |
---|
4047 | |
---|
4048 | require.register("runnable.js", function(module, exports, require){ |
---|
4049 | |
---|
4050 | /** |
---|
4051 | * Module dependencies. |
---|
4052 | */ |
---|
4053 | |
---|
4054 | var EventEmitter = require('browser/events').EventEmitter |
---|
4055 | , debug = require('browser/debug')('mocha:runnable') |
---|
4056 | , milliseconds = require('./ms'); |
---|
4057 | |
---|
4058 | /** |
---|
4059 | * Save timer references to avoid Sinon interfering (see GH-237). |
---|
4060 | */ |
---|
4061 | |
---|
4062 | var Date = global.Date |
---|
4063 | , setTimeout = global.setTimeout |
---|
4064 | , setInterval = global.setInterval |
---|
4065 | , clearTimeout = global.clearTimeout |
---|
4066 | , clearInterval = global.clearInterval; |
---|
4067 | |
---|
4068 | /** |
---|
4069 | * Object#toString(). |
---|
4070 | */ |
---|
4071 | |
---|
4072 | var toString = Object.prototype.toString; |
---|
4073 | |
---|
4074 | /** |
---|
4075 | * Expose `Runnable`. |
---|
4076 | */ |
---|
4077 | |
---|
4078 | module.exports = Runnable; |
---|
4079 | |
---|
4080 | /** |
---|
4081 | * Initialize a new `Runnable` with the given `title` and callback `fn`. |
---|
4082 | * |
---|
4083 | * @param {String} title |
---|
4084 | * @param {Function} fn |
---|
4085 | * @api private |
---|
4086 | */ |
---|
4087 | |
---|
4088 | function Runnable(title, fn) { |
---|
4089 | this.title = title; |
---|
4090 | this.fn = fn; |
---|
4091 | this.async = fn && fn.length; |
---|
4092 | this.sync = ! this.async; |
---|
4093 | this._timeout = 2000; |
---|
4094 | this._slow = 75; |
---|
4095 | this.timedOut = false; |
---|
4096 | } |
---|
4097 | |
---|
4098 | /** |
---|
4099 | * Inherit from `EventEmitter.prototype`. |
---|
4100 | */ |
---|
4101 | |
---|
4102 | function F(){}; |
---|
4103 | F.prototype = EventEmitter.prototype; |
---|
4104 | Runnable.prototype = new F; |
---|
4105 | Runnable.prototype.constructor = Runnable; |
---|
4106 | |
---|
4107 | |
---|
4108 | /** |
---|
4109 | * Set & get timeout `ms`. |
---|
4110 | * |
---|
4111 | * @param {Number|String} ms |
---|
4112 | * @return {Runnable|Number} ms or self |
---|
4113 | * @api private |
---|
4114 | */ |
---|
4115 | |
---|
4116 | Runnable.prototype.timeout = function(ms){ |
---|
4117 | if (0 == arguments.length) return this._timeout; |
---|
4118 | if ('string' == typeof ms) ms = milliseconds(ms); |
---|
4119 | debug('timeout %d', ms); |
---|
4120 | this._timeout = ms; |
---|
4121 | if (this.timer) this.resetTimeout(); |
---|
4122 | return this; |
---|
4123 | }; |
---|
4124 | |
---|
4125 | /** |
---|
4126 | * Set & get slow `ms`. |
---|
4127 | * |
---|
4128 | * @param {Number|String} ms |
---|
4129 | * @return {Runnable|Number} ms or self |
---|
4130 | * @api private |
---|
4131 | */ |
---|
4132 | |
---|
4133 | Runnable.prototype.slow = function(ms){ |
---|
4134 | if (0 === arguments.length) return this._slow; |
---|
4135 | if ('string' == typeof ms) ms = milliseconds(ms); |
---|
4136 | debug('timeout %d', ms); |
---|
4137 | this._slow = ms; |
---|
4138 | return this; |
---|
4139 | }; |
---|
4140 | |
---|
4141 | /** |
---|
4142 | * Return the full title generated by recursively |
---|
4143 | * concatenating the parent's full title. |
---|
4144 | * |
---|
4145 | * @return {String} |
---|
4146 | * @api public |
---|
4147 | */ |
---|
4148 | |
---|
4149 | Runnable.prototype.fullTitle = function(){ |
---|
4150 | return this.parent.fullTitle() + ' ' + this.title; |
---|
4151 | }; |
---|
4152 | |
---|
4153 | /** |
---|
4154 | * Clear the timeout. |
---|
4155 | * |
---|
4156 | * @api private |
---|
4157 | */ |
---|
4158 | |
---|
4159 | Runnable.prototype.clearTimeout = function(){ |
---|
4160 | clearTimeout(this.timer); |
---|
4161 | }; |
---|
4162 | |
---|
4163 | /** |
---|
4164 | * Inspect the runnable void of private properties. |
---|
4165 | * |
---|
4166 | * @return {String} |
---|
4167 | * @api private |
---|
4168 | */ |
---|
4169 | |
---|
4170 | Runnable.prototype.inspect = function(){ |
---|
4171 | return JSON.stringify(this, function(key, val){ |
---|
4172 | if ('_' == key[0]) return; |
---|
4173 | if ('parent' == key) return '#<Suite>'; |
---|
4174 | if ('ctx' == key) return '#<Context>'; |
---|
4175 | return val; |
---|
4176 | }, 2); |
---|
4177 | }; |
---|
4178 | |
---|
4179 | /** |
---|
4180 | * Reset the timeout. |
---|
4181 | * |
---|
4182 | * @api private |
---|
4183 | */ |
---|
4184 | |
---|
4185 | Runnable.prototype.resetTimeout = function(){ |
---|
4186 | var self = this; |
---|
4187 | var ms = this.timeout() || 1e9; |
---|
4188 | |
---|
4189 | this.clearTimeout(); |
---|
4190 | this.timer = setTimeout(function(){ |
---|
4191 | self.callback(new Error('timeout of ' + ms + 'ms exceeded')); |
---|
4192 | self.timedOut = true; |
---|
4193 | }, ms); |
---|
4194 | }; |
---|
4195 | |
---|
4196 | /** |
---|
4197 | * Run the test and invoke `fn(err)`. |
---|
4198 | * |
---|
4199 | * @param {Function} fn |
---|
4200 | * @api private |
---|
4201 | */ |
---|
4202 | |
---|
4203 | Runnable.prototype.run = function(fn){ |
---|
4204 | var self = this |
---|
4205 | , ms = this.timeout() |
---|
4206 | , start = new Date |
---|
4207 | , ctx = this.ctx |
---|
4208 | , finished |
---|
4209 | , emitted; |
---|
4210 | |
---|
4211 | if (ctx) ctx.runnable(this); |
---|
4212 | |
---|
4213 | // timeout |
---|
4214 | if (this.async) { |
---|
4215 | if (ms) { |
---|
4216 | this.timer = setTimeout(function(){ |
---|
4217 | done(new Error('timeout of ' + ms + 'ms exceeded')); |
---|
4218 | self.timedOut = true; |
---|
4219 | }, ms); |
---|
4220 | } |
---|
4221 | } |
---|
4222 | |
---|
4223 | // called multiple times |
---|
4224 | function multiple(err) { |
---|
4225 | if (emitted) return; |
---|
4226 | emitted = true; |
---|
4227 | self.emit('error', err || new Error('done() called multiple times')); |
---|
4228 | } |
---|
4229 | |
---|
4230 | // finished |
---|
4231 | function done(err) { |
---|
4232 | if (self.timedOut) return; |
---|
4233 | if (finished) return multiple(err); |
---|
4234 | self.clearTimeout(); |
---|
4235 | self.duration = new Date - start; |
---|
4236 | finished = true; |
---|
4237 | fn(err); |
---|
4238 | } |
---|
4239 | |
---|
4240 | // for .resetTimeout() |
---|
4241 | this.callback = done; |
---|
4242 | |
---|
4243 | // async |
---|
4244 | if (this.async) { |
---|
4245 | try { |
---|
4246 | this.fn.call(ctx, function(err){ |
---|
4247 | if (err instanceof Error || toString.call(err) === "[object Error]") return done(err); |
---|
4248 | if (null != err) return done(new Error('done() invoked with non-Error: ' + err)); |
---|
4249 | done(); |
---|
4250 | }); |
---|
4251 | } catch (err) { |
---|
4252 | done(err); |
---|
4253 | } |
---|
4254 | return; |
---|
4255 | } |
---|
4256 | |
---|
4257 | if (this.asyncOnly) { |
---|
4258 | return done(new Error('--async-only option in use without declaring `done()`')); |
---|
4259 | } |
---|
4260 | |
---|
4261 | // sync |
---|
4262 | try { |
---|
4263 | if (!this.pending) this.fn.call(ctx); |
---|
4264 | this.duration = new Date - start; |
---|
4265 | fn(); |
---|
4266 | } catch (err) { |
---|
4267 | fn(err); |
---|
4268 | } |
---|
4269 | }; |
---|
4270 | |
---|
4271 | }); // module: runnable.js |
---|
4272 | |
---|
4273 | require.register("runner.js", function(module, exports, require){ |
---|
4274 | /** |
---|
4275 | * Module dependencies. |
---|
4276 | */ |
---|
4277 | |
---|
4278 | var EventEmitter = require('browser/events').EventEmitter |
---|
4279 | , debug = require('browser/debug')('mocha:runner') |
---|
4280 | , Test = require('./test') |
---|
4281 | , utils = require('./utils') |
---|
4282 | , filter = utils.filter |
---|
4283 | , keys = utils.keys; |
---|
4284 | |
---|
4285 | /** |
---|
4286 | * Non-enumerable globals. |
---|
4287 | */ |
---|
4288 | |
---|
4289 | var globals = [ |
---|
4290 | 'setTimeout', |
---|
4291 | 'clearTimeout', |
---|
4292 | 'setInterval', |
---|
4293 | 'clearInterval', |
---|
4294 | 'XMLHttpRequest', |
---|
4295 | 'Date' |
---|
4296 | ]; |
---|
4297 | |
---|
4298 | /** |
---|
4299 | * Expose `Runner`. |
---|
4300 | */ |
---|
4301 | |
---|
4302 | module.exports = Runner; |
---|
4303 | |
---|
4304 | /** |
---|
4305 | * Initialize a `Runner` for the given `suite`. |
---|
4306 | * |
---|
4307 | * Events: |
---|
4308 | * |
---|
4309 | * - `start` execution started |
---|
4310 | * - `end` execution complete |
---|
4311 | * - `suite` (suite) test suite execution started |
---|
4312 | * - `suite end` (suite) all tests (and sub-suites) have finished |
---|
4313 | * - `test` (test) test execution started |
---|
4314 | * - `test end` (test) test completed |
---|
4315 | * - `hook` (hook) hook execution started |
---|
4316 | * - `hook end` (hook) hook complete |
---|
4317 | * - `pass` (test) test passed |
---|
4318 | * - `fail` (test, err) test failed |
---|
4319 | * - `pending` (test) test pending |
---|
4320 | * |
---|
4321 | * @api public |
---|
4322 | */ |
---|
4323 | |
---|
4324 | function Runner(suite) { |
---|
4325 | var self = this; |
---|
4326 | this._globals = []; |
---|
4327 | this.suite = suite; |
---|
4328 | this.total = suite.total(); |
---|
4329 | this.failures = 0; |
---|
4330 | this.on('test end', function(test){ self.checkGlobals(test); }); |
---|
4331 | this.on('hook end', function(hook){ self.checkGlobals(hook); }); |
---|
4332 | this.grep(/.*/); |
---|
4333 | this.globals(this.globalProps().concat(['errno'])); |
---|
4334 | } |
---|
4335 | |
---|
4336 | /** |
---|
4337 | * Wrapper for setImmediate, process.nextTick, or browser polyfill. |
---|
4338 | * |
---|
4339 | * @param {Function} fn |
---|
4340 | * @api private |
---|
4341 | */ |
---|
4342 | |
---|
4343 | Runner.immediately = global.setImmediate || process.nextTick; |
---|
4344 | |
---|
4345 | /** |
---|
4346 | * Inherit from `EventEmitter.prototype`. |
---|
4347 | */ |
---|
4348 | |
---|
4349 | function F(){}; |
---|
4350 | F.prototype = EventEmitter.prototype; |
---|
4351 | Runner.prototype = new F; |
---|
4352 | Runner.prototype.constructor = Runner; |
---|
4353 | |
---|
4354 | |
---|
4355 | /** |
---|
4356 | * Run tests with full titles matching `re`. Updates runner.total |
---|
4357 | * with number of tests matched. |
---|
4358 | * |
---|
4359 | * @param {RegExp} re |
---|
4360 | * @param {Boolean} invert |
---|
4361 | * @return {Runner} for chaining |
---|
4362 | * @api public |
---|
4363 | */ |
---|
4364 | |
---|
4365 | Runner.prototype.grep = function(re, invert){ |
---|
4366 | debug('grep %s', re); |
---|
4367 | this._grep = re; |
---|
4368 | this._invert = invert; |
---|
4369 | this.total = this.grepTotal(this.suite); |
---|
4370 | return this; |
---|
4371 | }; |
---|
4372 | |
---|
4373 | /** |
---|
4374 | * Returns the number of tests matching the grep search for the |
---|
4375 | * given suite. |
---|
4376 | * |
---|
4377 | * @param {Suite} suite |
---|
4378 | * @return {Number} |
---|
4379 | * @api public |
---|
4380 | */ |
---|
4381 | |
---|
4382 | Runner.prototype.grepTotal = function(suite) { |
---|
4383 | var self = this; |
---|
4384 | var total = 0; |
---|
4385 | |
---|
4386 | suite.eachTest(function(test){ |
---|
4387 | var match = self._grep.test(test.fullTitle()); |
---|
4388 | if (self._invert) match = !match; |
---|
4389 | if (match) total++; |
---|
4390 | }); |
---|
4391 | |
---|
4392 | return total; |
---|
4393 | }; |
---|
4394 | |
---|
4395 | /** |
---|
4396 | * Return a list of global properties. |
---|
4397 | * |
---|
4398 | * @return {Array} |
---|
4399 | * @api private |
---|
4400 | */ |
---|
4401 | |
---|
4402 | Runner.prototype.globalProps = function() { |
---|
4403 | var props = utils.keys(global); |
---|
4404 | |
---|
4405 | // non-enumerables |
---|
4406 | for (var i = 0; i < globals.length; ++i) { |
---|
4407 | if (~utils.indexOf(props, globals[i])) continue; |
---|
4408 | props.push(globals[i]); |
---|
4409 | } |
---|
4410 | |
---|
4411 | return props; |
---|
4412 | }; |
---|
4413 | |
---|
4414 | /** |
---|
4415 | * Allow the given `arr` of globals. |
---|
4416 | * |
---|
4417 | * @param {Array} arr |
---|
4418 | * @return {Runner} for chaining |
---|
4419 | * @api public |
---|
4420 | */ |
---|
4421 | |
---|
4422 | Runner.prototype.globals = function(arr){ |
---|
4423 | if (0 == arguments.length) return this._globals; |
---|
4424 | debug('globals %j', arr); |
---|
4425 | utils.forEach(arr, function(arr){ |
---|
4426 | this._globals.push(arr); |
---|
4427 | }, this); |
---|
4428 | return this; |
---|
4429 | }; |
---|
4430 | |
---|
4431 | /** |
---|
4432 | * Check for global variable leaks. |
---|
4433 | * |
---|
4434 | * @api private |
---|
4435 | */ |
---|
4436 | |
---|
4437 | Runner.prototype.checkGlobals = function(test){ |
---|
4438 | if (this.ignoreLeaks) return; |
---|
4439 | var ok = this._globals; |
---|
4440 | var globals = this.globalProps(); |
---|
4441 | var isNode = process.kill; |
---|
4442 | var leaks; |
---|
4443 | |
---|
4444 | // check length - 2 ('errno' and 'location' globals) |
---|
4445 | if (isNode && 1 == ok.length - globals.length) return; |
---|
4446 | else if (2 == ok.length - globals.length) return; |
---|
4447 | |
---|
4448 | if(this.prevGlobalsLength == globals.length) return; |
---|
4449 | this.prevGlobalsLength = globals.length; |
---|
4450 | |
---|
4451 | leaks = filterLeaks(ok, globals); |
---|
4452 | this._globals = this._globals.concat(leaks); |
---|
4453 | |
---|
4454 | if (leaks.length > 1) { |
---|
4455 | this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + '')); |
---|
4456 | } else if (leaks.length) { |
---|
4457 | this.fail(test, new Error('global leak detected: ' + leaks[0])); |
---|
4458 | } |
---|
4459 | }; |
---|
4460 | |
---|
4461 | /** |
---|
4462 | * Fail the given `test`. |
---|
4463 | * |
---|
4464 | * @param {Test} test |
---|
4465 | * @param {Error} err |
---|
4466 | * @api private |
---|
4467 | */ |
---|
4468 | |
---|
4469 | Runner.prototype.fail = function(test, err){ |
---|
4470 | ++this.failures; |
---|
4471 | test.state = 'failed'; |
---|
4472 | |
---|
4473 | if ('string' == typeof err) { |
---|
4474 | err = new Error('the string "' + err + '" was thrown, throw an Error :)'); |
---|
4475 | } |
---|
4476 | |
---|
4477 | this.emit('fail', test, err); |
---|
4478 | }; |
---|
4479 | |
---|
4480 | /** |
---|
4481 | * Fail the given `hook` with `err`. |
---|
4482 | * |
---|
4483 | * Hook failures (currently) hard-end due |
---|
4484 | * to that fact that a failing hook will |
---|
4485 | * surely cause subsequent tests to fail, |
---|
4486 | * causing jumbled reporting. |
---|
4487 | * |
---|
4488 | * @param {Hook} hook |
---|
4489 | * @param {Error} err |
---|
4490 | * @api private |
---|
4491 | */ |
---|
4492 | |
---|
4493 | Runner.prototype.failHook = function(hook, err){ |
---|
4494 | this.fail(hook, err); |
---|
4495 | this.emit('end'); |
---|
4496 | }; |
---|
4497 | |
---|
4498 | /** |
---|
4499 | * Run hook `name` callbacks and then invoke `fn()`. |
---|
4500 | * |
---|
4501 | * @param {String} name |
---|
4502 | * @param {Function} function |
---|
4503 | * @api private |
---|
4504 | */ |
---|
4505 | |
---|
4506 | Runner.prototype.hook = function(name, fn){ |
---|
4507 | var suite = this.suite |
---|
4508 | , hooks = suite['_' + name] |
---|
4509 | , self = this |
---|
4510 | , timer; |
---|
4511 | |
---|
4512 | function next(i) { |
---|
4513 | var hook = hooks[i]; |
---|
4514 | if (!hook) return fn(); |
---|
4515 | if (self.failures && suite.bail()) return fn(); |
---|
4516 | self.currentRunnable = hook; |
---|
4517 | |
---|
4518 | hook.ctx.currentTest = self.test; |
---|
4519 | |
---|
4520 | self.emit('hook', hook); |
---|
4521 | |
---|
4522 | hook.on('error', function(err){ |
---|
4523 | self.failHook(hook, err); |
---|
4524 | }); |
---|
4525 | |
---|
4526 | hook.run(function(err){ |
---|
4527 | hook.removeAllListeners('error'); |
---|
4528 | var testError = hook.error(); |
---|
4529 | if (testError) self.fail(self.test, testError); |
---|
4530 | if (err) return self.failHook(hook, err); |
---|
4531 | self.emit('hook end', hook); |
---|
4532 | delete hook.ctx.currentTest; |
---|
4533 | next(++i); |
---|
4534 | }); |
---|
4535 | } |
---|
4536 | |
---|
4537 | Runner.immediately(function(){ |
---|
4538 | next(0); |
---|
4539 | }); |
---|
4540 | }; |
---|
4541 | |
---|
4542 | /** |
---|
4543 | * Run hook `name` for the given array of `suites` |
---|
4544 | * in order, and callback `fn(err)`. |
---|
4545 | * |
---|
4546 | * @param {String} name |
---|
4547 | * @param {Array} suites |
---|
4548 | * @param {Function} fn |
---|
4549 | * @api private |
---|
4550 | */ |
---|
4551 | |
---|
4552 | Runner.prototype.hooks = function(name, suites, fn){ |
---|
4553 | var self = this |
---|
4554 | , orig = this.suite; |
---|
4555 | |
---|
4556 | function next(suite) { |
---|
4557 | self.suite = suite; |
---|
4558 | |
---|
4559 | if (!suite) { |
---|
4560 | self.suite = orig; |
---|
4561 | return fn(); |
---|
4562 | } |
---|
4563 | |
---|
4564 | self.hook(name, function(err){ |
---|
4565 | if (err) { |
---|
4566 | self.suite = orig; |
---|
4567 | return fn(err); |
---|
4568 | } |
---|
4569 | |
---|
4570 | next(suites.pop()); |
---|
4571 | }); |
---|
4572 | } |
---|
4573 | |
---|
4574 | next(suites.pop()); |
---|
4575 | }; |
---|
4576 | |
---|
4577 | /** |
---|
4578 | * Run hooks from the top level down. |
---|
4579 | * |
---|
4580 | * @param {String} name |
---|
4581 | * @param {Function} fn |
---|
4582 | * @api private |
---|
4583 | */ |
---|
4584 | |
---|
4585 | Runner.prototype.hookUp = function(name, fn){ |
---|
4586 | var suites = [this.suite].concat(this.parents()).reverse(); |
---|
4587 | this.hooks(name, suites, fn); |
---|
4588 | }; |
---|
4589 | |
---|
4590 | /** |
---|
4591 | * Run hooks from the bottom up. |
---|
4592 | * |
---|
4593 | * @param {String} name |
---|
4594 | * @param {Function} fn |
---|
4595 | * @api private |
---|
4596 | */ |
---|
4597 | |
---|
4598 | Runner.prototype.hookDown = function(name, fn){ |
---|
4599 | var suites = [this.suite].concat(this.parents()); |
---|
4600 | this.hooks(name, suites, fn); |
---|
4601 | }; |
---|
4602 | |
---|
4603 | /** |
---|
4604 | * Return an array of parent Suites from |
---|
4605 | * closest to furthest. |
---|
4606 | * |
---|
4607 | * @return {Array} |
---|
4608 | * @api private |
---|
4609 | */ |
---|
4610 | |
---|
4611 | Runner.prototype.parents = function(){ |
---|
4612 | var suite = this.suite |
---|
4613 | , suites = []; |
---|
4614 | while (suite = suite.parent) suites.push(suite); |
---|
4615 | return suites; |
---|
4616 | }; |
---|
4617 | |
---|
4618 | /** |
---|
4619 | * Run the current test and callback `fn(err)`. |
---|
4620 | * |
---|
4621 | * @param {Function} fn |
---|
4622 | * @api private |
---|
4623 | */ |
---|
4624 | |
---|
4625 | Runner.prototype.runTest = function(fn){ |
---|
4626 | var test = this.test |
---|
4627 | , self = this; |
---|
4628 | |
---|
4629 | if (this.asyncOnly) test.asyncOnly = true; |
---|
4630 | |
---|
4631 | try { |
---|
4632 | test.on('error', function(err){ |
---|
4633 | self.fail(test, err); |
---|
4634 | }); |
---|
4635 | test.run(fn); |
---|
4636 | } catch (err) { |
---|
4637 | fn(err); |
---|
4638 | } |
---|
4639 | }; |
---|
4640 | |
---|
4641 | /** |
---|
4642 | * Run tests in the given `suite` and invoke |
---|
4643 | * the callback `fn()` when complete. |
---|
4644 | * |
---|
4645 | * @param {Suite} suite |
---|
4646 | * @param {Function} fn |
---|
4647 | * @api private |
---|
4648 | */ |
---|
4649 | |
---|
4650 | Runner.prototype.runTests = function(suite, fn){ |
---|
4651 | var self = this |
---|
4652 | , tests = suite.tests.slice() |
---|
4653 | , test; |
---|
4654 | |
---|
4655 | function next(err) { |
---|
4656 | // if we bail after first err |
---|
4657 | if (self.failures && suite._bail) return fn(); |
---|
4658 | |
---|
4659 | // next test |
---|
4660 | test = tests.shift(); |
---|
4661 | |
---|
4662 | // all done |
---|
4663 | if (!test) return fn(); |
---|
4664 | |
---|
4665 | // grep |
---|
4666 | var match = self._grep.test(test.fullTitle()); |
---|
4667 | if (self._invert) match = !match; |
---|
4668 | if (!match) return next(); |
---|
4669 | |
---|
4670 | // pending |
---|
4671 | if (test.pending) { |
---|
4672 | self.emit('pending', test); |
---|
4673 | self.emit('test end', test); |
---|
4674 | return next(); |
---|
4675 | } |
---|
4676 | |
---|
4677 | // execute test and hook(s) |
---|
4678 | self.emit('test', self.test = test); |
---|
4679 | self.hookDown('beforeEach', function(){ |
---|
4680 | self.currentRunnable = self.test; |
---|
4681 | self.runTest(function(err){ |
---|
4682 | test = self.test; |
---|
4683 | |
---|
4684 | if (err) { |
---|
4685 | self.fail(test, err); |
---|
4686 | self.emit('test end', test); |
---|
4687 | return self.hookUp('afterEach', next); |
---|
4688 | } |
---|
4689 | |
---|
4690 | test.state = 'passed'; |
---|
4691 | self.emit('pass', test); |
---|
4692 | self.emit('test end', test); |
---|
4693 | self.hookUp('afterEach', next); |
---|
4694 | }); |
---|
4695 | }); |
---|
4696 | } |
---|
4697 | |
---|
4698 | this.next = next; |
---|
4699 | next(); |
---|
4700 | }; |
---|
4701 | |
---|
4702 | /** |
---|
4703 | * Run the given `suite` and invoke the |
---|
4704 | * callback `fn()` when complete. |
---|
4705 | * |
---|
4706 | * @param {Suite} suite |
---|
4707 | * @param {Function} fn |
---|
4708 | * @api private |
---|
4709 | */ |
---|
4710 | |
---|
4711 | Runner.prototype.runSuite = function(suite, fn){ |
---|
4712 | var total = this.grepTotal(suite) |
---|
4713 | , self = this |
---|
4714 | , i = 0; |
---|
4715 | |
---|
4716 | debug('run suite %s', suite.fullTitle()); |
---|
4717 | |
---|
4718 | if (!total) return fn(); |
---|
4719 | |
---|
4720 | this.emit('suite', this.suite = suite); |
---|
4721 | |
---|
4722 | function next() { |
---|
4723 | var curr = suite.suites[i++]; |
---|
4724 | if (!curr) return done(); |
---|
4725 | self.runSuite(curr, next); |
---|
4726 | } |
---|
4727 | |
---|
4728 | function done() { |
---|
4729 | self.suite = suite; |
---|
4730 | self.hook('afterAll', function(){ |
---|
4731 | self.emit('suite end', suite); |
---|
4732 | fn(); |
---|
4733 | }); |
---|
4734 | } |
---|
4735 | |
---|
4736 | this.hook('beforeAll', function(){ |
---|
4737 | self.runTests(suite, next); |
---|
4738 | }); |
---|
4739 | }; |
---|
4740 | |
---|
4741 | /** |
---|
4742 | * Handle uncaught exceptions. |
---|
4743 | * |
---|
4744 | * @param {Error} err |
---|
4745 | * @api private |
---|
4746 | */ |
---|
4747 | |
---|
4748 | Runner.prototype.uncaught = function(err){ |
---|
4749 | debug('uncaught exception %s', err.message); |
---|
4750 | var runnable = this.currentRunnable; |
---|
4751 | if (!runnable || 'failed' == runnable.state) return; |
---|
4752 | runnable.clearTimeout(); |
---|
4753 | err.uncaught = true; |
---|
4754 | this.fail(runnable, err); |
---|
4755 | |
---|
4756 | // recover from test |
---|
4757 | if ('test' == runnable.type) { |
---|
4758 | this.emit('test end', runnable); |
---|
4759 | this.hookUp('afterEach', this.next); |
---|
4760 | return; |
---|
4761 | } |
---|
4762 | |
---|
4763 | // bail on hooks |
---|
4764 | this.emit('end'); |
---|
4765 | }; |
---|
4766 | |
---|
4767 | /** |
---|
4768 | * Run the root suite and invoke `fn(failures)` |
---|
4769 | * on completion. |
---|
4770 | * |
---|
4771 | * @param {Function} fn |
---|
4772 | * @return {Runner} for chaining |
---|
4773 | * @api public |
---|
4774 | */ |
---|
4775 | |
---|
4776 | Runner.prototype.run = function(fn){ |
---|
4777 | var self = this |
---|
4778 | , fn = fn || function(){}; |
---|
4779 | |
---|
4780 | function uncaught(err){ |
---|
4781 | self.uncaught(err); |
---|
4782 | } |
---|
4783 | |
---|
4784 | debug('start'); |
---|
4785 | |
---|
4786 | // callback |
---|
4787 | this.on('end', function(){ |
---|
4788 | debug('end'); |
---|
4789 | process.removeListener('uncaughtException', uncaught); |
---|
4790 | fn(self.failures); |
---|
4791 | }); |
---|
4792 | |
---|
4793 | // run suites |
---|
4794 | this.emit('start'); |
---|
4795 | this.runSuite(this.suite, function(){ |
---|
4796 | debug('finished running'); |
---|
4797 | self.emit('end'); |
---|
4798 | }); |
---|
4799 | |
---|
4800 | // uncaught exception |
---|
4801 | process.on('uncaughtException', uncaught); |
---|
4802 | |
---|
4803 | return this; |
---|
4804 | }; |
---|
4805 | |
---|
4806 | /** |
---|
4807 | * Filter leaks with the given globals flagged as `ok`. |
---|
4808 | * |
---|
4809 | * @param {Array} ok |
---|
4810 | * @param {Array} globals |
---|
4811 | * @return {Array} |
---|
4812 | * @api private |
---|
4813 | */ |
---|
4814 | |
---|
4815 | function filterLeaks(ok, globals) { |
---|
4816 | return filter(globals, function(key){ |
---|
4817 | // Firefox and Chrome exposes iframes as index inside the window object |
---|
4818 | if (/^d+/.test(key)) return false; |
---|
4819 | |
---|
4820 | // in firefox |
---|
4821 | // if runner runs in an iframe, this iframe's window.getInterface method not init at first |
---|
4822 | // it is assigned in some seconds |
---|
4823 | if (global.navigator && /^getInterface/.test(key)) return false; |
---|
4824 | |
---|
4825 | // an iframe could be approached by window[iframeIndex] |
---|
4826 | // in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak |
---|
4827 | if (global.navigator && /^\d+/.test(key)) return false; |
---|
4828 | |
---|
4829 | // Opera and IE expose global variables for HTML element IDs (issue #243) |
---|
4830 | if (/^mocha-/.test(key)) return false; |
---|
4831 | |
---|
4832 | var matched = filter(ok, function(ok){ |
---|
4833 | if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]); |
---|
4834 | return key == ok; |
---|
4835 | }); |
---|
4836 | return matched.length == 0 && (!global.navigator || 'onerror' !== key); |
---|
4837 | }); |
---|
4838 | } |
---|
4839 | |
---|
4840 | }); // module: runner.js |
---|
4841 | |
---|
4842 | require.register("suite.js", function(module, exports, require){ |
---|
4843 | |
---|
4844 | /** |
---|
4845 | * Module dependencies. |
---|
4846 | */ |
---|
4847 | |
---|
4848 | var EventEmitter = require('browser/events').EventEmitter |
---|
4849 | , debug = require('browser/debug')('mocha:suite') |
---|
4850 | , milliseconds = require('./ms') |
---|
4851 | , utils = require('./utils') |
---|
4852 | , Hook = require('./hook'); |
---|
4853 | |
---|
4854 | /** |
---|
4855 | * Expose `Suite`. |
---|
4856 | */ |
---|
4857 | |
---|
4858 | exports = module.exports = Suite; |
---|
4859 | |
---|
4860 | /** |
---|
4861 | * Create a new `Suite` with the given `title` |
---|
4862 | * and parent `Suite`. When a suite with the |
---|
4863 | * same title is already present, that suite |
---|
4864 | * is returned to provide nicer reporter |
---|
4865 | * and more flexible meta-testing. |
---|
4866 | * |
---|
4867 | * @param {Suite} parent |
---|
4868 | * @param {String} title |
---|
4869 | * @return {Suite} |
---|
4870 | * @api public |
---|
4871 | */ |
---|
4872 | |
---|
4873 | exports.create = function(parent, title){ |
---|
4874 | var suite = new Suite(title, parent.ctx); |
---|
4875 | suite.parent = parent; |
---|
4876 | if (parent.pending) suite.pending = true; |
---|
4877 | title = suite.fullTitle(); |
---|
4878 | parent.addSuite(suite); |
---|
4879 | return suite; |
---|
4880 | }; |
---|
4881 | |
---|
4882 | /** |
---|
4883 | * Initialize a new `Suite` with the given |
---|
4884 | * `title` and `ctx`. |
---|
4885 | * |
---|
4886 | * @param {String} title |
---|
4887 | * @param {Context} ctx |
---|
4888 | * @api private |
---|
4889 | */ |
---|
4890 | |
---|
4891 | function Suite(title, ctx) { |
---|
4892 | this.title = title; |
---|
4893 | this.ctx = ctx; |
---|
4894 | this.suites = []; |
---|
4895 | this.tests = []; |
---|
4896 | this.pending = false; |
---|
4897 | this._beforeEach = []; |
---|
4898 | this._beforeAll = []; |
---|
4899 | this._afterEach = []; |
---|
4900 | this._afterAll = []; |
---|
4901 | this.root = !title; |
---|
4902 | this._timeout = 2000; |
---|
4903 | this._slow = 75; |
---|
4904 | this._bail = false; |
---|
4905 | } |
---|
4906 | |
---|
4907 | /** |
---|
4908 | * Inherit from `EventEmitter.prototype`. |
---|
4909 | */ |
---|
4910 | |
---|
4911 | function F(){}; |
---|
4912 | F.prototype = EventEmitter.prototype; |
---|
4913 | Suite.prototype = new F; |
---|
4914 | Suite.prototype.constructor = Suite; |
---|
4915 | |
---|
4916 | |
---|
4917 | /** |
---|
4918 | * Return a clone of this `Suite`. |
---|
4919 | * |
---|
4920 | * @return {Suite} |
---|
4921 | * @api private |
---|
4922 | */ |
---|
4923 | |
---|
4924 | Suite.prototype.clone = function(){ |
---|
4925 | var suite = new Suite(this.title); |
---|
4926 | debug('clone'); |
---|
4927 | suite.ctx = this.ctx; |
---|
4928 | suite.timeout(this.timeout()); |
---|
4929 | suite.slow(this.slow()); |
---|
4930 | suite.bail(this.bail()); |
---|
4931 | return suite; |
---|
4932 | }; |
---|
4933 | |
---|
4934 | /** |
---|
4935 | * Set timeout `ms` or short-hand such as "2s". |
---|
4936 | * |
---|
4937 | * @param {Number|String} ms |
---|
4938 | * @return {Suite|Number} for chaining |
---|
4939 | * @api private |
---|
4940 | */ |
---|
4941 | |
---|
4942 | Suite.prototype.timeout = function(ms){ |
---|
4943 | if (0 == arguments.length) return this._timeout; |
---|
4944 | if ('string' == typeof ms) ms = milliseconds(ms); |
---|
4945 | debug('timeout %d', ms); |
---|
4946 | this._timeout = parseInt(ms, 10); |
---|
4947 | return this; |
---|
4948 | }; |
---|
4949 | |
---|
4950 | /** |
---|
4951 | * Set slow `ms` or short-hand such as "2s". |
---|
4952 | * |
---|
4953 | * @param {Number|String} ms |
---|
4954 | * @return {Suite|Number} for chaining |
---|
4955 | * @api private |
---|
4956 | */ |
---|
4957 | |
---|
4958 | Suite.prototype.slow = function(ms){ |
---|
4959 | if (0 === arguments.length) return this._slow; |
---|
4960 | if ('string' == typeof ms) ms = milliseconds(ms); |
---|
4961 | debug('slow %d', ms); |
---|
4962 | this._slow = ms; |
---|
4963 | return this; |
---|
4964 | }; |
---|
4965 | |
---|
4966 | /** |
---|
4967 | * Sets whether to bail after first error. |
---|
4968 | * |
---|
4969 | * @parma {Boolean} bail |
---|
4970 | * @return {Suite|Number} for chaining |
---|
4971 | * @api private |
---|
4972 | */ |
---|
4973 | |
---|
4974 | Suite.prototype.bail = function(bail){ |
---|
4975 | if (0 == arguments.length) return this._bail; |
---|
4976 | debug('bail %s', bail); |
---|
4977 | this._bail = bail; |
---|
4978 | return this; |
---|
4979 | }; |
---|
4980 | |
---|
4981 | /** |
---|
4982 | * Run `fn(test[, done])` before running tests. |
---|
4983 | * |
---|
4984 | * @param {Function} fn |
---|
4985 | * @return {Suite} for chaining |
---|
4986 | * @api private |
---|
4987 | */ |
---|
4988 | |
---|
4989 | Suite.prototype.beforeAll = function(fn){ |
---|
4990 | if (this.pending) return this; |
---|
4991 | var hook = new Hook('"before all" hook', fn); |
---|
4992 | hook.parent = this; |
---|
4993 | hook.timeout(this.timeout()); |
---|
4994 | hook.slow(this.slow()); |
---|
4995 | hook.ctx = this.ctx; |
---|
4996 | this._beforeAll.push(hook); |
---|
4997 | this.emit('beforeAll', hook); |
---|
4998 | return this; |
---|
4999 | }; |
---|
5000 | |
---|
5001 | /** |
---|
5002 | * Run `fn(test[, done])` after running tests. |
---|
5003 | * |
---|
5004 | * @param {Function} fn |
---|
5005 | * @return {Suite} for chaining |
---|
5006 | * @api private |
---|
5007 | */ |
---|
5008 | |
---|
5009 | Suite.prototype.afterAll = function(fn){ |
---|
5010 | if (this.pending) return this; |
---|
5011 | var hook = new Hook('"after all" hook', fn); |
---|
5012 | hook.parent = this; |
---|
5013 | hook.timeout(this.timeout()); |
---|
5014 | hook.slow(this.slow()); |
---|
5015 | hook.ctx = this.ctx; |
---|
5016 | this._afterAll.push(hook); |
---|
5017 | this.emit('afterAll', hook); |
---|
5018 | return this; |
---|
5019 | }; |
---|
5020 | |
---|
5021 | /** |
---|
5022 | * Run `fn(test[, done])` before each test case. |
---|
5023 | * |
---|
5024 | * @param {Function} fn |
---|
5025 | * @return {Suite} for chaining |
---|
5026 | * @api private |
---|
5027 | */ |
---|
5028 | |
---|
5029 | Suite.prototype.beforeEach = function(fn){ |
---|
5030 | if (this.pending) return this; |
---|
5031 | var hook = new Hook('"before each" hook', fn); |
---|
5032 | hook.parent = this; |
---|
5033 | hook.timeout(this.timeout()); |
---|
5034 | hook.slow(this.slow()); |
---|
5035 | hook.ctx = this.ctx; |
---|
5036 | this._beforeEach.push(hook); |
---|
5037 | this.emit('beforeEach', hook); |
---|
5038 | return this; |
---|
5039 | }; |
---|
5040 | |
---|
5041 | /** |
---|
5042 | * Run `fn(test[, done])` after each test case. |
---|
5043 | * |
---|
5044 | * @param {Function} fn |
---|
5045 | * @return {Suite} for chaining |
---|
5046 | * @api private |
---|
5047 | */ |
---|
5048 | |
---|
5049 | Suite.prototype.afterEach = function(fn){ |
---|
5050 | if (this.pending) return this; |
---|
5051 | var hook = new Hook('"after each" hook', fn); |
---|
5052 | hook.parent = this; |
---|
5053 | hook.timeout(this.timeout()); |
---|
5054 | hook.slow(this.slow()); |
---|
5055 | hook.ctx = this.ctx; |
---|
5056 | this._afterEach.push(hook); |
---|
5057 | this.emit('afterEach', hook); |
---|
5058 | return this; |
---|
5059 | }; |
---|
5060 | |
---|
5061 | /** |
---|
5062 | * Add a test `suite`. |
---|
5063 | * |
---|
5064 | * @param {Suite} suite |
---|
5065 | * @return {Suite} for chaining |
---|
5066 | * @api private |
---|
5067 | */ |
---|
5068 | |
---|
5069 | Suite.prototype.addSuite = function(suite){ |
---|
5070 | suite.parent = this; |
---|
5071 | suite.timeout(this.timeout()); |
---|
5072 | suite.slow(this.slow()); |
---|
5073 | suite.bail(this.bail()); |
---|
5074 | this.suites.push(suite); |
---|
5075 | this.emit('suite', suite); |
---|
5076 | return this; |
---|
5077 | }; |
---|
5078 | |
---|
5079 | /** |
---|
5080 | * Add a `test` to this suite. |
---|
5081 | * |
---|
5082 | * @param {Test} test |
---|
5083 | * @return {Suite} for chaining |
---|
5084 | * @api private |
---|
5085 | */ |
---|
5086 | |
---|
5087 | Suite.prototype.addTest = function(test){ |
---|
5088 | test.parent = this; |
---|
5089 | test.timeout(this.timeout()); |
---|
5090 | test.slow(this.slow()); |
---|
5091 | test.ctx = this.ctx; |
---|
5092 | this.tests.push(test); |
---|
5093 | this.emit('test', test); |
---|
5094 | return this; |
---|
5095 | }; |
---|
5096 | |
---|
5097 | /** |
---|
5098 | * Return the full title generated by recursively |
---|
5099 | * concatenating the parent's full title. |
---|
5100 | * |
---|
5101 | * @return {String} |
---|
5102 | * @api public |
---|
5103 | */ |
---|
5104 | |
---|
5105 | Suite.prototype.fullTitle = function(){ |
---|
5106 | if (this.parent) { |
---|
5107 | var full = this.parent.fullTitle(); |
---|
5108 | if (full) return full + ' ' + this.title; |
---|
5109 | } |
---|
5110 | return this.title; |
---|
5111 | }; |
---|
5112 | |
---|
5113 | /** |
---|
5114 | * Return the total number of tests. |
---|
5115 | * |
---|
5116 | * @return {Number} |
---|
5117 | * @api public |
---|
5118 | */ |
---|
5119 | |
---|
5120 | Suite.prototype.total = function(){ |
---|
5121 | return utils.reduce(this.suites, function(sum, suite){ |
---|
5122 | return sum + suite.total(); |
---|
5123 | }, 0) + this.tests.length; |
---|
5124 | }; |
---|
5125 | |
---|
5126 | /** |
---|
5127 | * Iterates through each suite recursively to find |
---|
5128 | * all tests. Applies a function in the format |
---|
5129 | * `fn(test)`. |
---|
5130 | * |
---|
5131 | * @param {Function} fn |
---|
5132 | * @return {Suite} |
---|
5133 | * @api private |
---|
5134 | */ |
---|
5135 | |
---|
5136 | Suite.prototype.eachTest = function(fn){ |
---|
5137 | utils.forEach(this.tests, fn); |
---|
5138 | utils.forEach(this.suites, function(suite){ |
---|
5139 | suite.eachTest(fn); |
---|
5140 | }); |
---|
5141 | return this; |
---|
5142 | }; |
---|
5143 | |
---|
5144 | }); // module: suite.js |
---|
5145 | |
---|
5146 | require.register("test.js", function(module, exports, require){ |
---|
5147 | |
---|
5148 | /** |
---|
5149 | * Module dependencies. |
---|
5150 | */ |
---|
5151 | |
---|
5152 | var Runnable = require('./runnable'); |
---|
5153 | |
---|
5154 | /** |
---|
5155 | * Expose `Test`. |
---|
5156 | */ |
---|
5157 | |
---|
5158 | module.exports = Test; |
---|
5159 | |
---|
5160 | /** |
---|
5161 | * Initialize a new `Test` with the given `title` and callback `fn`. |
---|
5162 | * |
---|
5163 | * @param {String} title |
---|
5164 | * @param {Function} fn |
---|
5165 | * @api private |
---|
5166 | */ |
---|
5167 | |
---|
5168 | function Test(title, fn) { |
---|
5169 | Runnable.call(this, title, fn); |
---|
5170 | this.pending = !fn; |
---|
5171 | this.type = 'test'; |
---|
5172 | } |
---|
5173 | |
---|
5174 | /** |
---|
5175 | * Inherit from `Runnable.prototype`. |
---|
5176 | */ |
---|
5177 | |
---|
5178 | function F(){}; |
---|
5179 | F.prototype = Runnable.prototype; |
---|
5180 | Test.prototype = new F; |
---|
5181 | Test.prototype.constructor = Test; |
---|
5182 | |
---|
5183 | |
---|
5184 | }); // module: test.js |
---|
5185 | |
---|
5186 | require.register("utils.js", function(module, exports, require){ |
---|
5187 | /** |
---|
5188 | * Module dependencies. |
---|
5189 | */ |
---|
5190 | |
---|
5191 | var fs = require('browser/fs') |
---|
5192 | , path = require('browser/path') |
---|
5193 | , join = path.join |
---|
5194 | , debug = require('browser/debug')('mocha:watch'); |
---|
5195 | |
---|
5196 | /** |
---|
5197 | * Ignored directories. |
---|
5198 | */ |
---|
5199 | |
---|
5200 | var ignore = ['node_modules', '.git']; |
---|
5201 | |
---|
5202 | /** |
---|
5203 | * Escape special characters in the given string of html. |
---|
5204 | * |
---|
5205 | * @param {String} html |
---|
5206 | * @return {String} |
---|
5207 | * @api private |
---|
5208 | */ |
---|
5209 | |
---|
5210 | exports.escape = function(html){ |
---|
5211 | return String(html) |
---|
5212 | .replace(/&/g, '&') |
---|
5213 | .replace(/"/g, '"') |
---|
5214 | .replace(/</g, '<') |
---|
5215 | .replace(/>/g, '>'); |
---|
5216 | }; |
---|
5217 | |
---|
5218 | /** |
---|
5219 | * Array#forEach (<=IE8) |
---|
5220 | * |
---|
5221 | * @param {Array} array |
---|
5222 | * @param {Function} fn |
---|
5223 | * @param {Object} scope |
---|
5224 | * @api private |
---|
5225 | */ |
---|
5226 | |
---|
5227 | exports.forEach = function(arr, fn, scope){ |
---|
5228 | for (var i = 0, l = arr.length; i < l; i++) |
---|
5229 | fn.call(scope, arr[i], i); |
---|
5230 | }; |
---|
5231 | |
---|
5232 | /** |
---|
5233 | * Array#indexOf (<=IE8) |
---|
5234 | * |
---|
5235 | * @parma {Array} arr |
---|
5236 | * @param {Object} obj to find index of |
---|
5237 | * @param {Number} start |
---|
5238 | * @api private |
---|
5239 | */ |
---|
5240 | |
---|
5241 | exports.indexOf = function(arr, obj, start){ |
---|
5242 | for (var i = start || 0, l = arr.length; i < l; i++) { |
---|
5243 | if (arr[i] === obj) |
---|
5244 | return i; |
---|
5245 | } |
---|
5246 | return -1; |
---|
5247 | }; |
---|
5248 | |
---|
5249 | /** |
---|
5250 | * Array#reduce (<=IE8) |
---|
5251 | * |
---|
5252 | * @param {Array} array |
---|
5253 | * @param {Function} fn |
---|
5254 | * @param {Object} initial value |
---|
5255 | * @api private |
---|
5256 | */ |
---|
5257 | |
---|
5258 | exports.reduce = function(arr, fn, val){ |
---|
5259 | var rval = val; |
---|
5260 | |
---|
5261 | for (var i = 0, l = arr.length; i < l; i++) { |
---|
5262 | rval = fn(rval, arr[i], i, arr); |
---|
5263 | } |
---|
5264 | |
---|
5265 | return rval; |
---|
5266 | }; |
---|
5267 | |
---|
5268 | /** |
---|
5269 | * Array#filter (<=IE8) |
---|
5270 | * |
---|
5271 | * @param {Array} array |
---|
5272 | * @param {Function} fn |
---|
5273 | * @api private |
---|
5274 | */ |
---|
5275 | |
---|
5276 | exports.filter = function(arr, fn){ |
---|
5277 | var ret = []; |
---|
5278 | |
---|
5279 | for (var i = 0, l = arr.length; i < l; i++) { |
---|
5280 | var val = arr[i]; |
---|
5281 | if (fn(val, i, arr)) ret.push(val); |
---|
5282 | } |
---|
5283 | |
---|
5284 | return ret; |
---|
5285 | }; |
---|
5286 | |
---|
5287 | /** |
---|
5288 | * Object.keys (<=IE8) |
---|
5289 | * |
---|
5290 | * @param {Object} obj |
---|
5291 | * @return {Array} keys |
---|
5292 | * @api private |
---|
5293 | */ |
---|
5294 | |
---|
5295 | exports.keys = Object.keys || function(obj) { |
---|
5296 | var keys = [] |
---|
5297 | , has = Object.prototype.hasOwnProperty // for `window` on <=IE8 |
---|
5298 | |
---|
5299 | for (var key in obj) { |
---|
5300 | if (has.call(obj, key)) { |
---|
5301 | keys.push(key); |
---|
5302 | } |
---|
5303 | } |
---|
5304 | |
---|
5305 | return keys; |
---|
5306 | }; |
---|
5307 | |
---|
5308 | /** |
---|
5309 | * Watch the given `files` for changes |
---|
5310 | * and invoke `fn(file)` on modification. |
---|
5311 | * |
---|
5312 | * @param {Array} files |
---|
5313 | * @param {Function} fn |
---|
5314 | * @api private |
---|
5315 | */ |
---|
5316 | |
---|
5317 | exports.watch = function(files, fn){ |
---|
5318 | var options = { interval: 100 }; |
---|
5319 | files.forEach(function(file){ |
---|
5320 | debug('file %s', file); |
---|
5321 | fs.watchFile(file, options, function(curr, prev){ |
---|
5322 | if (prev.mtime < curr.mtime) fn(file); |
---|
5323 | }); |
---|
5324 | }); |
---|
5325 | }; |
---|
5326 | |
---|
5327 | /** |
---|
5328 | * Ignored files. |
---|
5329 | */ |
---|
5330 | |
---|
5331 | function ignored(path){ |
---|
5332 | return !~ignore.indexOf(path); |
---|
5333 | } |
---|
5334 | |
---|
5335 | /** |
---|
5336 | * Lookup files in the given `dir`. |
---|
5337 | * |
---|
5338 | * @return {Array} |
---|
5339 | * @api private |
---|
5340 | */ |
---|
5341 | |
---|
5342 | exports.files = function(dir, ret){ |
---|
5343 | ret = ret || []; |
---|
5344 | |
---|
5345 | fs.readdirSync(dir) |
---|
5346 | .filter(ignored) |
---|
5347 | .forEach(function(path){ |
---|
5348 | path = join(dir, path); |
---|
5349 | if (fs.statSync(path).isDirectory()) { |
---|
5350 | exports.files(path, ret); |
---|
5351 | } else if (path.match(/\.(js|coffee|litcoffee|coffee.md)$/)) { |
---|
5352 | ret.push(path); |
---|
5353 | } |
---|
5354 | }); |
---|
5355 | |
---|
5356 | return ret; |
---|
5357 | }; |
---|
5358 | |
---|
5359 | /** |
---|
5360 | * Compute a slug from the given `str`. |
---|
5361 | * |
---|
5362 | * @param {String} str |
---|
5363 | * @return {String} |
---|
5364 | * @api private |
---|
5365 | */ |
---|
5366 | |
---|
5367 | exports.slug = function(str){ |
---|
5368 | return str |
---|
5369 | .toLowerCase() |
---|
5370 | .replace(/ +/g, '-') |
---|
5371 | .replace(/[^-\w]/g, ''); |
---|
5372 | }; |
---|
5373 | |
---|
5374 | /** |
---|
5375 | * Strip the function definition from `str`, |
---|
5376 | * and re-indent for pre whitespace. |
---|
5377 | */ |
---|
5378 | |
---|
5379 | exports.clean = function(str) { |
---|
5380 | str = str |
---|
5381 | .replace(/^function *\(.*\) *{/, '') |
---|
5382 | .replace(/\s+\}$/, ''); |
---|
5383 | |
---|
5384 | var whitespace = str.match(/^\n?(\s*)/)[1] |
---|
5385 | , re = new RegExp('^' + whitespace, 'gm'); |
---|
5386 | |
---|
5387 | str = str.replace(re, ''); |
---|
5388 | |
---|
5389 | return exports.trim(str); |
---|
5390 | }; |
---|
5391 | |
---|
5392 | /** |
---|
5393 | * Escape regular expression characters in `str`. |
---|
5394 | * |
---|
5395 | * @param {String} str |
---|
5396 | * @return {String} |
---|
5397 | * @api private |
---|
5398 | */ |
---|
5399 | |
---|
5400 | exports.escapeRegexp = function(str){ |
---|
5401 | return str.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"); |
---|
5402 | }; |
---|
5403 | |
---|
5404 | /** |
---|
5405 | * Trim the given `str`. |
---|
5406 | * |
---|
5407 | * @param {String} str |
---|
5408 | * @return {String} |
---|
5409 | * @api private |
---|
5410 | */ |
---|
5411 | |
---|
5412 | exports.trim = function(str){ |
---|
5413 | return str.replace(/^\s+|\s+$/g, ''); |
---|
5414 | }; |
---|
5415 | |
---|
5416 | /** |
---|
5417 | * Parse the given `qs`. |
---|
5418 | * |
---|
5419 | * @param {String} qs |
---|
5420 | * @return {Object} |
---|
5421 | * @api private |
---|
5422 | */ |
---|
5423 | |
---|
5424 | exports.parseQuery = function(qs){ |
---|
5425 | return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){ |
---|
5426 | var i = pair.indexOf('=') |
---|
5427 | , key = pair.slice(0, i) |
---|
5428 | , val = pair.slice(++i); |
---|
5429 | |
---|
5430 | obj[key] = decodeURIComponent(val); |
---|
5431 | return obj; |
---|
5432 | }, {}); |
---|
5433 | }; |
---|
5434 | |
---|
5435 | /** |
---|
5436 | * Highlight the given string of `js`. |
---|
5437 | * |
---|
5438 | * @param {String} js |
---|
5439 | * @return {String} |
---|
5440 | * @api private |
---|
5441 | */ |
---|
5442 | |
---|
5443 | function highlight(js) { |
---|
5444 | return js |
---|
5445 | .replace(/</g, '<') |
---|
5446 | .replace(/>/g, '>') |
---|
5447 | .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>') |
---|
5448 | .replace(/('.*?')/gm, '<span class="string">$1</span>') |
---|
5449 | .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>') |
---|
5450 | .replace(/(\d+)/gm, '<span class="number">$1</span>') |
---|
5451 | .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>') |
---|
5452 | .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>') |
---|
5453 | } |
---|
5454 | |
---|
5455 | /** |
---|
5456 | * Highlight the contents of tag `name`. |
---|
5457 | * |
---|
5458 | * @param {String} name |
---|
5459 | * @api private |
---|
5460 | */ |
---|
5461 | |
---|
5462 | exports.highlightTags = function(name) { |
---|
5463 | var code = document.getElementsByTagName(name); |
---|
5464 | for (var i = 0, len = code.length; i < len; ++i) { |
---|
5465 | code[i].innerHTML = highlight(code[i].innerHTML); |
---|
5466 | } |
---|
5467 | }; |
---|
5468 | |
---|
5469 | }); // module: utils.js |
---|
5470 | // The global object is "self" in Web Workers. |
---|
5471 | global = (function() { return this; })(); |
---|
5472 | |
---|
5473 | /** |
---|
5474 | * Save timer references to avoid Sinon interfering (see GH-237). |
---|
5475 | */ |
---|
5476 | |
---|
5477 | var Date = global.Date; |
---|
5478 | var setTimeout = global.setTimeout; |
---|
5479 | var setInterval = global.setInterval; |
---|
5480 | var clearTimeout = global.clearTimeout; |
---|
5481 | var clearInterval = global.clearInterval; |
---|
5482 | |
---|
5483 | /** |
---|
5484 | * Node shims. |
---|
5485 | * |
---|
5486 | * These are meant only to allow |
---|
5487 | * mocha.js to run untouched, not |
---|
5488 | * to allow running node code in |
---|
5489 | * the browser. |
---|
5490 | */ |
---|
5491 | |
---|
5492 | var process = {}; |
---|
5493 | process.exit = function(status){}; |
---|
5494 | process.stdout = {}; |
---|
5495 | |
---|
5496 | /** |
---|
5497 | * Remove uncaughtException listener. |
---|
5498 | */ |
---|
5499 | |
---|
5500 | process.removeListener = function(e){ |
---|
5501 | if ('uncaughtException' == e) { |
---|
5502 | global.onerror = function() {}; |
---|
5503 | } |
---|
5504 | }; |
---|
5505 | |
---|
5506 | /** |
---|
5507 | * Implements uncaughtException listener. |
---|
5508 | */ |
---|
5509 | |
---|
5510 | process.on = function(e, fn){ |
---|
5511 | if ('uncaughtException' == e) { |
---|
5512 | global.onerror = function(err, url, line){ |
---|
5513 | fn(new Error(err + ' (' + url + ':' + line + ')')); |
---|
5514 | }; |
---|
5515 | } |
---|
5516 | }; |
---|
5517 | |
---|
5518 | /** |
---|
5519 | * Expose mocha. |
---|
5520 | */ |
---|
5521 | |
---|
5522 | var Mocha = global.Mocha = require('mocha'), |
---|
5523 | mocha = global.mocha = new Mocha({ reporter: 'html' }); |
---|
5524 | |
---|
5525 | var immediateQueue = [] |
---|
5526 | , immediateTimeout; |
---|
5527 | |
---|
5528 | function timeslice() { |
---|
5529 | var immediateStart = new Date().getTime(); |
---|
5530 | while (immediateQueue.length && (new Date().getTime() - immediateStart) < 100) { |
---|
5531 | immediateQueue.shift()(); |
---|
5532 | } |
---|
5533 | if (immediateQueue.length) { |
---|
5534 | immediateTimeout = setTimeout(timeslice, 0); |
---|
5535 | } else { |
---|
5536 | immediateTimeout = null; |
---|
5537 | } |
---|
5538 | } |
---|
5539 | |
---|
5540 | /** |
---|
5541 | * High-performance override of Runner.immediately. |
---|
5542 | */ |
---|
5543 | |
---|
5544 | Mocha.Runner.immediately = function(callback) { |
---|
5545 | immediateQueue.push(callback); |
---|
5546 | if (!immediateTimeout) { |
---|
5547 | immediateTimeout = setTimeout(timeslice, 0); |
---|
5548 | } |
---|
5549 | }; |
---|
5550 | |
---|
5551 | /** |
---|
5552 | * Override ui to ensure that the ui functions are initialized. |
---|
5553 | * Normally this would happen in Mocha.prototype.loadFiles. |
---|
5554 | */ |
---|
5555 | |
---|
5556 | mocha.ui = function(ui){ |
---|
5557 | Mocha.prototype.ui.call(this, ui); |
---|
5558 | this.suite.emit('pre-require', global, null, this); |
---|
5559 | return this; |
---|
5560 | }; |
---|
5561 | |
---|
5562 | /** |
---|
5563 | * Setup mocha with the given setting options. |
---|
5564 | */ |
---|
5565 | |
---|
5566 | mocha.setup = function(opts){ |
---|
5567 | if ('string' == typeof opts) opts = { ui: opts }; |
---|
5568 | for (var opt in opts) this[opt](opts[opt]); |
---|
5569 | return this; |
---|
5570 | }; |
---|
5571 | |
---|
5572 | /** |
---|
5573 | * Run mocha, returning the Runner. |
---|
5574 | */ |
---|
5575 | |
---|
5576 | mocha.run = function(fn){ |
---|
5577 | var options = mocha.options; |
---|
5578 | mocha.globals('location'); |
---|
5579 | |
---|
5580 | var query = Mocha.utils.parseQuery(global.location.search || ''); |
---|
5581 | if (query.grep) mocha.grep(query.grep); |
---|
5582 | if (query.invert) mocha.invert(); |
---|
5583 | |
---|
5584 | return Mocha.prototype.run.call(mocha, function(){ |
---|
5585 | // The DOM Document is not available in Web Workers. |
---|
5586 | if (global.document) { |
---|
5587 | Mocha.utils.highlightTags('code'); |
---|
5588 | } |
---|
5589 | if (fn) fn(); |
---|
5590 | }); |
---|
5591 | }; |
---|
5592 | |
---|
5593 | /** |
---|
5594 | * Expose the process shim. |
---|
5595 | */ |
---|
5596 | |
---|
5597 | Mocha.process = process; |
---|
5598 | })(); |
---|