Skip to content

Commit

Permalink
[New] 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 authored and ljharb committed Oct 2, 2015
1 parent a1e8f7e commit 022c26c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Results () {
this.count = 0;
this.fail = 0;
this.pass = 0;
this.skip = 0;
this._stream = through();
this.tests = [];
this._only = null;
Expand Down Expand Up @@ -103,7 +104,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 ++;
self.emit('fail');
Expand All @@ -121,6 +123,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 @@ -131,11 +134,11 @@ 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();
});
});
15 changes: 15 additions & 0 deletions test/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,33 @@ tap.test('test SKIP comment', function (assert) {
});
});

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++;
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++;
t.test('skip this', { skip: true }, function(t) {
Expand Down

0 comments on commit 022c26c

Please sign in to comment.