1 | ;(function(){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | function require(p){
|
7 | var path = require.resolve(p)
|
8 | , mod = require.modules[path];
|
9 | if (!mod) throw new Error('failed to require "' + p + '"');
|
10 | if (!mod.exports) {
|
11 | mod.exports = {};
|
12 | mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
13 | }
|
14 | return mod.exports;
|
15 | }
|
16 |
|
17 | require.modules = {};
|
18 |
|
19 | require.resolve = function (path){
|
20 | var orig = path
|
21 | , reg = path + '.js'
|
22 | , index = path + '/index.js';
|
23 | return require.modules[reg] && reg
|
24 | || require.modules[index] && index
|
25 | || orig;
|
26 | };
|
27 |
|
28 | require.register = function (path, fn){
|
29 | require.modules[path] = fn;
|
30 | };
|
31 |
|
32 | require.relative = function (parent) {
|
33 | return function(p){
|
34 | if ('.' != p.charAt(0)) return require(p);
|
35 |
|
36 | var path = parent.split('/')
|
37 | , segs = p.split('/');
|
38 | path.pop();
|
39 |
|
40 | for (var i = 0; i < segs.length; i++) {
|
41 | var seg = segs[i];
|
42 | if ('..' == seg) path.pop();
|
43 | else if ('.' != seg) path.push(seg);
|
44 | }
|
45 |
|
46 | return require(path.join('/'));
|
47 | };
|
48 | };
|
49 |
|
50 |
|
51 | require.register("browser/debug.js", function(module, exports, require){
|
52 |
|
53 | module.exports = function(type){
|
54 | return function(){
|
55 |
|
56 | }
|
57 | };
|
58 | });
|
59 |
|
60 | require.register("browser/diff.js", function(module, exports, require){
|
61 |
|
62 | });
|
63 |
|
64 | require.register("browser/events.js", function(module, exports, require){
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | exports.EventEmitter = EventEmitter;
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | function isArray(obj) {
|
77 | return '[object Array]' == {}.toString.call(obj);
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | function EventEmitter(){};
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | EventEmitter.prototype.on = function (name, fn) {
|
95 | if (!this.$events) {
|
96 | this.$events = {};
|
97 | }
|
98 |
|
99 | if (!this.$events[name]) {
|
100 | this.$events[name] = fn;
|
101 | } else if (isArray(this.$events[name])) {
|
102 | this.$events[name].push(fn);
|
103 | } else {
|
104 | this.$events[name] = [this.$events[name], fn];
|
105 | }
|
106 |
|
107 | return this;
|
108 | };
|
109 |
|
110 | EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | EventEmitter.prototype.once = function (name, fn) {
|
119 | var self = this;
|
120 |
|
121 | function on () {
|
122 | self.removeListener(name, on);
|
123 | fn.apply(this, arguments);
|
124 | };
|
125 |
|
126 | on.listener = fn;
|
127 | this.on(name, on);
|
128 |
|
129 | return this;
|
130 | };
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | EventEmitter.prototype.removeListener = function (name, fn) {
|
139 | if (this.$events && this.$events[name]) {
|
140 | var list = this.$events[name];
|
141 |
|
142 | if (isArray(list)) {
|
143 | var pos = -1;
|
144 |
|
145 | for (var i = 0, l = list.length; i < l; i++) {
|
146 | if (list[i] === fn || (list[i].listener && list[i].listener === fn)) {
|
147 | pos = i;
|
148 | break;
|
149 | }
|
150 | }
|
151 |
|
152 | if (pos < 0) {
|
153 | return this;
|
154 | }
|
155 |
|
156 | list.splice(pos, 1);
|
157 |
|
158 | if (!list.length) {
|
159 | delete this.$events[name];
|
160 | }
|
161 | } else if (list === fn || (list.listener && list.listener === fn)) {
|
162 | delete this.$events[name];
|
163 | }
|
164 | }
|
165 |
|
166 | return this;
|
167 | };
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | EventEmitter.prototype.removeAllListeners = function (name) {
|
176 | if (name === undefined) {
|
177 | this.$events = {};
|
178 | return this;
|
179 | }
|
180 |
|
181 | if (this.$events && this.$events[name]) {
|
182 | this.$events[name] = null;
|
183 | }
|
184 |
|
185 | return this;
|
186 | };
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | EventEmitter.prototype.listeners = function (name) {
|
195 | if (!this.$events) {
|
196 | this.$events = {};
|
197 | }
|
198 |
|
199 | if (!this.$events[name]) {
|
200 | this.$events[name] = [];
|
201 | }
|
202 |
|
203 | if (!isArray(this.$events[name])) {
|
204 | this.$events[name] = [this.$events[name]];
|
205 | }
|
206 |
|
207 | return this.$events[name];
|
208 | };
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | EventEmitter.prototype.emit = function (name) {
|
217 | if (!this.$events) {
|
218 | return false;
|
219 | }
|
220 |
|
221 | var handler = this.$events[name];
|
222 |
|
223 | if (!handler) {
|
224 | return false;
|
225 | }
|
226 |
|
227 | var args = [].slice.call(arguments, 1);
|
228 |
|
229 | if ('function' == typeof handler) {
|
230 | handler.apply(this, args);
|
231 | } else if (isArray(handler)) {
|
232 | var listeners = handler.slice();
|
233 |
|
234 | for (var i = 0, l = listeners.length; i < l; i++) {
|
235 | listeners[i].apply(this, args);
|
236 | }
|
237 | } else {
|
238 | return false;
|
239 | }
|
240 |
|
241 | return true;
|
242 | };
|
243 | });
|
244 |
|
245 | require.register("browser/fs.js", function(module, exports, require){
|
246 |
|
247 | });
|
248 |
|
249 | require.register("browser/path.js", function(module, exports, require){
|
250 |
|
251 | });
|
252 |
|
253 | require.register("browser/progress.js", function(module, exports, require){
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | module.exports = Progress;
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | function Progress() {
|
266 | this.percent = 0;
|
267 | this.size(0);
|
268 | this.fontSize(11);
|
269 | this.font('helvetica, arial, sans-serif');
|
270 | }
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | Progress.prototype.size = function(n){
|
281 | this._size = n;
|
282 | return this;
|
283 | };
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 | Progress.prototype.text = function(str){
|
294 | this._text = str;
|
295 | return this;
|
296 | };
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | Progress.prototype.fontSize = function(n){
|
307 | this._fontSize = n;
|
308 | return this;
|
309 | };
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | Progress.prototype.font = function(family){
|
319 | this._font = family;
|
320 | return this;
|
321 | };
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 | Progress.prototype.update = function(n){
|
331 | this.percent = n;
|
332 | return this;
|
333 | };
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | Progress.prototype.draw = function(ctx){
|
343 | var percent = Math.min(this.percent, 100)
|
344 | , size = this._size
|
345 | , half = size / 2
|
346 | , x = half
|
347 | , y = half
|
348 | , rad = half - 1
|
349 | , fontSize = this._fontSize;
|
350 |
|
351 | ctx.font = fontSize + 'px ' + this._font;
|
352 |
|
353 | var angle = Math.PI * 2 * (percent / 100);
|
354 | ctx.clearRect(0, 0, size, size);
|
355 |
|
356 |
|
357 | ctx.strokeStyle = '#9f9f9f';
|
358 | ctx.beginPath();
|
359 | ctx.arc(x, y, rad, 0, angle, false);
|
360 | ctx.stroke();
|
361 |
|
362 |
|
363 | ctx.strokeStyle = '#eee';
|
364 | ctx.beginPath();
|
365 | ctx.arc(x, y, rad - 1, 0, angle, true);
|
366 | ctx.stroke();
|
367 |
|
368 |
|
369 | var text = this._text || (percent | 0) + '%'
|
370 | , w = ctx.measureText(text).width;
|
371 |
|
372 | ctx.fillText(
|
373 | text
|
374 | , x - w / 2 + 1
|
375 | , y + fontSize / 2 - 1);
|
376 |
|
377 | return this;
|
378 | };
|
379 |
|
380 | });
|
381 |
|
382 | require.register("browser/tty.js", function(module, exports, require){
|
383 |
|
384 | exports.isatty = function(){
|
385 | return true;
|
386 | };
|
387 |
|
388 | exports.getWindowSize = function(){
|
389 | return [window.innerHeight, window.innerWidth];
|
390 | };
|
391 | });
|
392 |
|
393 | require.register("context.js", function(module, exports, require){
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | module.exports = Context;
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 | function Context(){}
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | Context.prototype.runnable = function(runnable){
|
418 | if (0 == arguments.length) return this._runnable;
|
419 | this.test = this._runnable = runnable;
|
420 | return this;
|
421 | };
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 | Context.prototype.timeout = function(ms){
|
432 | this.runnable().timeout(ms);
|
433 | return this;
|
434 | };
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | Context.prototype.inspect = function(){
|
444 | return JSON.stringify(this, function(key, val){
|
445 | if ('_runnable' == key) return;
|
446 | if ('test' == key) return;
|
447 | return val;
|
448 | }, 2);
|
449 | };
|
450 |
|
451 | });
|
452 |
|
453 | require.register("hook.js", function(module, exports, require){
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 | var Runnable = require('./runnable');
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | module.exports = Hook;
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 | function Hook(title, fn) {
|
476 | Runnable.call(this, title, fn);
|
477 | this.type = 'hook';
|
478 | }
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 | Hook.prototype = new Runnable;
|
485 | Hook.prototype.constructor = Hook;
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 | Hook.prototype.error = function(err){
|
497 | if (0 == arguments.length) {
|
498 | var err = this._error;
|
499 | this._error = null;
|
500 | return err;
|
501 | }
|
502 |
|
503 | this._error = err;
|
504 | };
|
505 |
|
506 |
|
507 | });
|
508 |
|
509 | require.register("interfaces/bdd.js", function(module, exports, require){
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 | var Suite = require('../suite')
|
516 | , Test = require('../test');
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 | module.exports = function(suite){
|
536 | var suites = [suite];
|
537 |
|
538 | suite.on('pre-require', function(context, file, mocha){
|
539 |
|
540 | |
541 |
|
542 |
|
543 |
|
544 | context.before = function(fn){
|
545 | suites[0].beforeAll(fn);
|
546 | };
|
547 |
|
548 | |
549 |
|
550 |
|
551 |
|
552 | context.after = function(fn){
|
553 | suites[0].afterAll(fn);
|
554 | };
|
555 |
|
556 | |
557 |
|
558 |
|
559 |
|
560 | context.beforeEach = function(fn){
|
561 | suites[0].beforeEach(fn);
|
562 | };
|
563 |
|
564 | |
565 |
|
566 |
|
567 |
|
568 | context.afterEach = function(fn){
|
569 | suites[0].afterEach(fn);
|
570 | };
|
571 |
|
572 | |
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 | context.describe = context.context = function(title, fn){
|
579 | var suite = Suite.create(suites[0], title);
|
580 | suites.unshift(suite);
|
581 | fn();
|
582 | suites.shift();
|
583 | return suite;
|
584 | };
|
585 |
|
586 | |
587 |
|
588 |
|
589 |
|
590 | context.xdescribe =
|
591 | context.xcontext =
|
592 | context.describe.skip = function(title, fn){
|
593 | var suite = Suite.create(suites[0], title);
|
594 | suite.pending = true;
|
595 | suites.unshift(suite);
|
596 | fn();
|
597 | suites.shift();
|
598 | };
|
599 |
|
600 | |
601 |
|
602 |
|
603 |
|
604 | context.describe.only = function(title, fn){
|
605 | var suite = context.describe(title, fn);
|
606 | mocha.grep(suite.fullTitle());
|
607 | };
|
608 |
|
609 | |
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | context.it = context.specify = function(title, fn){
|
616 | var suite = suites[0];
|
617 | if (suite.pending) var fn = null;
|
618 | var test = new Test(title, fn);
|
619 | suite.addTest(test);
|
620 | return test;
|
621 | };
|
622 |
|
623 | |
624 |
|
625 |
|
626 |
|
627 | context.it.only = function(title, fn){
|
628 | var test = context.it(title, fn);
|
629 | mocha.grep(test.fullTitle());
|
630 | };
|
631 |
|
632 | |
633 |
|
634 |
|
635 |
|
636 | context.xit =
|
637 | context.xspecify =
|
638 | context.it.skip = function(title){
|
639 | context.it(title);
|
640 | };
|
641 | });
|
642 | };
|
643 |
|
644 | });
|
645 |
|
646 | require.register("interfaces/exports.js", function(module, exports, require){
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | var Suite = require('../suite')
|
653 | , Test = require('../test');
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 | module.exports = function(suite){
|
673 | var suites = [suite];
|
674 |
|
675 | suite.on('require', visit);
|
676 |
|
677 | function visit(obj) {
|
678 | var suite;
|
679 | for (var key in obj) {
|
680 | if ('function' == typeof obj[key]) {
|
681 | var fn = obj[key];
|
682 | switch (key) {
|
683 | case 'before':
|
684 | suites[0].beforeAll(fn);
|
685 | break;
|
686 | case 'after':
|
687 | suites[0].afterAll(fn);
|
688 | break;
|
689 | case 'beforeEach':
|
690 | suites[0].beforeEach(fn);
|
691 | break;
|
692 | case 'afterEach':
|
693 | suites[0].afterEach(fn);
|
694 | break;
|
695 | default:
|
696 | suites[0].addTest(new Test(key, fn));
|
697 | }
|
698 | } else {
|
699 | var suite = Suite.create(suites[0], key);
|
700 | suites.unshift(suite);
|
701 | visit(obj[key]);
|
702 | suites.shift();
|
703 | }
|
704 | }
|
705 | }
|
706 | };
|
707 | });
|
708 |
|
709 | require.register("interfaces/index.js", function(module, exports, require){
|
710 |
|
711 | exports.bdd = require('./bdd');
|
712 | exports.tdd = require('./tdd');
|
713 | exports.qunit = require('./qunit');
|
714 | exports.exports = require('./exports');
|
715 |
|
716 | });
|
717 |
|
718 | require.register("interfaces/qunit.js", function(module, exports, require){
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 | var Suite = require('../suite')
|
725 | , Test = require('../test');
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 | module.exports = function(suite){
|
753 | var suites = [suite];
|
754 |
|
755 | suite.on('pre-require', function(context){
|
756 |
|
757 | |
758 |
|
759 |
|
760 |
|
761 | context.before = function(fn){
|
762 | suites[0].beforeAll(fn);
|
763 | };
|
764 |
|
765 | |
766 |
|
767 |
|
768 |
|
769 | context.after = function(fn){
|
770 | suites[0].afterAll(fn);
|
771 | };
|
772 |
|
773 | |
774 |
|
775 |
|
776 |
|
777 | context.beforeEach = function(fn){
|
778 | suites[0].beforeEach(fn);
|
779 | };
|
780 |
|
781 | |
782 |
|
783 |
|
784 |
|
785 | context.afterEach = function(fn){
|
786 | suites[0].afterEach(fn);
|
787 | };
|
788 |
|
789 | |
790 |
|
791 |
|
792 |
|
793 | context.suite = function(title){
|
794 | if (suites.length > 1) suites.shift();
|
795 | var suite = Suite.create(suites[0], title);
|
796 | suites.unshift(suite);
|
797 | };
|
798 |
|
799 | |
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 | context.test = function(title, fn){
|
806 | suites[0].addTest(new Test(title, fn));
|
807 | };
|
808 | });
|
809 | };
|
810 |
|
811 | });
|
812 |
|
813 | require.register("interfaces/tdd.js", function(module, exports, require){
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 | var Suite = require('../suite')
|
820 | , Test = require('../test');
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 | module.exports = function(suite){
|
848 | var suites = [suite];
|
849 |
|
850 | suite.on('pre-require', function(context, file, mocha){
|
851 |
|
852 | |
853 |
|
854 |
|
855 |
|
856 | context.setup = function(fn){
|
857 | suites[0].beforeEach(fn);
|
858 | };
|
859 |
|
860 | |
861 |
|
862 |
|
863 |
|
864 | context.teardown = function(fn){
|
865 | suites[0].afterEach(fn);
|
866 | };
|
867 |
|
868 | |
869 |
|
870 |
|
871 |
|
872 | context.suiteSetup = function(fn){
|
873 | suites[0].beforeAll(fn);
|
874 | };
|
875 |
|
876 | |
877 |
|
878 |
|
879 |
|
880 | context.suiteTeardown = function(fn){
|
881 | suites[0].afterAll(fn);
|
882 | };
|
883 |
|
884 | |
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 | context.suite = function(title, fn){
|
891 | var suite = Suite.create(suites[0], title);
|
892 | suites.unshift(suite);
|
893 | fn();
|
894 | suites.shift();
|
895 | return suite;
|
896 | };
|
897 |
|
898 | |
899 |
|
900 |
|
901 |
|
902 | context.suite.only = function(title, fn){
|
903 | var suite = context.suite(title, fn);
|
904 | mocha.grep(suite.fullTitle());
|
905 | };
|
906 |
|
907 | |
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 | context.test = function(title, fn){
|
914 | var test = new Test(title, fn);
|
915 | suites[0].addTest(test);
|
916 | return test;
|
917 | };
|
918 |
|
919 | |
920 |
|
921 |
|
922 |
|
923 | context.test.only = function(title, fn){
|
924 | var test = context.test(title, fn);
|
925 | mocha.grep(test.fullTitle());
|
926 | };
|
927 | });
|
928 | };
|
929 |
|
930 | });
|
931 |
|
932 | require.register("mocha.js", function(module, exports, require){
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 | var path = require('browser/path')
|
944 | , utils = require('./utils');
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 | exports = module.exports = Mocha;
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 | exports.utils = utils;
|
957 | exports.interfaces = require('./interfaces');
|
958 | exports.reporters = require('./reporters');
|
959 | exports.Runnable = require('./runnable');
|
960 | exports.Context = require('./context');
|
961 | exports.Runner = require('./runner');
|
962 | exports.Suite = require('./suite');
|
963 | exports.Hook = require('./hook');
|
964 | exports.Test = require('./test');
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 | function image(name) {
|
975 | return __dirname + '/../images/' + name + '.png';
|
976 | }
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 | function Mocha(options) {
|
995 | options = options || {};
|
996 | this.files = [];
|
997 | this.options = options;
|
998 | this.grep(options.grep);
|
999 | this.suite = new exports.Suite('', new exports.Context);
|
1000 | this.ui(options.ui);
|
1001 | this.reporter(options.reporter);
|
1002 | if (options.timeout) this.timeout(options.timeout);
|
1003 | }
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 | Mocha.prototype.addFile = function(file){
|
1013 | this.files.push(file);
|
1014 | return this;
|
1015 | };
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 | Mocha.prototype.reporter = function(reporter){
|
1025 | if ('function' == typeof reporter) {
|
1026 | this._reporter = reporter;
|
1027 | } else {
|
1028 | reporter = reporter || 'dot';
|
1029 | try {
|
1030 | this._reporter = require('./reporters/' + reporter);
|
1031 | } catch (err) {
|
1032 | this._reporter = require(reporter);
|
1033 | }
|
1034 | if (!this._reporter) throw new Error('invalid reporter "' + reporter + '"');
|
1035 | }
|
1036 | return this;
|
1037 | };
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | Mocha.prototype.ui = function(name){
|
1047 | name = name || 'bdd';
|
1048 | this._ui = exports.interfaces[name];
|
1049 | if (!this._ui) throw new Error('invalid interface "' + name + '"');
|
1050 | this._ui = this._ui(this.suite);
|
1051 | return this;
|
1052 | };
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 | Mocha.prototype.loadFiles = function(fn){
|
1061 | var self = this;
|
1062 | var suite = this.suite;
|
1063 | var pending = this.files.length;
|
1064 | this.files.forEach(function(file){
|
1065 | file = path.resolve(file);
|
1066 | suite.emit('pre-require', global, file, self);
|
1067 | suite.emit('require', require(file), file, self);
|
1068 | suite.emit('post-require', global, file, self);
|
1069 | --pending || (fn && fn());
|
1070 | });
|
1071 | };
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 | Mocha.prototype._growl = function(runner, reporter) {
|
1080 | var notify = require('growl');
|
1081 |
|
1082 | runner.on('end', function(){
|
1083 | var stats = reporter.stats;
|
1084 | if (stats.failures) {
|
1085 | var msg = stats.failures + ' of ' + runner.total + ' tests failed';
|
1086 | notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
|
1087 | } else {
|
1088 | notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
|
1089 | name: 'mocha'
|
1090 | , title: 'Passed'
|
1091 | , image: image('ok')
|
1092 | });
|
1093 | }
|
1094 | });
|
1095 | };
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 | Mocha.prototype.grep = function(re){
|
1106 | this.options.grep = 'string' == typeof re
|
1107 | ? new RegExp(utils.escapeRegexp(re))
|
1108 | : re;
|
1109 | return this;
|
1110 | };
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 | Mocha.prototype.invert = function(){
|
1120 | this.options.invert = true;
|
1121 | return this;
|
1122 | };
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 | Mocha.prototype.ignoreLeaks = function(){
|
1132 | this.options.ignoreLeaks = true;
|
1133 | return this;
|
1134 | };
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | Mocha.prototype.growl = function(){
|
1144 | this.options.growl = true;
|
1145 | return this;
|
1146 | };
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 | Mocha.prototype.globals = function(globals){
|
1157 | this.options.globals = (this.options.globals || []).concat(globals);
|
1158 | return this;
|
1159 | };
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 | Mocha.prototype.timeout = function(timeout){
|
1170 | this.suite.timeout(timeout);
|
1171 | return this;
|
1172 | };
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 | Mocha.prototype.run = function(fn){
|
1183 | this.loadFiles();
|
1184 | var suite = this.suite;
|
1185 | var options = this.options;
|
1186 | var runner = new exports.Runner(suite);
|
1187 | var reporter = new this._reporter(runner);
|
1188 | runner.ignoreLeaks = options.ignoreLeaks;
|
1189 | if (options.grep) runner.grep(options.grep, options.invert);
|
1190 | if (options.globals) runner.globals(options.globals);
|
1191 | if (options.growl) this._growl(runner, reporter);
|
1192 | return runner.run(fn);
|
1193 | };
|
1194 |
|
1195 | });
|
1196 |
|
1197 | require.register("reporters/base.js", function(module, exports, require){
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 | var tty = require('browser/tty')
|
1204 | , diff = require('browser/diff');
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 | var Date = global.Date
|
1211 | , setTimeout = global.setTimeout
|
1212 | , setInterval = global.setInterval
|
1213 | , clearTimeout = global.clearTimeout
|
1214 | , clearInterval = global.clearInterval;
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | var isatty = tty.isatty(1) && tty.isatty(2);
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 | exports = module.exports = Base;
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 | exports.useColors = isatty;
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 | exports.colors = {
|
1239 | 'pass': 90
|
1240 | , 'fail': 31
|
1241 | , 'bright pass': 92
|
1242 | , 'bright fail': 91
|
1243 | , 'bright yellow': 93
|
1244 | , 'pending': 36
|
1245 | , 'suite': 0
|
1246 | , 'error title': 0
|
1247 | , 'error message': 31
|
1248 | , 'error stack': 90
|
1249 | , 'checkmark': 32
|
1250 | , 'fast': 90
|
1251 | , 'medium': 33
|
1252 | , 'slow': 31
|
1253 | , 'green': 32
|
1254 | , 'light': 90
|
1255 | , 'diff gutter': 90
|
1256 | , 'diff added': 42
|
1257 | , 'diff removed': 41
|
1258 | };
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 | var color = exports.color = function(type, str) {
|
1273 | if (!exports.useColors) return str;
|
1274 | return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
|
1275 | };
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 | exports.window = {
|
1283 | width: isatty
|
1284 | ? process.stdout.getWindowSize
|
1285 | ? process.stdout.getWindowSize(1)[0]
|
1286 | : tty.getWindowSize()[1]
|
1287 | : 75
|
1288 | };
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 | exports.cursor = {
|
1296 | hide: function(){
|
1297 | process.stdout.write('\u001b[?25l');
|
1298 | },
|
1299 |
|
1300 | show: function(){
|
1301 | process.stdout.write('\u001b[?25h');
|
1302 | },
|
1303 |
|
1304 | deleteLine: function(){
|
1305 | process.stdout.write('\u001b[2K');
|
1306 | },
|
1307 |
|
1308 | beginningOfLine: function(){
|
1309 | process.stdout.write('\u001b[0G');
|
1310 | },
|
1311 |
|
1312 | CR: function(){
|
1313 | exports.cursor.deleteLine();
|
1314 | exports.cursor.beginningOfLine();
|
1315 | }
|
1316 | };
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 | exports.slow = 75;
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 | exports.list = function(failures){
|
1333 | console.error();
|
1334 | failures.forEach(function(test, i){
|
1335 |
|
1336 | var fmt = color('error title', ' %s) %s:\n')
|
1337 | + color('error message', ' %s')
|
1338 | + color('error stack', '\n%s\n');
|
1339 |
|
1340 |
|
1341 | var err = test.err
|
1342 | , message = err.message || ''
|
1343 | , stack = err.stack || message
|
1344 | , index = stack.indexOf(message) + message.length
|
1345 | , msg = stack.slice(0, index)
|
1346 | , actual = err.actual
|
1347 | , expected = err.expected;
|
1348 |
|
1349 |
|
1350 | if ('string' == typeof actual && 'string' == typeof expected) {
|
1351 | var len = Math.max(actual.length, expected.length);
|
1352 |
|
1353 | if (len < 20) msg = errorDiff(err, 'Chars');
|
1354 | else msg = errorDiff(err, 'Words');
|
1355 |
|
1356 |
|
1357 | var lines = msg.split('\n');
|
1358 | if (lines.length > 4) {
|
1359 | var width = String(lines.length).length;
|
1360 | msg = lines.map(function(str, i){
|
1361 | return pad(++i, width) + ' |' + ' ' + str;
|
1362 | }).join('\n');
|
1363 | }
|
1364 |
|
1365 |
|
1366 | msg = '\n'
|
1367 | + color('diff removed', 'actual')
|
1368 | + ' '
|
1369 | + color('diff added', 'expected')
|
1370 | + '\n\n'
|
1371 | + msg
|
1372 | + '\n';
|
1373 |
|
1374 |
|
1375 | msg = msg.replace(/^/gm, ' ');
|
1376 |
|
1377 | fmt = color('error title', ' %s) %s:\n%s')
|
1378 | + color('error stack', '\n%s\n');
|
1379 | }
|
1380 |
|
1381 |
|
1382 | stack = stack.slice(index ? index + 1 : index)
|
1383 | .replace(/^/gm, ' ');
|
1384 |
|
1385 | console.error(fmt, (i + 1), test.fullTitle(), msg, stack);
|
1386 | });
|
1387 | };
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 | function Base(runner) {
|
1402 | var self = this
|
1403 | , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
|
1404 | , failures = this.failures = [];
|
1405 |
|
1406 | if (!runner) return;
|
1407 | this.runner = runner;
|
1408 |
|
1409 | runner.on('start', function(){
|
1410 | stats.start = new Date;
|
1411 | });
|
1412 |
|
1413 | runner.on('suite', function(suite){
|
1414 | stats.suites = stats.suites || 0;
|
1415 | suite.root || stats.suites++;
|
1416 | });
|
1417 |
|
1418 | runner.on('test end', function(test){
|
1419 | stats.tests = stats.tests || 0;
|
1420 | stats.tests++;
|
1421 | });
|
1422 |
|
1423 | runner.on('pass', function(test){
|
1424 | stats.passes = stats.passes || 0;
|
1425 |
|
1426 | var medium = exports.slow / 2;
|
1427 | test.speed = test.duration > exports.slow
|
1428 | ? 'slow'
|
1429 | : test.duration > medium
|
1430 | ? 'medium'
|
1431 | : 'fast';
|
1432 |
|
1433 | stats.passes++;
|
1434 | });
|
1435 |
|
1436 | runner.on('fail', function(test, err){
|
1437 | stats.failures = stats.failures || 0;
|
1438 | stats.failures++;
|
1439 | test.err = err;
|
1440 | failures.push(test);
|
1441 | });
|
1442 |
|
1443 | runner.on('end', function(){
|
1444 | stats.end = new Date;
|
1445 | stats.duration = new Date - stats.start;
|
1446 | });
|
1447 |
|
1448 | runner.on('pending', function(){
|
1449 | stats.pending++;
|
1450 | });
|
1451 | }
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 | Base.prototype.epilogue = function(){
|
1461 | var stats = this.stats
|
1462 | , fmt
|
1463 | , tests;
|
1464 |
|
1465 | console.log();
|
1466 |
|
1467 | function pluralize(n) {
|
1468 | return 1 == n ? 'test' : 'tests';
|
1469 | }
|
1470 |
|
1471 |
|
1472 | if (stats.failures) {
|
1473 | fmt = color('bright fail', ' ✖')
|
1474 | + color('fail', ' %d of %d %s failed')
|
1475 | + color('light', ':')
|
1476 |
|
1477 | console.error(fmt,
|
1478 | stats.failures,
|
1479 | this.runner.total,
|
1480 | pluralize(this.runner.total));
|
1481 |
|
1482 | Base.list(this.failures);
|
1483 | console.error();
|
1484 | return;
|
1485 | }
|
1486 |
|
1487 |
|
1488 | fmt = color('bright pass', ' ✔')
|
1489 | + color('green', ' %d %s complete')
|
1490 | + color('light', ' (%dms)');
|
1491 |
|
1492 | console.log(fmt,
|
1493 | stats.tests || 0,
|
1494 | pluralize(stats.tests),
|
1495 | stats.duration);
|
1496 |
|
1497 |
|
1498 | if (stats.pending) {
|
1499 | fmt = color('pending', ' •')
|
1500 | + color('pending', ' %d %s pending');
|
1501 |
|
1502 | console.log(fmt, stats.pending, pluralize(stats.pending));
|
1503 | }
|
1504 |
|
1505 | console.log();
|
1506 | };
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 | function pad(str, len) {
|
1518 | str = String(str);
|
1519 | return Array(len - str.length + 1).join(' ') + str;
|
1520 | }
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 | function errorDiff(err, type) {
|
1531 | return diff['diff' + type](err.actual, err.expected).map(function(str){
|
1532 | if (/^(\n+)$/.test(str.value)) str.value = Array(++RegExp.$1.length).join('<newline>');
|
1533 | if (str.added) return colorLines('diff added', str.value);
|
1534 | if (str.removed) return colorLines('diff removed', str.value);
|
1535 | return str.value;
|
1536 | }).join('');
|
1537 | }
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 | function colorLines(name, str) {
|
1549 | return str.split('\n').map(function(str){
|
1550 | return color(name, str);
|
1551 | }).join('\n');
|
1552 | }
|
1553 |
|
1554 | });
|
1555 |
|
1556 | require.register("reporters/doc.js", function(module, exports, require){
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 | var Base = require('./base')
|
1563 | , utils = require('../utils');
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 | exports = module.exports = Doc;
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 | function Doc(runner) {
|
1579 | Base.call(this, runner);
|
1580 |
|
1581 | var self = this
|
1582 | , stats = this.stats
|
1583 | , total = runner.total
|
1584 | , indents = 2;
|
1585 |
|
1586 | function indent() {
|
1587 | return Array(indents).join(' ');
|
1588 | }
|
1589 |
|
1590 | runner.on('suite', function(suite){
|
1591 | if (suite.root) return;
|
1592 | ++indents;
|
1593 | console.log('%s<section class="suite">', indent());
|
1594 | ++indents;
|
1595 | console.log('%s<h1>%s</h1>', indent(), suite.title);
|
1596 | console.log('%s<dl>', indent());
|
1597 | });
|
1598 |
|
1599 | runner.on('suite end', function(suite){
|
1600 | if (suite.root) return;
|
1601 | console.log('%s</dl>', indent());
|
1602 | --indents;
|
1603 | console.log('%s</section>', indent());
|
1604 | --indents;
|
1605 | });
|
1606 |
|
1607 | runner.on('pass', function(test){
|
1608 | console.log('%s <dt>%s</dt>', indent(), test.title);
|
1609 | var code = utils.escape(utils.clean(test.fn.toString()));
|
1610 | console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
1611 | });
|
1612 | }
|
1613 |
|
1614 | });
|
1615 |
|
1616 | require.register("reporters/dot.js", function(module, exports, require){
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 | var Base = require('./base')
|
1623 | , color = Base.color;
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 | exports = module.exports = Dot;
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 | function Dot(runner) {
|
1639 | Base.call(this, runner);
|
1640 |
|
1641 | var self = this
|
1642 | , stats = this.stats
|
1643 | , width = Base.window.width * .75 | 0
|
1644 | , c = '․'
|
1645 | , n = 0;
|
1646 |
|
1647 | runner.on('start', function(){
|
1648 | process.stdout.write('\n ');
|
1649 | });
|
1650 |
|
1651 | runner.on('pending', function(test){
|
1652 | process.stdout.write(color('pending', c));
|
1653 | });
|
1654 |
|
1655 | runner.on('pass', function(test){
|
1656 | if (++n % width == 0) process.stdout.write('\n ');
|
1657 | if ('slow' == test.speed) {
|
1658 | process.stdout.write(color('bright yellow', c));
|
1659 | } else {
|
1660 | process.stdout.write(color(test.speed, c));
|
1661 | }
|
1662 | });
|
1663 |
|
1664 | runner.on('fail', function(test, err){
|
1665 | if (++n % width == 0) process.stdout.write('\n ');
|
1666 | process.stdout.write(color('fail', c));
|
1667 | });
|
1668 |
|
1669 | runner.on('end', function(){
|
1670 | console.log();
|
1671 | self.epilogue();
|
1672 | });
|
1673 | }
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 | Dot.prototype = new Base;
|
1680 | Dot.prototype.constructor = Dot;
|
1681 |
|
1682 | });
|
1683 |
|
1684 | require.register("reporters/html-cov.js", function(module, exports, require){
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 | var JSONCov = require('./json-cov')
|
1691 | , fs = require('browser/fs');
|
1692 |
|
1693 |
|
1694 |
|
1695 |
|
1696 |
|
1697 | exports = module.exports = HTMLCov;
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 | function HTMLCov(runner) {
|
1707 | var jade = require('jade')
|
1708 | , file = __dirname + '/templates/coverage.jade'
|
1709 | , str = fs.readFileSync(file, 'utf8')
|
1710 | , fn = jade.compile(str, { filename: file })
|
1711 | , self = this;
|
1712 |
|
1713 | JSONCov.call(this, runner, false);
|
1714 |
|
1715 | runner.on('end', function(){
|
1716 | process.stdout.write(fn({
|
1717 | cov: self.cov
|
1718 | , coverageClass: coverageClass
|
1719 | }));
|
1720 | });
|
1721 | }
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 | function coverageClass(n) {
|
1731 | if (n >= 75) return 'high';
|
1732 | if (n >= 50) return 'medium';
|
1733 | if (n >= 25) return 'low';
|
1734 | return 'terrible';
|
1735 | }
|
1736 | });
|
1737 |
|
1738 | require.register("reporters/html.js", function(module, exports, require){
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 | var Base = require('./base')
|
1745 | , utils = require('../utils')
|
1746 | , Progress = require('../browser/progress')
|
1747 | , escape = utils.escape;
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 | var Date = global.Date
|
1754 | , setTimeout = global.setTimeout
|
1755 | , setInterval = global.setInterval
|
1756 | , clearTimeout = global.clearTimeout
|
1757 | , clearInterval = global.clearInterval;
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 | exports = module.exports = HTML;
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 | var statsTemplate = '<ul id="stats">'
|
1770 | + '<li class="progress"><canvas width="40" height="40"></canvas></li>'
|
1771 | + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>'
|
1772 | + '<li class="failures"><a href="#">failures:</a> <em>0</em></li>'
|
1773 | + '<li class="duration">duration: <em>0</em>s</li>'
|
1774 | + '</ul>';
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 | function HTML(runner, root) {
|
1784 | Base.call(this, runner);
|
1785 |
|
1786 | var self = this
|
1787 | , stats = this.stats
|
1788 | , total = runner.total
|
1789 | , stat = fragment(statsTemplate)
|
1790 | , items = stat.getElementsByTagName('li')
|
1791 | , passes = items[1].getElementsByTagName('em')[0]
|
1792 | , passesLink = items[1].getElementsByTagName('a')[0]
|
1793 | , failures = items[2].getElementsByTagName('em')[0]
|
1794 | , failuresLink = items[2].getElementsByTagName('a')[0]
|
1795 | , duration = items[3].getElementsByTagName('em')[0]
|
1796 | , canvas = stat.getElementsByTagName('canvas')[0]
|
1797 | , report = fragment('<ul id="report"></ul>')
|
1798 | , stack = [report]
|
1799 | , progress
|
1800 | , ctx
|
1801 |
|
1802 | root = root || document.getElementById('mocha');
|
1803 |
|
1804 | if (canvas.getContext) {
|
1805 | var ratio = window.devicePixelRatio || 1;
|
1806 | canvas.style.width = canvas.width;
|
1807 | canvas.style.height = canvas.height;
|
1808 | canvas.width *= ratio;
|
1809 | canvas.height *= ratio;
|
1810 | ctx = canvas.getContext('2d');
|
1811 | ctx.scale(ratio, ratio);
|
1812 | progress = new Progress;
|
1813 | }
|
1814 |
|
1815 | if (!root) return error('#mocha div missing, add it to your document');
|
1816 |
|
1817 |
|
1818 | on(passesLink, 'click', function () {
|
1819 | var className = /pass/.test(report.className) ? '' : ' pass';
|
1820 | report.className = report.className.replace(/fail|pass/g, '') + className;
|
1821 | });
|
1822 |
|
1823 |
|
1824 | on(failuresLink, 'click', function () {
|
1825 | var className = /fail/.test(report.className) ? '' : ' fail';
|
1826 | report.className = report.className.replace(/fail|pass/g, '') + className;
|
1827 | });
|
1828 |
|
1829 | root.appendChild(stat);
|
1830 | root.appendChild(report);
|
1831 |
|
1832 | if (progress) progress.size(40);
|
1833 |
|
1834 | runner.on('suite', function(suite){
|
1835 | if (suite.root) return;
|
1836 |
|
1837 |
|
1838 | var url = '?grep=' + encodeURIComponent(suite.fullTitle());
|
1839 | var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
|
1840 |
|
1841 |
|
1842 | stack[0].appendChild(el);
|
1843 | stack.unshift(document.createElement('ul'));
|
1844 | el.appendChild(stack[0]);
|
1845 | });
|
1846 |
|
1847 | runner.on('suite end', function(suite){
|
1848 | if (suite.root) return;
|
1849 | stack.shift();
|
1850 | });
|
1851 |
|
1852 | runner.on('fail', function(test, err){
|
1853 | if ('hook' == test.type || err.uncaught) runner.emit('test end', test);
|
1854 | });
|
1855 |
|
1856 | runner.on('test end', function(test){
|
1857 | window.scrollTo(0, document.body.scrollHeight);
|
1858 |
|
1859 |
|
1860 | var percent = stats.tests / total * 100 | 0;
|
1861 | if (progress) progress.update(percent).draw(ctx);
|
1862 |
|
1863 |
|
1864 | var ms = new Date - stats.start;
|
1865 | text(passes, stats.passes);
|
1866 | text(failures, stats.failures);
|
1867 | text(duration, (ms / 1000).toFixed(2));
|
1868 |
|
1869 |
|
1870 | if ('passed' == test.state) {
|
1871 | var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span></h2></li>', test.speed, test.title, test.duration);
|
1872 | } else if (test.pending) {
|
1873 | var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
|
1874 | } else {
|
1875 | var el = fragment('<li class="test fail"><h2>%e</h2></li>', test.title);
|
1876 | var str = test.err.stack || test.err.toString();
|
1877 |
|
1878 |
|
1879 | if (!~str.indexOf(test.err.message)) {
|
1880 | str = test.err.message + '\n' + str;
|
1881 | }
|
1882 |
|
1883 |
|
1884 |
|
1885 | if ('[object Error]' == str) str = test.err.message;
|
1886 |
|
1887 |
|
1888 | if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
|
1889 | str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
|
1890 | }
|
1891 |
|
1892 | el.appendChild(fragment('<pre class="error">%e</pre>', str));
|
1893 | }
|
1894 |
|
1895 |
|
1896 |
|
1897 | if (!test.pending) {
|
1898 | var h2 = el.getElementsByTagName('h2')[0];
|
1899 |
|
1900 | on(h2, 'click', function(){
|
1901 | pre.style.display = 'none' == pre.style.display
|
1902 | ? 'inline-block'
|
1903 | : 'none';
|
1904 | });
|
1905 |
|
1906 | var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));
|
1907 | el.appendChild(pre);
|
1908 | pre.style.display = 'none';
|
1909 | }
|
1910 |
|
1911 | stack[0].appendChild(el);
|
1912 | });
|
1913 | }
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 | function error(msg) {
|
1920 | document.body.appendChild(fragment('<div id="error">%s</div>', msg));
|
1921 | }
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 | function fragment(html) {
|
1928 | var args = arguments
|
1929 | , div = document.createElement('div')
|
1930 | , i = 1;
|
1931 |
|
1932 | div.innerHTML = html.replace(/%([se])/g, function(_, type){
|
1933 | switch (type) {
|
1934 | case 's': return String(args[i++]);
|
1935 | case 'e': return escape(args[i++]);
|
1936 | }
|
1937 | });
|
1938 |
|
1939 | return div.firstChild;
|
1940 | }
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 | function text(el, str) {
|
1947 | if (el.textContent) {
|
1948 | el.textContent = str;
|
1949 | } else {
|
1950 | el.innerText = str;
|
1951 | }
|
1952 | }
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 | function on(el, event, fn) {
|
1959 | if (el.addEventListener) {
|
1960 | el.addEventListener(event, fn, false);
|
1961 | } else {
|
1962 | el.attachEvent('on' + event, fn);
|
1963 | }
|
1964 | }
|
1965 |
|
1966 | });
|
1967 |
|
1968 | require.register("reporters/index.js", function(module, exports, require){
|
1969 |
|
1970 | exports.Base = require('./base');
|
1971 | exports.Dot = require('./dot');
|
1972 | exports.Doc = require('./doc');
|
1973 | exports.TAP = require('./tap');
|
1974 | exports.JSON = require('./json');
|
1975 | exports.HTML = require('./html');
|
1976 | exports.List = require('./list');
|
1977 | exports.Min = require('./min');
|
1978 | exports.Spec = require('./spec');
|
1979 | exports.Nyan = require('./nyan');
|
1980 | exports.XUnit = require('./xunit');
|
1981 | exports.Markdown = require('./markdown');
|
1982 | exports.Progress = require('./progress');
|
1983 | exports.Landing = require('./landing');
|
1984 | exports.JSONCov = require('./json-cov');
|
1985 | exports.HTMLCov = require('./html-cov');
|
1986 | exports.JSONStream = require('./json-stream');
|
1987 | exports.Teamcity = require('./teamcity');
|
1988 |
|
1989 | });
|
1990 |
|
1991 | require.register("reporters/json-cov.js", function(module, exports, require){
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 | var Base = require('./base');
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 | exports = module.exports = JSONCov;
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | function JSONCov(runner, output) {
|
2014 | var self = this
|
2015 | , output = 1 == arguments.length ? true : output;
|
2016 |
|
2017 | Base.call(this, runner);
|
2018 |
|
2019 | var tests = []
|
2020 | , failures = []
|
2021 | , passes = [];
|
2022 |
|
2023 | runner.on('test end', function(test){
|
2024 | tests.push(test);
|
2025 | });
|
2026 |
|
2027 | runner.on('pass', function(test){
|
2028 | passes.push(test);
|
2029 | });
|
2030 |
|
2031 | runner.on('fail', function(test){
|
2032 | failures.push(test);
|
2033 | });
|
2034 |
|
2035 | runner.on('end', function(){
|
2036 | var cov = global._$jscoverage || {};
|
2037 | var result = self.cov = map(cov);
|
2038 | result.stats = self.stats;
|
2039 | result.tests = tests.map(clean);
|
2040 | result.failures = failures.map(clean);
|
2041 | result.passes = passes.map(clean);
|
2042 | if (!output) return;
|
2043 | process.stdout.write(JSON.stringify(result, null, 2 ));
|
2044 | });
|
2045 | }
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 | function map(cov) {
|
2057 | var ret = {
|
2058 | instrumentation: 'node-jscoverage'
|
2059 | , sloc: 0
|
2060 | , hits: 0
|
2061 | , misses: 0
|
2062 | , coverage: 0
|
2063 | , files: []
|
2064 | };
|
2065 |
|
2066 | for (var filename in cov) {
|
2067 | var data = coverage(filename, cov[filename]);
|
2068 | ret.files.push(data);
|
2069 | ret.hits += data.hits;
|
2070 | ret.misses += data.misses;
|
2071 | ret.sloc += data.sloc;
|
2072 | }
|
2073 |
|
2074 | if (ret.sloc > 0) {
|
2075 | ret.coverage = (ret.hits / ret.sloc) * 100;
|
2076 | }
|
2077 |
|
2078 | return ret;
|
2079 | };
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 | function coverage(filename, data) {
|
2092 | var ret = {
|
2093 | filename: filename,
|
2094 | coverage: 0,
|
2095 | hits: 0,
|
2096 | misses: 0,
|
2097 | sloc: 0,
|
2098 | source: {}
|
2099 | };
|
2100 |
|
2101 | data.source.forEach(function(line, num){
|
2102 | num++;
|
2103 |
|
2104 | if (data[num] === 0) {
|
2105 | ret.misses++;
|
2106 | ret.sloc++;
|
2107 | } else if (data[num] !== undefined) {
|
2108 | ret.hits++;
|
2109 | ret.sloc++;
|
2110 | }
|
2111 |
|
2112 | ret.source[num] = {
|
2113 | source: line
|
2114 | , coverage: data[num] === undefined
|
2115 | ? ''
|
2116 | : data[num]
|
2117 | };
|
2118 | });
|
2119 |
|
2120 | ret.coverage = ret.hits / ret.sloc * 100;
|
2121 |
|
2122 | return ret;
|
2123 | }
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 | function clean(test) {
|
2135 | return {
|
2136 | title: test.title
|
2137 | , fullTitle: test.fullTitle()
|
2138 | , duration: test.duration
|
2139 | }
|
2140 | }
|
2141 |
|
2142 | });
|
2143 |
|
2144 | require.register("reporters/json-stream.js", function(module, exports, require){
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 | var Base = require('./base')
|
2151 | , color = Base.color;
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 | exports = module.exports = List;
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 | function List(runner) {
|
2167 | Base.call(this, runner);
|
2168 |
|
2169 | var self = this
|
2170 | , stats = this.stats
|
2171 | , total = runner.total;
|
2172 |
|
2173 | runner.on('start', function(){
|
2174 | console.log(JSON.stringify(['start', { total: total }]));
|
2175 | });
|
2176 |
|
2177 | runner.on('pass', function(test){
|
2178 | console.log(JSON.stringify(['pass', clean(test)]));
|
2179 | });
|
2180 |
|
2181 | runner.on('fail', function(test, err){
|
2182 | console.log(JSON.stringify(['fail', clean(test)]));
|
2183 | });
|
2184 |
|
2185 | runner.on('end', function(){
|
2186 | process.stdout.write(JSON.stringify(['end', self.stats]));
|
2187 | });
|
2188 | }
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 | function clean(test) {
|
2200 | return {
|
2201 | title: test.title
|
2202 | , fullTitle: test.fullTitle()
|
2203 | , duration: test.duration
|
2204 | }
|
2205 | }
|
2206 | });
|
2207 |
|
2208 | require.register("reporters/json.js", function(module, exports, require){
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 | var Base = require('./base')
|
2215 | , cursor = Base.cursor
|
2216 | , color = Base.color;
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 | exports = module.exports = JSONReporter;
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 | function JSONReporter(runner) {
|
2232 | var self = this;
|
2233 | Base.call(this, runner);
|
2234 |
|
2235 | var tests = []
|
2236 | , failures = []
|
2237 | , passes = [];
|
2238 |
|
2239 | runner.on('test end', function(test){
|
2240 | tests.push(test);
|
2241 | });
|
2242 |
|
2243 | runner.on('pass', function(test){
|
2244 | passes.push(test);
|
2245 | });
|
2246 |
|
2247 | runner.on('fail', function(test){
|
2248 | failures.push(test);
|
2249 | });
|
2250 |
|
2251 | runner.on('end', function(){
|
2252 | var obj = {
|
2253 | stats: self.stats
|
2254 | , tests: tests.map(clean)
|
2255 | , failures: failures.map(clean)
|
2256 | , passes: passes.map(clean)
|
2257 | };
|
2258 |
|
2259 | process.stdout.write(JSON.stringify(obj, null, 2));
|
2260 | });
|
2261 | }
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 | function clean(test) {
|
2273 | return {
|
2274 | title: test.title
|
2275 | , fullTitle: test.fullTitle()
|
2276 | , duration: test.duration
|
2277 | }
|
2278 | }
|
2279 | });
|
2280 |
|
2281 | require.register("reporters/landing.js", function(module, exports, require){
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 | var Base = require('./base')
|
2288 | , cursor = Base.cursor
|
2289 | , color = Base.color;
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 | exports = module.exports = Landing;
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 | Base.colors.plane = 0;
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 | Base.colors['plane crash'] = 31;
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 | Base.colors.runway = 90;
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 | function Landing(runner) {
|
2323 | Base.call(this, runner);
|
2324 |
|
2325 | var self = this
|
2326 | , stats = this.stats
|
2327 | , width = Base.window.width * .75 | 0
|
2328 | , total = runner.total
|
2329 | , stream = process.stdout
|
2330 | , plane = color('plane', '✈')
|
2331 | , crashed = -1
|
2332 | , n = 0;
|
2333 |
|
2334 | function runway() {
|
2335 | var buf = Array(width).join('-');
|
2336 | return ' ' + color('runway', buf);
|
2337 | }
|
2338 |
|
2339 | runner.on('start', function(){
|
2340 | stream.write('\n ');
|
2341 | cursor.hide();
|
2342 | });
|
2343 |
|
2344 | runner.on('test end', function(test){
|
2345 |
|
2346 | var col = -1 == crashed
|
2347 | ? width * ++n / total | 0
|
2348 | : crashed;
|
2349 |
|
2350 |
|
2351 | if ('failed' == test.state) {
|
2352 | plane = color('plane crash', '✈');
|
2353 | crashed = col;
|
2354 | }
|
2355 |
|
2356 |
|
2357 | stream.write('\u001b[4F\n\n');
|
2358 | stream.write(runway());
|
2359 | stream.write('\n ');
|
2360 | stream.write(color('runway', Array(col).join('⋅')));
|
2361 | stream.write(plane)
|
2362 | stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
|
2363 | stream.write(runway());
|
2364 | stream.write('\u001b[0m');
|
2365 | });
|
2366 |
|
2367 | runner.on('end', function(){
|
2368 | cursor.show();
|
2369 | console.log();
|
2370 | self.epilogue();
|
2371 | });
|
2372 | }
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 | Landing.prototype = new Base;
|
2379 | Landing.prototype.constructor = Landing;
|
2380 |
|
2381 | });
|
2382 |
|
2383 | require.register("reporters/list.js", function(module, exports, require){
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 | var Base = require('./base')
|
2390 | , cursor = Base.cursor
|
2391 | , color = Base.color;
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 | exports = module.exports = List;
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 | function List(runner) {
|
2407 | Base.call(this, runner);
|
2408 |
|
2409 | var self = this
|
2410 | , stats = this.stats
|
2411 | , n = 0;
|
2412 |
|
2413 | runner.on('start', function(){
|
2414 | console.log();
|
2415 | });
|
2416 |
|
2417 | runner.on('test', function(test){
|
2418 | process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
2419 | });
|
2420 |
|
2421 | runner.on('pending', function(test){
|
2422 | var fmt = color('checkmark', ' -')
|
2423 | + color('pending', ' %s');
|
2424 | console.log(fmt, test.fullTitle());
|
2425 | });
|
2426 |
|
2427 | runner.on('pass', function(test){
|
2428 | var fmt = color('checkmark', ' ✓')
|
2429 | + color('pass', ' %s: ')
|
2430 | + color(test.speed, '%dms');
|
2431 | cursor.CR();
|
2432 | console.log(fmt, test.fullTitle(), test.duration);
|
2433 | });
|
2434 |
|
2435 | runner.on('fail', function(test, err){
|
2436 | cursor.CR();
|
2437 | console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
2438 | });
|
2439 |
|
2440 | runner.on('end', self.epilogue.bind(self));
|
2441 | }
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 | List.prototype = new Base;
|
2448 | List.prototype.constructor = List;
|
2449 |
|
2450 |
|
2451 | });
|
2452 |
|
2453 | require.register("reporters/markdown.js", function(module, exports, require){
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 | var Base = require('./base')
|
2459 | , utils = require('../utils');
|
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 | exports = module.exports = Markdown;
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 | function Markdown(runner) {
|
2475 | Base.call(this, runner);
|
2476 |
|
2477 | var self = this
|
2478 | , stats = this.stats
|
2479 | , total = runner.total
|
2480 | , level = 0
|
2481 | , buf = '';
|
2482 |
|
2483 | function title(str) {
|
2484 | return Array(level).join('#') + ' ' + str;
|
2485 | }
|
2486 |
|
2487 | function indent() {
|
2488 | return Array(level).join(' ');
|
2489 | }
|
2490 |
|
2491 | function mapTOC(suite, obj) {
|
2492 | var ret = obj;
|
2493 | obj = obj[suite.title] = obj[suite.title] || { suite: suite };
|
2494 | suite.suites.forEach(function(suite){
|
2495 | mapTOC(suite, obj);
|
2496 | });
|
2497 | return ret;
|
2498 | }
|
2499 |
|
2500 | function stringifyTOC(obj, level) {
|
2501 | ++level;
|
2502 | var buf = '';
|
2503 | var link;
|
2504 | for (var key in obj) {
|
2505 | if ('suite' == key) continue;
|
2506 | if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
|
2507 | if (key) buf += Array(level).join(' ') + link;
|
2508 | buf += stringifyTOC(obj[key], level);
|
2509 | }
|
2510 | --level;
|
2511 | return buf;
|
2512 | }
|
2513 |
|
2514 | function generateTOC(suite) {
|
2515 | var obj = mapTOC(suite, {});
|
2516 | return stringifyTOC(obj, 0);
|
2517 | }
|
2518 |
|
2519 | generateTOC(runner.suite);
|
2520 |
|
2521 | runner.on('suite', function(suite){
|
2522 | ++level;
|
2523 | var slug = utils.slug(suite.fullTitle());
|
2524 | buf += '<a name="' + slug + '" />' + '\n';
|
2525 | buf += title(suite.title) + '\n';
|
2526 | });
|
2527 |
|
2528 | runner.on('suite end', function(suite){
|
2529 | --level;
|
2530 | });
|
2531 |
|
2532 | runner.on('pass', function(test){
|
2533 | var code = utils.clean(test.fn.toString());
|
2534 | buf += test.title + '.\n';
|
2535 | buf += '\n```js\n';
|
2536 | buf += code + '\n';
|
2537 | buf += '```\n\n';
|
2538 | });
|
2539 |
|
2540 | runner.on('end', function(){
|
2541 | process.stdout.write('# TOC\n');
|
2542 | process.stdout.write(generateTOC(runner.suite));
|
2543 | process.stdout.write(buf);
|
2544 | });
|
2545 | }
|
2546 | });
|
2547 |
|
2548 | require.register("reporters/min.js", function(module, exports, require){
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 | var Base = require('./base');
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 | exports = module.exports = Min;
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 |
|
2569 | function Min(runner) {
|
2570 | Base.call(this, runner);
|
2571 |
|
2572 | runner.on('start', function(){
|
2573 |
|
2574 | process.stdout.write('\u001b[2J');
|
2575 |
|
2576 | process.stdout.write('\u001b[1;3H');
|
2577 | });
|
2578 |
|
2579 | runner.on('end', this.epilogue.bind(this));
|
2580 | }
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 | Min.prototype = new Base;
|
2587 | Min.prototype.constructor = Min;
|
2588 |
|
2589 | });
|
2590 |
|
2591 | require.register("reporters/nyan.js", function(module, exports, require){
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 |
|
2597 | var Base = require('./base')
|
2598 | , color = Base.color;
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 | exports = module.exports = NyanCat;
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 | function NyanCat(runner) {
|
2614 | Base.call(this, runner);
|
2615 |
|
2616 | var self = this
|
2617 | , stats = this.stats
|
2618 | , width = Base.window.width * .75 | 0
|
2619 | , rainbowColors = this.rainbowColors = self.generateColors()
|
2620 | , colorIndex = this.colorIndex = 0
|
2621 | , numerOfLines = this.numberOfLines = 4
|
2622 | , trajectories = this.trajectories = [[], [], [], []]
|
2623 | , nyanCatWidth = this.nyanCatWidth = 11
|
2624 | , trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
|
2625 | , scoreboardWidth = this.scoreboardWidth = 5
|
2626 | , tick = this.tick = 0
|
2627 | , n = 0;
|
2628 |
|
2629 | runner.on('start', function(){
|
2630 | Base.cursor.hide();
|
2631 | self.draw('start');
|
2632 | });
|
2633 |
|
2634 | runner.on('pending', function(test){
|
2635 | self.draw('pending');
|
2636 | });
|
2637 |
|
2638 | runner.on('pass', function(test){
|
2639 | self.draw('pass');
|
2640 | });
|
2641 |
|
2642 | runner.on('fail', function(test, err){
|
2643 | self.draw('fail');
|
2644 | });
|
2645 |
|
2646 | runner.on('end', function(){
|
2647 | Base.cursor.show();
|
2648 | for (var i = 0; i < self.numberOfLines; i++) write('\n');
|
2649 | self.epilogue();
|
2650 | });
|
2651 | }
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 | NyanCat.prototype.draw = function(status){
|
2661 | this.appendRainbow();
|
2662 | this.drawScoreboard();
|
2663 | this.drawRainbow();
|
2664 | this.drawNyanCat(status);
|
2665 | this.tick = !this.tick;
|
2666 | };
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 | NyanCat.prototype.drawScoreboard = function(){
|
2676 | var stats = this.stats;
|
2677 | var colors = Base.colors;
|
2678 |
|
2679 | function draw(color, n) {
|
2680 | write(' ');
|
2681 | write('\u001b[' + color + 'm' + n + '\u001b[0m');
|
2682 | write('\n');
|
2683 | }
|
2684 |
|
2685 | draw(colors.green, stats.passes);
|
2686 | draw(colors.fail, stats.failures);
|
2687 | draw(colors.pending, stats.pending);
|
2688 | write('\n');
|
2689 |
|
2690 | this.cursorUp(this.numberOfLines);
|
2691 | };
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 | NyanCat.prototype.appendRainbow = function(){
|
2700 | var segment = this.tick ? '_' : '-';
|
2701 | var rainbowified = this.rainbowify(segment);
|
2702 |
|
2703 | for (var index = 0; index < this.numberOfLines; index++) {
|
2704 | var trajectory = this.trajectories[index];
|
2705 | if (trajectory.length >= this.trajectoryWidthMax) trajectory.shift();
|
2706 | trajectory.push(rainbowified);
|
2707 | }
|
2708 | };
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 | NyanCat.prototype.drawRainbow = function(){
|
2717 | var self = this;
|
2718 |
|
2719 | this.trajectories.forEach(function(line, index) {
|
2720 | write('\u001b[' + self.scoreboardWidth + 'C');
|
2721 | write(line.join(''));
|
2722 | write('\n');
|
2723 | });
|
2724 |
|
2725 | this.cursorUp(this.numberOfLines);
|
2726 | };
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 | NyanCat.prototype.drawNyanCat = function(status) {
|
2736 | var self = this;
|
2737 | var startWidth = this.scoreboardWidth + this.trajectories[0].length;
|
2738 |
|
2739 | [0, 1, 2, 3].forEach(function(index) {
|
2740 | write('\u001b[' + startWidth + 'C');
|
2741 |
|
2742 | switch (index) {
|
2743 | case 0:
|
2744 | write('_,------,');
|
2745 | write('\n');
|
2746 | break;
|
2747 | case 1:
|
2748 | var padding = self.tick ? ' ' : ' ';
|
2749 | write('_|' + padding + '/\\_/\\ ');
|
2750 | write('\n');
|
2751 | break;
|
2752 | case 2:
|
2753 | var padding = self.tick ? '_' : '__';
|
2754 | var tail = self.tick ? '~' : '^';
|
2755 | var face;
|
2756 | switch (status) {
|
2757 | case 'pass':
|
2758 | face = '( ^ .^)';
|
2759 | break;
|
2760 | case 'fail':
|
2761 | face = '( o .o)';
|
2762 | break;
|
2763 | default:
|
2764 | face = '( - .-)';
|
2765 | }
|
2766 | write(tail + '|' + padding + face + ' ');
|
2767 | write('\n');
|
2768 | break;
|
2769 | case 3:
|
2770 | var padding = self.tick ? ' ' : ' ';
|
2771 | write(padding + '"" "" ');
|
2772 | write('\n');
|
2773 | break;
|
2774 | }
|
2775 | });
|
2776 |
|
2777 | this.cursorUp(this.numberOfLines);
|
2778 | };
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 | NyanCat.prototype.cursorUp = function(n) {
|
2788 | write('\u001b[' + n + 'A');
|
2789 | };
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 | NyanCat.prototype.cursorDown = function(n) {
|
2799 | write('\u001b[' + n + 'B');
|
2800 | };
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 | NyanCat.prototype.generateColors = function(){
|
2810 | var colors = [];
|
2811 |
|
2812 | for (var i = 0; i < (6 * 7); i++) {
|
2813 | var pi3 = Math.floor(Math.PI / 3);
|
2814 | var n = (i * (1.0 / 6));
|
2815 | var r = Math.floor(3 * Math.sin(n) + 3);
|
2816 | var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
|
2817 | var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
|
2818 | colors.push(36 * r + 6 * g + b + 16);
|
2819 | }
|
2820 |
|
2821 | return colors;
|
2822 | };
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 |
|
2831 |
|
2832 | NyanCat.prototype.rainbowify = function(str){
|
2833 | var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
|
2834 | this.colorIndex += 1;
|
2835 | return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
|
2836 | };
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 | function write(string) {
|
2843 | process.stdout.write(string);
|
2844 | }
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 | NyanCat.prototype = new Base;
|
2851 | NyanCat.prototype.constructor = NyanCat;
|
2852 |
|
2853 |
|
2854 | });
|
2855 |
|
2856 | require.register("reporters/progress.js", function(module, exports, require){
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 | var Base = require('./base')
|
2863 | , cursor = Base.cursor
|
2864 | , color = Base.color;
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 | exports = module.exports = Progress;
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 | Base.colors.progress = 90;
|
2877 |
|
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 | function Progress(runner, options) {
|
2887 | Base.call(this, runner);
|
2888 |
|
2889 | var self = this
|
2890 | , options = options || {}
|
2891 | , stats = this.stats
|
2892 | , width = Base.window.width * .50 | 0
|
2893 | , total = runner.total
|
2894 | , complete = 0
|
2895 | , max = Math.max;
|
2896 |
|
2897 |
|
2898 | options.open = options.open || '[';
|
2899 | options.complete = options.complete || '▬';
|
2900 | options.incomplete = options.incomplete || '⋅';
|
2901 | options.close = options.close || ']';
|
2902 | options.verbose = false;
|
2903 |
|
2904 |
|
2905 | runner.on('start', function(){
|
2906 | console.log();
|
2907 | cursor.hide();
|
2908 | });
|
2909 |
|
2910 |
|
2911 | runner.on('test end', function(){
|
2912 | complete++;
|
2913 | var incomplete = total - complete
|
2914 | , percent = complete / total
|
2915 | , n = width * percent | 0
|
2916 | , i = width - n;
|
2917 |
|
2918 | cursor.CR();
|
2919 | process.stdout.write('\u001b[J');
|
2920 | process.stdout.write(color('progress', ' ' + options.open));
|
2921 | process.stdout.write(Array(n).join(options.complete));
|
2922 | process.stdout.write(Array(i).join(options.incomplete));
|
2923 | process.stdout.write(color('progress', options.close));
|
2924 | if (options.verbose) {
|
2925 | process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
|
2926 | }
|
2927 | });
|
2928 |
|
2929 |
|
2930 |
|
2931 | runner.on('end', function(){
|
2932 | cursor.show();
|
2933 | console.log();
|
2934 | self.epilogue();
|
2935 | });
|
2936 | }
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 | Progress.prototype = new Base;
|
2943 | Progress.prototype.constructor = Progress;
|
2944 |
|
2945 |
|
2946 | });
|
2947 |
|
2948 | require.register("reporters/spec.js", function(module, exports, require){
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 | var Base = require('./base')
|
2955 | , cursor = Base.cursor
|
2956 | , color = Base.color;
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 | exports = module.exports = Spec;
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 | function Spec(runner) {
|
2972 | Base.call(this, runner);
|
2973 |
|
2974 | var self = this
|
2975 | , stats = this.stats
|
2976 | , indents = 0
|
2977 | , n = 0;
|
2978 |
|
2979 | function indent() {
|
2980 | return Array(indents).join(' ')
|
2981 | }
|
2982 |
|
2983 | runner.on('start', function(){
|
2984 | console.log();
|
2985 | });
|
2986 |
|
2987 | runner.on('suite', function(suite){
|
2988 | ++indents;
|
2989 | console.log(color('suite', '%s%s'), indent(), suite.title);
|
2990 | });
|
2991 |
|
2992 | runner.on('suite end', function(suite){
|
2993 | --indents;
|
2994 | if (1 == indents) console.log();
|
2995 | });
|
2996 |
|
2997 | runner.on('test', function(test){
|
2998 | process.stdout.write(indent() + color('pass', ' ◦ ' + test.title + ': '));
|
2999 | });
|
3000 |
|
3001 | runner.on('pending', function(test){
|
3002 | var fmt = indent() + color('pending', ' - %s');
|
3003 | console.log(fmt, test.title);
|
3004 | });
|
3005 |
|
3006 | runner.on('pass', function(test){
|
3007 | if ('fast' == test.speed) {
|
3008 | var fmt = indent()
|
3009 | + color('checkmark', ' ✓')
|
3010 | + color('pass', ' %s ');
|
3011 | cursor.CR();
|
3012 | console.log(fmt, test.title);
|
3013 | } else {
|
3014 | var fmt = indent()
|
3015 | + color('checkmark', ' ✓')
|
3016 | + color('pass', ' %s ')
|
3017 | + color(test.speed, '(%dms)');
|
3018 | cursor.CR();
|
3019 | console.log(fmt, test.title, test.duration);
|
3020 | }
|
3021 | });
|
3022 |
|
3023 | runner.on('fail', function(test, err){
|
3024 | cursor.CR();
|
3025 | console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
3026 | });
|
3027 |
|
3028 | runner.on('end', self.epilogue.bind(self));
|
3029 | }
|
3030 |
|
3031 |
|
3032 |
|
3033 |
|
3034 |
|
3035 | Spec.prototype = new Base;
|
3036 | Spec.prototype.constructor = Spec;
|
3037 |
|
3038 |
|
3039 | });
|
3040 |
|
3041 | require.register("reporters/tap.js", function(module, exports, require){
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 | var Base = require('./base')
|
3048 | , cursor = Base.cursor
|
3049 | , color = Base.color;
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 |
|
3055 | exports = module.exports = TAP;
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 | function TAP(runner) {
|
3065 | Base.call(this, runner);
|
3066 |
|
3067 | var self = this
|
3068 | , stats = this.stats
|
3069 | , total = runner.total
|
3070 | , n = 1;
|
3071 |
|
3072 | runner.on('start', function(){
|
3073 | console.log('%d..%d', 1, total);
|
3074 | });
|
3075 |
|
3076 | runner.on('test end', function(){
|
3077 | ++n;
|
3078 | });
|
3079 |
|
3080 | runner.on('pending', function(test){
|
3081 | console.log('ok %d %s # SKIP -', n, title(test));
|
3082 | });
|
3083 |
|
3084 | runner.on('pass', function(test){
|
3085 | console.log('ok %d %s', n, title(test));
|
3086 | });
|
3087 |
|
3088 | runner.on('fail', function(test, err){
|
3089 | console.log('not ok %d %s', n, title(test));
|
3090 | console.log(err.stack.replace(/^/gm, ' '));
|
3091 | });
|
3092 | }
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 | function title(test) {
|
3103 | return test.fullTitle().replace(/#/g, '');
|
3104 | }
|
3105 |
|
3106 | });
|
3107 |
|
3108 | require.register("reporters/teamcity.js", function(module, exports, require){
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 | var Base = require('./base');
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 | exports = module.exports = Teamcity;
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 | function Teamcity(runner) {
|
3130 | Base.call(this, runner);
|
3131 | var stats = this.stats;
|
3132 |
|
3133 | runner.on('start', function() {
|
3134 | console.log("##teamcity[testSuiteStarted name='mocha.suite']");
|
3135 | });
|
3136 |
|
3137 | runner.on('test', function(test) {
|
3138 | console.log("##teamcity[testStarted name='" + escape(test.fullTitle()) + "']");
|
3139 | });
|
3140 |
|
3141 | runner.on('fail', function(test, err) {
|
3142 | console.log("##teamcity[testFailed name='" + escape(test.fullTitle()) + "' message='" + escape(err.message) + "']");
|
3143 | });
|
3144 |
|
3145 | runner.on('pending', function(test) {
|
3146 | console.log("##teamcity[testIgnored name='" + escape(test.fullTitle()) + "' message='pending']");
|
3147 | });
|
3148 |
|
3149 | runner.on('test end', function(test) {
|
3150 | console.log("##teamcity[testFinished name='" + escape(test.fullTitle()) + "' duration='" + test.duration + "']");
|
3151 | });
|
3152 |
|
3153 | runner.on('end', function() {
|
3154 | console.log("##teamcity[testSuiteFinished name='mocha.suite' duration='" + stats.duration + "']");
|
3155 | });
|
3156 | }
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 | function escape(str) {
|
3163 | return str
|
3164 | .replace(/\|/g, "||")
|
3165 | .replace(/\n/g, "|n")
|
3166 | .replace(/\r/g, "|r")
|
3167 | .replace(/\[/g, "|[")
|
3168 | .replace(/\]/g, "|]")
|
3169 | .replace(/\u0085/g, "|x")
|
3170 | .replace(/\u2028/g, "|l")
|
3171 | .replace(/\u2029/g, "|p")
|
3172 | .replace(/'/g, "|'");
|
3173 | }
|
3174 |
|
3175 | });
|
3176 |
|
3177 | require.register("reporters/xunit.js", function(module, exports, require){
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 | var Base = require('./base')
|
3184 | , utils = require('../utils')
|
3185 | , escape = utils.escape;
|
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 | var Date = global.Date
|
3192 | , setTimeout = global.setTimeout
|
3193 | , setInterval = global.setInterval
|
3194 | , clearTimeout = global.clearTimeout
|
3195 | , clearInterval = global.clearInterval;
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 | exports = module.exports = XUnit;
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 | function XUnit(runner) {
|
3211 | Base.call(this, runner);
|
3212 | var stats = this.stats
|
3213 | , tests = []
|
3214 | , self = this;
|
3215 |
|
3216 | runner.on('pass', function(test){
|
3217 | tests.push(test);
|
3218 | });
|
3219 |
|
3220 | runner.on('fail', function(test){
|
3221 | tests.push(test);
|
3222 | });
|
3223 |
|
3224 | runner.on('end', function(){
|
3225 | console.log(tag('testsuite', {
|
3226 | name: 'Mocha Tests'
|
3227 | , tests: stats.tests
|
3228 | , failures: stats.failures
|
3229 | , errors: stats.failures
|
3230 | , skip: stats.tests - stats.failures - stats.passes
|
3231 | , timestamp: (new Date).toUTCString()
|
3232 | , time: stats.duration / 1000
|
3233 | }, false));
|
3234 |
|
3235 | tests.forEach(test);
|
3236 | console.log('</testsuite>');
|
3237 | });
|
3238 | }
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 | XUnit.prototype = new Base;
|
3245 | XUnit.prototype.constructor = XUnit;
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 | function test(test) {
|
3253 | var attrs = {
|
3254 | classname: test.parent.fullTitle()
|
3255 | , name: test.title
|
3256 | , time: test.duration / 1000
|
3257 | };
|
3258 |
|
3259 | if ('failed' == test.state) {
|
3260 | var err = test.err;
|
3261 | attrs.message = escape(err.message);
|
3262 | console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack))));
|
3263 | } else if (test.pending) {
|
3264 | console.log(tag('testcase', attrs, false, tag('skipped', {}, true)));
|
3265 | } else {
|
3266 | console.log(tag('testcase', attrs, true) );
|
3267 | }
|
3268 | }
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 | function tag(name, attrs, close, content) {
|
3275 | var end = close ? '/>' : '>'
|
3276 | , pairs = []
|
3277 | , tag;
|
3278 |
|
3279 | for (var key in attrs) {
|
3280 | pairs.push(key + '="' + escape(attrs[key]) + '"');
|
3281 | }
|
3282 |
|
3283 | tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
|
3284 | if (content) tag += content + '</' + name + end;
|
3285 | return tag;
|
3286 | }
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 | function cdata(str) {
|
3293 | return '<![CDATA[' + escape(str) + ']]>';
|
3294 | }
|
3295 |
|
3296 | });
|
3297 |
|
3298 | require.register("runnable.js", function(module, exports, require){
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 | var EventEmitter = require('browser/events').EventEmitter
|
3305 | , debug = require('browser/debug')('mocha:runnable');
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 | var Date = global.Date
|
3312 | , setTimeout = global.setTimeout
|
3313 | , setInterval = global.setInterval
|
3314 | , clearTimeout = global.clearTimeout
|
3315 | , clearInterval = global.clearInterval;
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 | module.exports = Runnable;
|
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 |
|
3331 | function Runnable(title, fn) {
|
3332 | this.title = title;
|
3333 | this.fn = fn;
|
3334 | this.async = fn && fn.length;
|
3335 | this.sync = ! this.async;
|
3336 | this._timeout = 2000;
|
3337 | this.timedOut = false;
|
3338 | }
|
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 | Runnable.prototype = new EventEmitter;
|
3345 | Runnable.prototype.constructor = Runnable;
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 | Runnable.prototype.timeout = function(ms){
|
3357 | if (0 == arguments.length) return this._timeout;
|
3358 | debug('timeout %d', ms);
|
3359 | this._timeout = ms;
|
3360 | if (this.timer) this.resetTimeout();
|
3361 | return this;
|
3362 | };
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 | Runnable.prototype.fullTitle = function(){
|
3373 | return this.parent.fullTitle() + ' ' + this.title;
|
3374 | };
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 | Runnable.prototype.clearTimeout = function(){
|
3383 | clearTimeout(this.timer);
|
3384 | };
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 | Runnable.prototype.inspect = function(){
|
3394 | return JSON.stringify(this, function(key, val){
|
3395 | if ('_' == key[0]) return;
|
3396 | if ('parent' == key) return '#<Suite>';
|
3397 | if ('ctx' == key) return '#<Context>';
|
3398 | return val;
|
3399 | }, 2);
|
3400 | };
|
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 | Runnable.prototype.resetTimeout = function(){
|
3409 | var self = this
|
3410 | , ms = this.timeout();
|
3411 |
|
3412 | this.clearTimeout();
|
3413 | if (ms) {
|
3414 | this.timer = setTimeout(function(){
|
3415 | self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
|
3416 | self.timedOut = true;
|
3417 | }, ms);
|
3418 | }
|
3419 | };
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 | Runnable.prototype.run = function(fn){
|
3429 | var self = this
|
3430 | , ms = this.timeout()
|
3431 | , start = new Date
|
3432 | , ctx = this.ctx
|
3433 | , finished
|
3434 | , emitted;
|
3435 |
|
3436 | if (ctx) ctx.runnable(this);
|
3437 |
|
3438 |
|
3439 | if (this.async) {
|
3440 | if (ms) {
|
3441 | this.timer = setTimeout(function(){
|
3442 | done(new Error('timeout of ' + ms + 'ms exceeded'));
|
3443 | self.timedOut = true;
|
3444 | }, ms);
|
3445 | }
|
3446 | }
|
3447 |
|
3448 |
|
3449 | function multiple(err) {
|
3450 | if (emitted) return;
|
3451 | emitted = true;
|
3452 | self.emit('error', err || new Error('done() called multiple times'));
|
3453 | }
|
3454 |
|
3455 |
|
3456 | function done(err) {
|
3457 | if (self.timedOut) return;
|
3458 | if (finished) return multiple(err);
|
3459 | self.clearTimeout();
|
3460 | self.duration = new Date - start;
|
3461 | finished = true;
|
3462 | fn(err);
|
3463 | }
|
3464 |
|
3465 |
|
3466 | this.callback = done;
|
3467 |
|
3468 |
|
3469 | if (this.async) {
|
3470 | try {
|
3471 | this.fn.call(ctx, function(err){
|
3472 | if (err instanceof Error) return done(err);
|
3473 | if (null != err) return done(new Error('done() invoked with non-Error: ' + err));
|
3474 | done();
|
3475 | });
|
3476 | } catch (err) {
|
3477 | done(err);
|
3478 | }
|
3479 | return;
|
3480 | }
|
3481 |
|
3482 |
|
3483 | try {
|
3484 | if (!this.pending) this.fn.call(ctx);
|
3485 | this.duration = new Date - start;
|
3486 | fn();
|
3487 | } catch (err) {
|
3488 | fn(err);
|
3489 | }
|
3490 | };
|
3491 |
|
3492 | });
|
3493 |
|
3494 | require.register("runner.js", function(module, exports, require){
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 | var EventEmitter = require('browser/events').EventEmitter
|
3501 | , debug = require('browser/debug')('mocha:runner')
|
3502 | , Test = require('./test')
|
3503 | , utils = require('./utils')
|
3504 | , filter = utils.filter
|
3505 | , keys = utils.keys
|
3506 | , noop = function(){};
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 | module.exports = Runner;
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 | function Runner(suite) {
|
3534 | var self = this;
|
3535 | this._globals = [];
|
3536 | this.suite = suite;
|
3537 | this.total = suite.total();
|
3538 | this.failures = 0;
|
3539 | this.on('test end', function(test){ self.checkGlobals(test); });
|
3540 | this.on('hook end', function(hook){ self.checkGlobals(hook); });
|
3541 | this.grep(/.*/);
|
3542 | this.globals(utils.keys(global).concat(['errno']));
|
3543 | }
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 | Runner.prototype = new EventEmitter;
|
3550 | Runner.prototype.constructor = Runner;
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 | Runner.prototype.grep = function(re, invert){
|
3564 | debug('grep %s', re);
|
3565 | this._grep = re;
|
3566 | this._invert = invert;
|
3567 | this.total = this.grepTotal(this.suite);
|
3568 | return this;
|
3569 | };
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 | Runner.prototype.grepTotal = function(suite) {
|
3581 | var self = this;
|
3582 | var total = 0;
|
3583 |
|
3584 | suite.eachTest(function(test){
|
3585 | var match = self._grep.test(test.fullTitle());
|
3586 | if (self._invert) match = !match;
|
3587 | if (match) total++;
|
3588 | });
|
3589 |
|
3590 | return total;
|
3591 | };
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 | Runner.prototype.globals = function(arr){
|
3602 | if (0 == arguments.length) return this._globals;
|
3603 | debug('globals %j', arr);
|
3604 | utils.forEach(arr, function(arr){
|
3605 | this._globals.push(arr);
|
3606 | }, this);
|
3607 | return this;
|
3608 | };
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 | Runner.prototype.checkGlobals = function(test){
|
3617 | if (this.ignoreLeaks) return;
|
3618 | var leaks = filterLeaks(this._globals);
|
3619 |
|
3620 | this._globals = this._globals.concat(leaks);
|
3621 |
|
3622 | if (leaks.length > 1) {
|
3623 | this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
|
3624 | } else if (leaks.length) {
|
3625 | this.fail(test, new Error('global leak detected: ' + leaks[0]));
|
3626 | }
|
3627 | };
|
3628 |
|
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 | Runner.prototype.fail = function(test, err){
|
3638 | ++this.failures;
|
3639 | test.state = 'failed';
|
3640 | if ('string' == typeof err) {
|
3641 | err = new Error('the string "' + err + '" was thrown, throw an Error :)');
|
3642 | }
|
3643 | this.emit('fail', test, err);
|
3644 | };
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 | Runner.prototype.failHook = function(hook, err){
|
3660 | this.fail(hook, err);
|
3661 | this.emit('end');
|
3662 | };
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 | Runner.prototype.hook = function(name, fn){
|
3673 | var suite = this.suite
|
3674 | , hooks = suite['_' + name]
|
3675 | , ms = suite._timeout
|
3676 | , self = this
|
3677 | , timer;
|
3678 |
|
3679 | function next(i) {
|
3680 | var hook = hooks[i];
|
3681 | if (!hook) return fn();
|
3682 | self.currentRunnable = hook;
|
3683 |
|
3684 | self.emit('hook', hook);
|
3685 |
|
3686 | hook.on('error', function(err){
|
3687 | self.failHook(hook, err);
|
3688 | });
|
3689 |
|
3690 | hook.run(function(err){
|
3691 | hook.removeAllListeners('error');
|
3692 | var testError = hook.error();
|
3693 | if (testError) self.fail(self.test, testError);
|
3694 | if (err) return self.failHook(hook, err);
|
3695 | self.emit('hook end', hook);
|
3696 | next(++i);
|
3697 | });
|
3698 | }
|
3699 |
|
3700 | process.nextTick(function(){
|
3701 | next(0);
|
3702 | });
|
3703 | };
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 | Runner.prototype.hooks = function(name, suites, fn){
|
3716 | var self = this
|
3717 | , orig = this.suite;
|
3718 |
|
3719 | function next(suite) {
|
3720 | self.suite = suite;
|
3721 |
|
3722 | if (!suite) {
|
3723 | self.suite = orig;
|
3724 | return fn();
|
3725 | }
|
3726 |
|
3727 | self.hook(name, function(err){
|
3728 | if (err) {
|
3729 | self.suite = orig;
|
3730 | return fn(err);
|
3731 | }
|
3732 |
|
3733 | next(suites.pop());
|
3734 | });
|
3735 | }
|
3736 |
|
3737 | next(suites.pop());
|
3738 | };
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 | Runner.prototype.hookUp = function(name, fn){
|
3749 | var suites = [this.suite].concat(this.parents()).reverse();
|
3750 | this.hooks(name, suites, fn);
|
3751 | };
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 | Runner.prototype.hookDown = function(name, fn){
|
3762 | var suites = [this.suite].concat(this.parents());
|
3763 | this.hooks(name, suites, fn);
|
3764 | };
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 | Runner.prototype.parents = function(){
|
3775 | var suite = this.suite
|
3776 | , suites = [];
|
3777 | while (suite = suite.parent) suites.push(suite);
|
3778 | return suites;
|
3779 | };
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 | Runner.prototype.runTest = function(fn){
|
3789 | var test = this.test
|
3790 | , self = this;
|
3791 |
|
3792 | try {
|
3793 | test.on('error', function(err){
|
3794 | self.fail(test, err);
|
3795 | });
|
3796 | test.run(fn);
|
3797 | } catch (err) {
|
3798 | fn(err);
|
3799 | }
|
3800 | };
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 | Runner.prototype.runTests = function(suite, fn){
|
3812 | var self = this
|
3813 | , tests = suite.tests
|
3814 | , test;
|
3815 |
|
3816 | function next(err) {
|
3817 |
|
3818 | if (self.failures && suite._bail) return fn();
|
3819 |
|
3820 |
|
3821 | test = tests.shift();
|
3822 |
|
3823 |
|
3824 | if (!test) return fn();
|
3825 |
|
3826 |
|
3827 | var match = self._grep.test(test.fullTitle());
|
3828 | if (self._invert) match = !match;
|
3829 | if (!match) return next();
|
3830 |
|
3831 |
|
3832 | if (test.pending) {
|
3833 | self.emit('pending', test);
|
3834 | self.emit('test end', test);
|
3835 | return next();
|
3836 | }
|
3837 |
|
3838 |
|
3839 | self.emit('test', self.test = test);
|
3840 | self.hookDown('beforeEach', function(){
|
3841 | self.currentRunnable = self.test;
|
3842 | self.runTest(function(err){
|
3843 | test = self.test;
|
3844 |
|
3845 | if (err) {
|
3846 | self.fail(test, err);
|
3847 | self.emit('test end', test);
|
3848 | return self.hookUp('afterEach', next);
|
3849 | }
|
3850 |
|
3851 | test.state = 'passed';
|
3852 | self.emit('pass', test);
|
3853 | self.emit('test end', test);
|
3854 | self.hookUp('afterEach', next);
|
3855 | });
|
3856 | });
|
3857 | }
|
3858 |
|
3859 | this.next = next;
|
3860 | next();
|
3861 | };
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 | Runner.prototype.runSuite = function(suite, fn){
|
3873 | var total = this.grepTotal(suite)
|
3874 | , self = this
|
3875 | , i = 0;
|
3876 |
|
3877 | debug('run suite %s', suite.fullTitle());
|
3878 |
|
3879 | if (!total) return fn();
|
3880 |
|
3881 | this.emit('suite', this.suite = suite);
|
3882 |
|
3883 | function next() {
|
3884 | var curr = suite.suites[i++];
|
3885 | if (!curr) return done();
|
3886 | self.runSuite(curr, next);
|
3887 | }
|
3888 |
|
3889 | function done() {
|
3890 | self.suite = suite;
|
3891 | self.hook('afterAll', function(){
|
3892 | self.emit('suite end', suite);
|
3893 | fn();
|
3894 | });
|
3895 | }
|
3896 |
|
3897 | this.hook('beforeAll', function(){
|
3898 | self.runTests(suite, next);
|
3899 | });
|
3900 | };
|
3901 |
|
3902 |
|
3903 |
|
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 |
|
3909 | Runner.prototype.uncaught = function(err){
|
3910 | debug('uncaught exception %s', err.message);
|
3911 | var runnable = this.currentRunnable;
|
3912 | if (!runnable || 'failed' == runnable.state) return;
|
3913 | runnable.clearTimeout();
|
3914 | err.uncaught = true;
|
3915 | this.fail(runnable, err);
|
3916 |
|
3917 |
|
3918 | if ('test' == runnable.type) {
|
3919 | this.emit('test end', runnable);
|
3920 | this.hookUp('afterEach', this.next);
|
3921 | return;
|
3922 | }
|
3923 |
|
3924 |
|
3925 | this.emit('end');
|
3926 | };
|
3927 |
|
3928 |
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 | Runner.prototype.run = function(fn){
|
3938 | var self = this
|
3939 | , fn = fn || function(){};
|
3940 |
|
3941 | debug('start');
|
3942 |
|
3943 |
|
3944 | function uncaught(err) {
|
3945 | self.uncaught(err);
|
3946 | }
|
3947 |
|
3948 |
|
3949 | this.on('end', function(){
|
3950 | debug('end');
|
3951 | process.removeListener('uncaughtException', uncaught);
|
3952 | fn(self.failures);
|
3953 | });
|
3954 |
|
3955 |
|
3956 | this.emit('start');
|
3957 | this.runSuite(this.suite, function(){
|
3958 | debug('finished running');
|
3959 | self.emit('end');
|
3960 | });
|
3961 |
|
3962 |
|
3963 | process.on('uncaughtException', uncaught);
|
3964 |
|
3965 | return this;
|
3966 | };
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 | function filterLeaks(ok) {
|
3977 | return filter(keys(global), function(key){
|
3978 | var matched = filter(ok, function(ok){
|
3979 | if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
|
3980 | return key == ok;
|
3981 | });
|
3982 | return matched.length == 0 && (!global.navigator || 'onerror' !== key);
|
3983 | });
|
3984 | }
|
3985 | });
|
3986 |
|
3987 | require.register("suite.js", function(module, exports, require){
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 | var EventEmitter = require('browser/events').EventEmitter
|
3994 | , debug = require('browser/debug')('mocha:suite')
|
3995 | , utils = require('./utils')
|
3996 | , Hook = require('./hook');
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 | exports = module.exports = Suite;
|
4003 |
|
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 | exports.create = function(parent, title){
|
4018 | var suite = new Suite(title, parent.ctx);
|
4019 | suite.parent = parent;
|
4020 | if (parent.pending) suite.pending = true;
|
4021 | title = suite.fullTitle();
|
4022 | parent.addSuite(suite);
|
4023 | return suite;
|
4024 | };
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 | function Suite(title, ctx) {
|
4036 | this.title = title;
|
4037 | this.ctx = ctx;
|
4038 | this.suites = [];
|
4039 | this.tests = [];
|
4040 | this.pending = false;
|
4041 | this._beforeEach = [];
|
4042 | this._beforeAll = [];
|
4043 | this._afterEach = [];
|
4044 | this._afterAll = [];
|
4045 | this.root = !title;
|
4046 | this._timeout = 2000;
|
4047 | this._bail = false;
|
4048 | }
|
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 | Suite.prototype = new EventEmitter;
|
4055 | Suite.prototype.constructor = Suite;
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 | Suite.prototype.clone = function(){
|
4066 | var suite = new Suite(this.title);
|
4067 | debug('clone');
|
4068 | suite.ctx = this.ctx;
|
4069 | suite.timeout(this.timeout());
|
4070 | suite.bail(this.bail());
|
4071 | return suite;
|
4072 | };
|
4073 |
|
4074 |
|
4075 |
|
4076 |
|
4077 |
|
4078 |
|
4079 |
|
4080 |
|
4081 |
|
4082 | Suite.prototype.timeout = function(ms){
|
4083 | if (0 == arguments.length) return this._timeout;
|
4084 | if (String(ms).match(/s$/)) ms = parseFloat(ms) * 1000;
|
4085 | debug('timeout %d', ms);
|
4086 | this._timeout = parseInt(ms, 10);
|
4087 | return this;
|
4088 | };
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 | Suite.prototype.bail = function(bail){
|
4099 | if (0 == arguments.length) return this._bail;
|
4100 | debug('bail %s', bail);
|
4101 | this._bail = bail;
|
4102 | return this;
|
4103 | };
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 | Suite.prototype.beforeAll = function(fn){
|
4114 | if (this.pending) return this;
|
4115 | var hook = new Hook('"before all" hook', fn);
|
4116 | hook.parent = this;
|
4117 | hook.timeout(this.timeout());
|
4118 | hook.ctx = this.ctx;
|
4119 | this._beforeAll.push(hook);
|
4120 | this.emit('beforeAll', hook);
|
4121 | return this;
|
4122 | };
|
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 | Suite.prototype.afterAll = function(fn){
|
4133 | if (this.pending) return this;
|
4134 | var hook = new Hook('"after all" hook', fn);
|
4135 | hook.parent = this;
|
4136 | hook.timeout(this.timeout());
|
4137 | hook.ctx = this.ctx;
|
4138 | this._afterAll.push(hook);
|
4139 | this.emit('afterAll', hook);
|
4140 | return this;
|
4141 | };
|
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 |
|
4147 |
|
4148 |
|
4149 |
|
4150 |
|
4151 | Suite.prototype.beforeEach = function(fn){
|
4152 | if (this.pending) return this;
|
4153 | var hook = new Hook('"before each" hook', fn);
|
4154 | hook.parent = this;
|
4155 | hook.timeout(this.timeout());
|
4156 | hook.ctx = this.ctx;
|
4157 | this._beforeEach.push(hook);
|
4158 | this.emit('beforeEach', hook);
|
4159 | return this;
|
4160 | };
|
4161 |
|
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 | Suite.prototype.afterEach = function(fn){
|
4171 | if (this.pending) return this;
|
4172 | var hook = new Hook('"after each" hook', fn);
|
4173 | hook.parent = this;
|
4174 | hook.timeout(this.timeout());
|
4175 | hook.ctx = this.ctx;
|
4176 | this._afterEach.push(hook);
|
4177 | this.emit('afterEach', hook);
|
4178 | return this;
|
4179 | };
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 | Suite.prototype.addSuite = function(suite){
|
4190 | suite.parent = this;
|
4191 | suite.timeout(this.timeout());
|
4192 | suite.bail(this.bail());
|
4193 | this.suites.push(suite);
|
4194 | this.emit('suite', suite);
|
4195 | return this;
|
4196 | };
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 | Suite.prototype.addTest = function(test){
|
4207 | test.parent = this;
|
4208 | test.timeout(this.timeout());
|
4209 | test.ctx = this.ctx;
|
4210 | this.tests.push(test);
|
4211 | this.emit('test', test);
|
4212 | return this;
|
4213 | };
|
4214 |
|
4215 |
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 |
|
4223 | Suite.prototype.fullTitle = function(){
|
4224 | if (this.parent) {
|
4225 | var full = this.parent.fullTitle();
|
4226 | if (full) return full + ' ' + this.title;
|
4227 | }
|
4228 | return this.title;
|
4229 | };
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 |
|
4237 |
|
4238 | Suite.prototype.total = function(){
|
4239 | return utils.reduce(this.suites, function(sum, suite){
|
4240 | return sum + suite.total();
|
4241 | }, 0) + this.tests.length;
|
4242 | };
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 | Suite.prototype.eachTest = function(fn){
|
4255 | utils.forEach(this.tests, fn);
|
4256 | utils.forEach(this.suites, function(suite){
|
4257 | suite.eachTest(fn);
|
4258 | });
|
4259 | return this;
|
4260 | };
|
4261 |
|
4262 | });
|
4263 |
|
4264 | require.register("test.js", function(module, exports, require){
|
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 | var Runnable = require('./runnable');
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 | module.exports = Test;
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 |
|
4282 |
|
4283 |
|
4284 |
|
4285 |
|
4286 | function Test(title, fn) {
|
4287 | Runnable.call(this, title, fn);
|
4288 | this.pending = !fn;
|
4289 | this.type = 'test';
|
4290 | }
|
4291 |
|
4292 |
|
4293 |
|
4294 |
|
4295 |
|
4296 | Test.prototype = new Runnable;
|
4297 | Test.prototype.constructor = Test;
|
4298 |
|
4299 |
|
4300 | });
|
4301 |
|
4302 | require.register("utils.js", function(module, exports, require){
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 | var fs = require('browser/fs')
|
4309 | , path = require('browser/path')
|
4310 | , join = path.join
|
4311 | , debug = require('browser/debug')('mocha:watch');
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 | var ignore = ['node_modules', '.git'];
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 |
|
4324 |
|
4325 |
|
4326 |
|
4327 | exports.escape = function(html) {
|
4328 | return String(html)
|
4329 | .replace(/&/g, '&')
|
4330 | .replace(/"/g, '"')
|
4331 | .replace(/</g, '<')
|
4332 | .replace(/>/g, '>');
|
4333 | };
|
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 |
|
4343 |
|
4344 | exports.forEach = function(arr, fn, scope) {
|
4345 | for (var i = 0, l = arr.length; i < l; i++)
|
4346 | fn.call(scope, arr[i], i);
|
4347 | };
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 | exports.indexOf = function (arr, obj, start) {
|
4359 | for (var i = start || 0, l = arr.length; i < l; i++) {
|
4360 | if (arr[i] === obj)
|
4361 | return i;
|
4362 | }
|
4363 | return -1;
|
4364 | };
|
4365 |
|
4366 |
|
4367 |
|
4368 |
|
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 |
|
4375 |
|
4376 | exports.reduce = function(arr, fn, val, scope) {
|
4377 | var rval = val;
|
4378 |
|
4379 | for (var i = 0, l = arr.length; i < l; i++) {
|
4380 | rval = fn.call(scope, rval, arr[i], i, arr);
|
4381 | }
|
4382 |
|
4383 | return rval;
|
4384 | };
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 | exports.filter = function(arr, fn, scope) {
|
4396 | var ret = [];
|
4397 |
|
4398 | for (var i = 0, l = arr.length; i < l; i++) {
|
4399 | var val = arr[i];
|
4400 | if (fn.call(scope, val, i, arr))
|
4401 | ret.push(val);
|
4402 | }
|
4403 |
|
4404 | return ret;
|
4405 | };
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 | exports.keys = Object.keys || function(obj) {
|
4416 | var keys = []
|
4417 | , has = Object.prototype.hasOwnProperty
|
4418 |
|
4419 | for (var key in obj) {
|
4420 | if (has.call(obj, key)) {
|
4421 | keys.push(key);
|
4422 | }
|
4423 | }
|
4424 |
|
4425 | return keys;
|
4426 | };
|
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 | exports.watch = function(files, fn){
|
4438 | var options = { interval: 100 };
|
4439 | files.forEach(function(file){
|
4440 | debug('file %s', file);
|
4441 | fs.watchFile(file, options, function(curr, prev){
|
4442 | if (prev.mtime < curr.mtime) fn(file);
|
4443 | });
|
4444 | });
|
4445 | };
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 | function ignored(path){
|
4452 | return !~ignore.indexOf(path);
|
4453 | }
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 | exports.files = function(dir, ret){
|
4463 | ret = ret || [];
|
4464 |
|
4465 | fs.readdirSync(dir)
|
4466 | .filter(ignored)
|
4467 | .forEach(function(path){
|
4468 | path = join(dir, path);
|
4469 | if (fs.statSync(path).isDirectory()) {
|
4470 | exports.files(path, ret);
|
4471 | } else if (path.match(/\.(js|coffee)$/)) {
|
4472 | ret.push(path);
|
4473 | }
|
4474 | });
|
4475 |
|
4476 | return ret;
|
4477 | };
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 | exports.slug = function(str){
|
4488 | return str
|
4489 | .toLowerCase()
|
4490 | .replace(/ +/g, '-')
|
4491 | .replace(/[^-\w]/g, '');
|
4492 | };
|
4493 |
|
4494 |
|
4495 |
|
4496 |
|
4497 |
|
4498 |
|
4499 | exports.clean = function(str) {
|
4500 | str = str
|
4501 | .replace(/^function *\(.*\) *{/, '')
|
4502 | .replace(/\s+\}$/, '');
|
4503 |
|
4504 | var spaces = str.match(/^\n?( *)/)[1].length
|
4505 | , re = new RegExp('^ {' + spaces + '}', 'gm');
|
4506 |
|
4507 | str = str.replace(re, '');
|
4508 |
|
4509 | return exports.trim(str);
|
4510 | };
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 |
|
4518 |
|
4519 |
|
4520 | exports.escapeRegexp = function(str){
|
4521 | return str.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
|
4522 | };
|
4523 |
|
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 |
|
4529 |
|
4530 |
|
4531 |
|
4532 | exports.trim = function(str){
|
4533 | return str.replace(/^\s+|\s+$/g, '');
|
4534 | };
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 |
|
4544 | exports.parseQuery = function(qs){
|
4545 | return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
|
4546 | var i = pair.indexOf('=')
|
4547 | , key = pair.slice(0, i)
|
4548 | , val = pair.slice(++i);
|
4549 |
|
4550 | obj[key] = decodeURIComponent(val);
|
4551 | return obj;
|
4552 | }, {});
|
4553 | };
|
4554 |
|
4555 |
|
4556 |
|
4557 |
|
4558 |
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 | function highlight(js) {
|
4564 | return js
|
4565 | .replace(/</g, '<')
|
4566 | .replace(/>/g, '>')
|
4567 | .replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
4568 | .replace(/('.*?')/gm, '<span class="string">$1</span>')
|
4569 | .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
4570 | .replace(/(\d+)/gm, '<span class="number">$1</span>')
|
4571 | .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
|
4572 | .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
|
4573 | }
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 |
|
4581 |
|
4582 | exports.highlightTags = function(name) {
|
4583 | var code = document.getElementsByTagName(name);
|
4584 | for (var i = 0, len = code.length; i < len; ++i) {
|
4585 | code[i].innerHTML = highlight(code[i].innerHTML);
|
4586 | }
|
4587 | };
|
4588 | });
|
4589 |
|
4590 |
|
4591 |
|
4592 |
|
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
|
4598 | process = {};
|
4599 | process.exit = function(status){};
|
4600 | process.stdout = {};
|
4601 | global = window;
|
4602 |
|
4603 |
|
4604 |
|
4605 |
|
4606 |
|
4607 | process.nextTick = (function(){
|
4608 |
|
4609 | if (window.ActiveXObject || !window.postMessage) {
|
4610 | return function(fn){ fn() };
|
4611 | }
|
4612 |
|
4613 |
|
4614 |
|
4615 | var timeouts = []
|
4616 | , name = 'mocha-zero-timeout'
|
4617 |
|
4618 | window.addEventListener('message', function(e){
|
4619 | if (e.source == window && e.data == name) {
|
4620 | if (e.stopPropagation) e.stopPropagation();
|
4621 | if (timeouts.length) timeouts.shift()();
|
4622 | }
|
4623 | }, true);
|
4624 |
|
4625 | return function(fn){
|
4626 | timeouts.push(fn);
|
4627 | window.postMessage(name, '*');
|
4628 | }
|
4629 | })();
|
4630 |
|
4631 |
|
4632 |
|
4633 |
|
4634 |
|
4635 | process.removeListener = function(e){
|
4636 | if ('uncaughtException' == e) {
|
4637 | window.onerror = null;
|
4638 | }
|
4639 | };
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 | process.on = function(e, fn){
|
4646 | if ('uncaughtException' == e) {
|
4647 | window.onerror = fn;
|
4648 | }
|
4649 | };
|
4650 |
|
4651 |
|
4652 | ;(function(){
|
4653 |
|
4654 | |
4655 |
|
4656 |
|
4657 |
|
4658 | var Mocha = window.Mocha = require('mocha'),
|
4659 | mocha = window.mocha = new Mocha({ reporter: 'html' });
|
4660 |
|
4661 | |
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 | mocha.ui = function(ui){
|
4667 | Mocha.prototype.ui.call(this, ui);
|
4668 | this.suite.emit('pre-require', window, null, this);
|
4669 | return this;
|
4670 | };
|
4671 |
|
4672 | |
4673 |
|
4674 |
|
4675 |
|
4676 | mocha.setup = function(opts){
|
4677 | if ('string' == typeof opts) opts = { ui: opts };
|
4678 | for (var opt in opts) this[opt](opts[opt]);
|
4679 | return this;
|
4680 | };
|
4681 |
|
4682 | |
4683 |
|
4684 |
|
4685 |
|
4686 | mocha.run = function(fn){
|
4687 | var options = mocha.options;
|
4688 | mocha.globals('location');
|
4689 |
|
4690 | var query = Mocha.utils.parseQuery(window.location.search || '');
|
4691 | if (query.grep) mocha.grep(query.grep);
|
4692 |
|
4693 | return Mocha.prototype.run.call(mocha, function(){
|
4694 | Mocha.utils.highlightTags('code');
|
4695 | if (fn) fn();
|
4696 | });
|
4697 | };
|
4698 | })();
|
4699 | })(); |
\ | No newline at end of file |