Skip to content

Commit

Permalink
Report skipped assertions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidmason committed Oct 2, 2015
1 parent 0dc9313 commit 6d9ee1e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Results () {
this.count = 0;
this.fail = 0;
this.pass = 0;
this.skip = 0;
this._stream = through();
this.tests = [];
}
Expand Down Expand Up @@ -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 ++
});

Expand All @@ -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')
Expand All @@ -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;

Expand Down
54 changes: 54 additions & 0 deletions test/skip-output.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
14 changes: 13 additions & 1 deletion test/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++;
Expand Down

0 comments on commit 6d9ee1e

Please sign in to comment.