rails_sandbox_mocha_chai 0.0.1

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