mocha 2.5.2 → 2.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 2.5.3 / 2016-05-25
2
+
3
+ - [#2112] - Fix HTML reporter regression causing duplicate error output ([@danielstjules] via 6d24063)
4
+ - [#2119] - Make HTML reporter failure/passed links preventDefault to avoid SPA's hash navigation ([@jimenglish81] via 9e93efc)
5
+
6
+ [@danielstjules]: https://github.com/danielstjules
7
+ [@jimenglish81]: https://github.com/jimenglish81
8
+ [#2112]: https://github.com/mochajs/mocha/pull/2112
9
+ [#2119]: https://github.com/mochajs/mocha/pull/2119
10
+
1
11
  # 2.5.2 / 2016-05-24
2
12
 
3
13
  - [#2178] - Avoid double and triple xUnit XML escaping ([@graingert] via 49b5ff1)
@@ -80,7 +80,8 @@ function HTML(runner) {
80
80
  }
81
81
 
82
82
  // pass toggle
83
- on(passesLink, 'click', function() {
83
+ on(passesLink, 'click', function(evt) {
84
+ evt.preventDefault();
84
85
  unhide();
85
86
  var name = (/pass/).test(report.className) ? '' : ' pass';
86
87
  report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -90,7 +91,8 @@ function HTML(runner) {
90
91
  });
91
92
 
92
93
  // failure toggle
93
- on(failuresLink, 'click', function() {
94
+ on(failuresLink, 'click', function(evt) {
95
+ evt.preventDefault();
94
96
  unhide();
95
97
  var name = (/fail/).test(report.className) ? '' : ' fail';
96
98
  report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -128,88 +130,82 @@ function HTML(runner) {
128
130
  stack.shift();
129
131
  });
130
132
 
131
- runner.on('fail', function(test) {
132
- // For type = 'test' its possible that the test failed due to multiple
133
- // done() calls. So report the issue here.
134
- if (test.type === 'hook'
135
- || test.type === 'test') {
136
- runner.emit('test end', test);
137
- }
133
+ runner.on('pass', function(test) {
134
+ var url = self.testURL(test);
135
+ var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
136
+ + '<a href="%s" class="replay">‣</a></h2></li>';
137
+ var el = fragment(markup, test.speed, test.title, test.duration, url);
138
+ self.addCodeToggle(el, test.body);
139
+ appendToStack(el);
140
+ updateStats();
138
141
  });
139
142
 
140
- runner.on('test end', function(test) {
141
- // TODO: add to stats
142
- var percent = stats.tests / this.total * 100 | 0;
143
- if (progress) {
144
- progress.update(percent).draw(ctx);
143
+ runner.on('fail', function(test) {
144
+ var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
145
+ test.title, self.testURL(test));
146
+ var stackString; // Note: Includes leading newline
147
+ var message = test.err.toString();
148
+
149
+ // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
150
+ // check for the result of the stringifying.
151
+ if (message === '[object Error]') {
152
+ message = test.err.message;
145
153
  }
146
154
 
147
- // update stats
148
- var ms = new Date() - stats.start;
149
- text(passes, stats.passes);
150
- text(failures, stats.failures);
151
- text(duration, (ms / 1000).toFixed(2));
152
-
153
- // test
154
- var el;
155
- if (test.state === 'passed') {
156
- var url = self.testURL(test);
157
- el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
158
- } else if (test.isPending()) {
159
- el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
160
- } else {
161
- el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>', test.title, self.testURL(test));
162
- var stackString; // Note: Includes leading newline
163
- var message = test.err.toString();
164
-
165
- // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
166
- // check for the result of the stringifying.
167
- if (message === '[object Error]') {
168
- message = test.err.message;
169
- }
170
-
171
- if (test.err.stack) {
172
- var indexOfMessage = test.err.stack.indexOf(test.err.message);
173
- if (indexOfMessage === -1) {
174
- stackString = test.err.stack;
175
- } else {
176
- stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
177
- }
178
- } else if (test.err.sourceURL && test.err.line !== undefined) {
179
- // Safari doesn't give you a stack. Let's at least provide a source line.
180
- stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
181
- }
182
-
183
- stackString = stackString || '';
184
-
185
- if (test.err.htmlMessage && stackString) {
186
- el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>', test.err.htmlMessage, stackString));
187
- } else if (test.err.htmlMessage) {
188
- el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
155
+ if (test.err.stack) {
156
+ var indexOfMessage = test.err.stack.indexOf(test.err.message);
157
+ if (indexOfMessage === -1) {
158
+ stackString = test.err.stack;
189
159
  } else {
190
- el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
160
+ stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
191
161
  }
162
+ } else if (test.err.sourceURL && test.err.line !== undefined) {
163
+ // Safari doesn't give you a stack. Let's at least provide a source line.
164
+ stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
192
165
  }
193
166
 
194
- // toggle code
195
- // TODO: defer
196
- if (!test.isPending()) {
197
- var h2 = el.getElementsByTagName('h2')[0];
167
+ stackString = stackString || '';
198
168
 
199
- on(h2, 'click', function() {
200
- pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
201
- });
202
-
203
- var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
204
- el.appendChild(pre);
205
- pre.style.display = 'none';
169
+ if (test.err.htmlMessage && stackString) {
170
+ el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
171
+ test.err.htmlMessage, stackString));
172
+ } else if (test.err.htmlMessage) {
173
+ el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
174
+ } else {
175
+ el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
206
176
  }
207
177
 
178
+ self.addCodeToggle(el, test.body);
179
+ appendToStack(el);
180
+ updateStats();
181
+ });
182
+
183
+ runner.on('pending', function(test) {
184
+ var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
185
+ appendToStack(el);
186
+ updateStats();
187
+ });
188
+
189
+ function appendToStack(el) {
208
190
  // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
209
191
  if (stack[0]) {
210
192
  stack[0].appendChild(el);
211
193
  }
212
- });
194
+ }
195
+
196
+ function updateStats() {
197
+ // TODO: add to stats
198
+ var percent = stats.tests / this.total * 100 | 0;
199
+ if (progress) {
200
+ progress.update(percent).draw(ctx);
201
+ }
202
+
203
+ // update stats
204
+ var ms = new Date() - stats.start;
205
+ text(passes, stats.passes);
206
+ text(failures, stats.failures);
207
+ text(duration, (ms / 1000).toFixed(2));
208
+ }
213
209
  }
214
210
 
215
211
  /**
@@ -247,6 +243,24 @@ HTML.prototype.testURL = function(test) {
247
243
  return makeUrl(test.fullTitle());
248
244
  };
249
245
 
246
+ /**
247
+ * Adds code toggle functionality for the provided test's list element.
248
+ *
249
+ * @param {HTMLLIElement} el
250
+ * @param {string} contents
251
+ */
252
+ HTML.prototype.addCodeToggle = function(el, contents) {
253
+ var h2 = el.getElementsByTagName('h2')[0];
254
+
255
+ on(h2, 'click', function() {
256
+ pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
257
+ });
258
+
259
+ var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
260
+ el.appendChild(pre);
261
+ pre.style.display = 'none';
262
+ };
263
+
250
264
  /**
251
265
  * Display error `msg`.
252
266
  *
package/mocha.js CHANGED
@@ -2559,7 +2559,8 @@ function HTML(runner) {
2559
2559
  }
2560
2560
 
2561
2561
  // pass toggle
2562
- on(passesLink, 'click', function() {
2562
+ on(passesLink, 'click', function(evt) {
2563
+ evt.preventDefault();
2563
2564
  unhide();
2564
2565
  var name = (/pass/).test(report.className) ? '' : ' pass';
2565
2566
  report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -2569,7 +2570,8 @@ function HTML(runner) {
2569
2570
  });
2570
2571
 
2571
2572
  // failure toggle
2572
- on(failuresLink, 'click', function() {
2573
+ on(failuresLink, 'click', function(evt) {
2574
+ evt.preventDefault();
2573
2575
  unhide();
2574
2576
  var name = (/fail/).test(report.className) ? '' : ' fail';
2575
2577
  report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -2607,88 +2609,82 @@ function HTML(runner) {
2607
2609
  stack.shift();
2608
2610
  });
2609
2611
 
2610
- runner.on('fail', function(test) {
2611
- // For type = 'test' its possible that the test failed due to multiple
2612
- // done() calls. So report the issue here.
2613
- if (test.type === 'hook'
2614
- || test.type === 'test') {
2615
- runner.emit('test end', test);
2616
- }
2612
+ runner.on('pass', function(test) {
2613
+ var url = self.testURL(test);
2614
+ var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
2615
+ + '<a href="%s" class="replay">‣</a></h2></li>';
2616
+ var el = fragment(markup, test.speed, test.title, test.duration, url);
2617
+ self.addCodeToggle(el, test.body);
2618
+ appendToStack(el);
2619
+ updateStats();
2617
2620
  });
2618
2621
 
2619
- runner.on('test end', function(test) {
2620
- // TODO: add to stats
2621
- var percent = stats.tests / this.total * 100 | 0;
2622
- if (progress) {
2623
- progress.update(percent).draw(ctx);
2624
- }
2625
-
2626
- // update stats
2627
- var ms = new Date() - stats.start;
2628
- text(passes, stats.passes);
2629
- text(failures, stats.failures);
2630
- text(duration, (ms / 1000).toFixed(2));
2631
-
2632
- // test
2633
- var el;
2634
- if (test.state === 'passed') {
2635
- var url = self.testURL(test);
2636
- el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
2637
- } else if (test.isPending()) {
2638
- el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
2639
- } else {
2640
- el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>', test.title, self.testURL(test));
2641
- var stackString; // Note: Includes leading newline
2642
- var message = test.err.toString();
2643
-
2644
- // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
2645
- // check for the result of the stringifying.
2646
- if (message === '[object Error]') {
2647
- message = test.err.message;
2648
- }
2649
-
2650
- if (test.err.stack) {
2651
- var indexOfMessage = test.err.stack.indexOf(test.err.message);
2652
- if (indexOfMessage === -1) {
2653
- stackString = test.err.stack;
2654
- } else {
2655
- stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
2656
- }
2657
- } else if (test.err.sourceURL && test.err.line !== undefined) {
2658
- // Safari doesn't give you a stack. Let's at least provide a source line.
2659
- stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
2660
- }
2622
+ runner.on('fail', function(test) {
2623
+ var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
2624
+ test.title, self.testURL(test));
2625
+ var stackString; // Note: Includes leading newline
2626
+ var message = test.err.toString();
2661
2627
 
2662
- stackString = stackString || '';
2628
+ // <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
2629
+ // check for the result of the stringifying.
2630
+ if (message === '[object Error]') {
2631
+ message = test.err.message;
2632
+ }
2663
2633
 
2664
- if (test.err.htmlMessage && stackString) {
2665
- el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>', test.err.htmlMessage, stackString));
2666
- } else if (test.err.htmlMessage) {
2667
- el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
2634
+ if (test.err.stack) {
2635
+ var indexOfMessage = test.err.stack.indexOf(test.err.message);
2636
+ if (indexOfMessage === -1) {
2637
+ stackString = test.err.stack;
2668
2638
  } else {
2669
- el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
2639
+ stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
2670
2640
  }
2641
+ } else if (test.err.sourceURL && test.err.line !== undefined) {
2642
+ // Safari doesn't give you a stack. Let's at least provide a source line.
2643
+ stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
2671
2644
  }
2672
2645
 
2673
- // toggle code
2674
- // TODO: defer
2675
- if (!test.isPending()) {
2676
- var h2 = el.getElementsByTagName('h2')[0];
2646
+ stackString = stackString || '';
2677
2647
 
2678
- on(h2, 'click', function() {
2679
- pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
2680
- });
2681
-
2682
- var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
2683
- el.appendChild(pre);
2684
- pre.style.display = 'none';
2648
+ if (test.err.htmlMessage && stackString) {
2649
+ el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
2650
+ test.err.htmlMessage, stackString));
2651
+ } else if (test.err.htmlMessage) {
2652
+ el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
2653
+ } else {
2654
+ el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
2685
2655
  }
2686
2656
 
2657
+ self.addCodeToggle(el, test.body);
2658
+ appendToStack(el);
2659
+ updateStats();
2660
+ });
2661
+
2662
+ runner.on('pending', function(test) {
2663
+ var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
2664
+ appendToStack(el);
2665
+ updateStats();
2666
+ });
2667
+
2668
+ function appendToStack(el) {
2687
2669
  // Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
2688
2670
  if (stack[0]) {
2689
2671
  stack[0].appendChild(el);
2690
2672
  }
2691
- });
2673
+ }
2674
+
2675
+ function updateStats() {
2676
+ // TODO: add to stats
2677
+ var percent = stats.tests / this.total * 100 | 0;
2678
+ if (progress) {
2679
+ progress.update(percent).draw(ctx);
2680
+ }
2681
+
2682
+ // update stats
2683
+ var ms = new Date() - stats.start;
2684
+ text(passes, stats.passes);
2685
+ text(failures, stats.failures);
2686
+ text(duration, (ms / 1000).toFixed(2));
2687
+ }
2692
2688
  }
2693
2689
 
2694
2690
  /**
@@ -2726,6 +2722,24 @@ HTML.prototype.testURL = function(test) {
2726
2722
  return makeUrl(test.fullTitle());
2727
2723
  };
2728
2724
 
2725
+ /**
2726
+ * Adds code toggle functionality for the provided test's list element.
2727
+ *
2728
+ * @param {HTMLLIElement} el
2729
+ * @param {string} contents
2730
+ */
2731
+ HTML.prototype.addCodeToggle = function(el, contents) {
2732
+ var h2 = el.getElementsByTagName('h2')[0];
2733
+
2734
+ on(h2, 'click', function() {
2735
+ pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
2736
+ });
2737
+
2738
+ var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
2739
+ el.appendChild(pre);
2740
+ pre.style.display = 'none';
2741
+ };
2742
+
2729
2743
  /**
2730
2744
  * Display error `msg`.
2731
2745
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mocha",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "description": "simple, flexible, fun test framework",
5
5
  "keywords": [
6
6
  "mocha",