From 6d9ee1e5f559c8712bbebb4fefa51dec17b2b21d Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 2 Oct 2015 20:54:43 +1000 Subject: [PATCH] Report skipped assertions The standard indicates that skipped assertions should be summarized at the end of output, and the specified place for # SKIP and # TODO is before the message. --- lib/results.js | 9 ++++---- test/skip-output.js | 54 +++++++++++++++++++++++++++++++++++++++++++++ test/skip.js | 14 +++++++++++- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 test/skip-output.js diff --git a/lib/results.js b/lib/results.js index 9a494094..c87c1854 100644 --- a/lib/results.js +++ b/lib/results.js @@ -20,6 +20,7 @@ function Results () { this.count = 0; this.fail = 0; this.pass = 0; + this.skip = 0; this._stream = through(); this.tests = []; } @@ -107,7 +108,8 @@ Results.prototype._watch = function (t) { write(encodeResult(res, self.count + 1)); self.count ++; - if (res.ok) self.pass ++ + if (res.skip) self.skip ++ + else if (res.ok) self.pass ++ else self.fail ++ }); @@ -122,6 +124,7 @@ Results.prototype.close = function () { write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); + if (self.skip) write('# skip ' + self.skip + '\n'); write('# pass ' + self.pass + '\n'); if (self.fail) write('# fail ' + self.fail + '\n') else write('\n# ok\n') @@ -132,11 +135,9 @@ Results.prototype.close = function () { function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; - output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; - if (res.skip) output += ' # SKIP'; else if (res.todo) output += ' # TODO'; - + output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; output += '\n'; if (res.ok) return output; diff --git a/test/skip-output.js b/test/skip-output.js new file mode 100644 index 00000000..186c00c4 --- /dev/null +++ b/test/skip-output.js @@ -0,0 +1,54 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +tap.test('skip output test', function (tt) { + tt.plan(1); + + var test = tape.createHarness({ exit : false }); + test.createStream().pipe(concat(function (body) { + tt.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# skip assertions\n' + + 'ok 1 # SKIP not enough pylons\n' + + '# skip subtests\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# skip 1\n' + + '# pass 0\n' + + '\n' + + '# ok\n' + ); + })); + + // doesn't look like test.skip is available with createHarness() + // test.skip('we require more minerals', function (t) { + // t.plan(1); + // t.fail('should not fail test.skip()'); + // }); + + test('we require more vespene gas', { skip: true }, function (t) { + t.plan(1); + t.fail('should not fail test with { skip: true}'); + }); + + test('skip assertions', function (t) { + t.plan(1); + t.skip('not enough pylons'); + }); + + test('skip subtests', function (t) { + // doesn't look like test.skip is available with createHarness() + // test.skip('build more farms', function (t) { + // t.plan(1) + // t.fail('should not run subtest with test.skip()'); + // }); + test('we require more ziggurats', { skip: true }, function (t) { + t.plan(1) + t.fail('should not run subtest with { skip: true }'); + }); + t.end(); + }); +}); diff --git a/test/skip.js b/test/skip.js index 7b23126c..38e0e973 100644 --- a/test/skip.js +++ b/test/skip.js @@ -6,18 +6,30 @@ test('do not skip this', { skip: false }, function(t) { ran ++; t.end(); }); +test('does not skip with { skip: false }', function(t) { + t.equal(ran, 1, 'should have run the previous test'); + t.end(); +}) test('skip this', { skip: true }, function(t) { t.fail('this should not even run'); - ran++; + ran ++; t.end(); }); +test('does skip with { skip: true }', function(t) { + t.equal(ran, 1, 'should not have run the previous test'); + t.end(); +}) test.skip('skip this too', function(t) { t.fail('this should not even run'); ran++; t.end(); }); +test('does skip with test.skip', function(t) { + t.equal(ran, 1, 'should not have run the previous test'); + t.end(); +}) test('skip subtest', function(t) { ran ++;