Skip to content
This repository

Displaying the number of pending specs #370

Merged
merged 2 commits into from about 2 years ago

2 participants

Attila Domokos TJ Holowaychuk
Attila Domokos

I am displaying the number of pending specs at the end of the reporter output.

I also modified the way we print the summary. It now will say 1 test complete instead of 1 tests complete.

This is what you're getting with this pull request:
# of pending tests

TJ Holowaychuk
Owner

cool looks good :D we must have an issue this can close, I think a few people requested it, I'll comment in the diff

lib/reporters/base.js
@@ -237,6 +237,11 @@ function Base(runner) {
237 237
     stats.end = new Date;
238 238
     stats.duration = new Date - stats.start;
239 239
   });
  240
+
  241
+  runner.on('pending', function(){
  242
+    stats.pendings = stats.pendings || 0;
1
TJ Holowaychuk Owner

we shouldn't need this line since it's defined above. I'd probably just called it stats.pending for plural

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/reporters/base.js
((7 lines not shown))
252 258
 
253 259
   console.log();
254 260
 
  261
+  var pluralizeTest = function(numberOfTests) {
  262
+    if (numberOfTests === 1) {
  263
+      return "test";
  264
+    }
  265
+    else {
  266
+      return "tests";
  267
+    }
  268
+  }
  269
+
1
TJ Holowaychuk Owner

style nitpick, maybe just:

function pluralize(n){
  return 1 == n ? 'test' : 'tests';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/reporters/base.js
((6 lines not shown))
270 288
     + color('light', ' (%dms)');
271 289
 
272  
-  console.log(fmt, stats.tests || 0, stats.duration);
  290
+  console.log(fmt,
  291
+              stats.tests || 0,
  292
+              pluralizeTest(stats.tests),
  293
+              stats.duration);
  294
+
  295
+  // pending
  296
+  if (stats.pendings > 0) {
  297
+    fmt = color('pending', '  *')
1
TJ Holowaychuk Owner

let's use • instead of *
just because unicode is hawt, or one of the other circular glyphs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/reporters/base.js
((6 lines not shown))
270 288
     + color('light', ' (%dms)');
271 289
 
272  
-  console.log(fmt, stats.tests || 0, stats.duration);
  290
+  console.log(fmt,
  291
+              stats.tests || 0,
  292
+              pluralizeTest(stats.tests),
  293
+              stats.duration);
  294
+
  295
+  // pending
  296
+  if (stats.pendings > 0) {
1
TJ Holowaychuk Owner

if (stats.pending) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Attila Domokos

I think issue 340 can be closed when this is closed.

Attila Domokos

Can this pull request be merged into master and closed? Is there anything else I should change there?

TJ Holowaychuk visionmedia merged commit f3eeab1 into from
TJ Holowaychuk visionmedia closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 32 additions and 6 deletions. Show diff stats Hide diff stats

  1. 38  lib/reporters/base.js
38  lib/reporters/base.js
@@ -193,7 +193,7 @@ exports.list = function(failures){
193 193
 
194 194
 function Base(runner) {
195 195
   var self = this
196  
-    , stats = this.stats = { suites: 0, tests: 0, passes: 0, failures: 0 }
  196
+    , stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
197 197
     , failures = this.failures = [];
198 198
 
199 199
   if (!runner) return;
@@ -237,6 +237,10 @@ function Base(runner) {
237 237
     stats.end = new Date;
238 238
     stats.duration = new Date - stats.start;
239 239
   });
  240
+
  241
+  runner.on('pending', function(){
  242
+    stats.pending++;
  243
+  });
240 244
 }
241 245
 
242 246
 /**
@@ -248,17 +252,25 @@ function Base(runner) {
248 252
 
249 253
 Base.prototype.epilogue = function(){
250 254
   var stats = this.stats
251  
-    , fmt;
  255
+    , fmt
  256
+    , tests;
252 257
 
253 258
   console.log();
254 259
 
  260
+  var pluralizeTest = function(n) {
  261
+    return 1 == n ? 'test' : 'tests';
  262
+  }
  263
+
255 264
   // failure
256 265
   if (stats.failures) {
257 266
     fmt = color('bright fail', '  ✖')
258  
-      + color('fail', ' %d of %d tests failed')
  267
+      + color('fail', ' %d of %d %s failed')
259 268
       + color('light', ':')
260 269
 
261  
-    console.error(fmt, stats.failures, this.runner.total);
  270
+    console.error(fmt,
  271
+                  stats.failures,
  272
+                  this.runner.total,
  273
+                  pluralizeTest(this.runner.total));
262 274
     Base.list(this.failures);
263 275
     console.error();
264 276
     return;
@@ -266,10 +278,24 @@ Base.prototype.epilogue = function(){
266 278
 
267 279
   // pass
268 280
   fmt = color('bright pass', '  ✔')
269  
-    + color('green', ' %d tests complete')
  281
+    + color('green', ' %d %s complete')
270 282
     + color('light', ' (%dms)');
271 283
 
272  
-  console.log(fmt, stats.tests || 0, stats.duration);
  284
+  console.log(fmt,
  285
+              stats.tests || 0,
  286
+              pluralizeTest(stats.tests),
  287
+              stats.duration);
  288
+
  289
+  // pending
  290
+  if (stats.pending) {
  291
+    fmt = color('pending', '  •')
  292
+      + color('pending', ' %d %s pending');
  293
+
  294
+    console.log(fmt,
  295
+                stats.pending,
  296
+                pluralizeTest(stats.pending));
  297
+  }
  298
+
273 299
   console.log();
274 300
 };
275 301
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.