Skip to content

Commit 022c26c

Browse files
davidmasonljharb
authored andcommitted
[New] 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.
1 parent a1e8f7e commit 022c26c

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

lib/results.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function Results () {
2121
this.count = 0;
2222
this.fail = 0;
2323
this.pass = 0;
24+
this.skip = 0;
2425
this._stream = through();
2526
this.tests = [];
2627
this._only = null;
@@ -103,7 +104,8 @@ Results.prototype._watch = function (t) {
103104
write(encodeResult(res, self.count + 1));
104105
self.count ++;
105106

106-
if (res.ok) self.pass ++
107+
if (res.skip) self.skip ++
108+
else if (res.ok) self.pass ++
107109
else {
108110
self.fail ++;
109111
self.emit('fail');
@@ -121,6 +123,7 @@ Results.prototype.close = function () {
121123

122124
write('\n1..' + self.count + '\n');
123125
write('# tests ' + self.count + '\n');
126+
if (self.skip) write('# skip ' + self.skip + '\n');
124127
write('# pass ' + self.pass + '\n');
125128
if (self.fail) write('# fail ' + self.fail + '\n')
126129
else write('\n# ok\n')
@@ -131,11 +134,11 @@ Results.prototype.close = function () {
131134
function encodeResult (res, count) {
132135
var output = '';
133136
output += (res.ok ? 'ok ' : 'not ok ') + count;
134-
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
135137

136138
if (res.skip) output += ' # SKIP';
137139
else if (res.todo) output += ' # TODO';
138140

141+
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
139142
output += '\n';
140143
if (res.ok) return output;
141144

test/skip-output.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var tape = require('../');
2+
var tap = require('tap');
3+
var concat = require('concat-stream');
4+
5+
tap.test('skip output test', function (tt) {
6+
tt.plan(1);
7+
8+
var test = tape.createHarness({ exit : false });
9+
test.createStream().pipe(concat(function (body) {
10+
tt.equal(
11+
body.toString('utf8'),
12+
'TAP version 13\n'
13+
+ '# skip assertions\n'
14+
+ 'ok 1 # SKIP not enough pylons\n'
15+
+ '# skip subtests\n'
16+
+ '\n'
17+
+ '1..1\n'
18+
+ '# tests 1\n'
19+
+ '# skip 1\n'
20+
+ '# pass 0\n'
21+
+ '\n'
22+
+ '# ok\n'
23+
);
24+
}));
25+
26+
// doesn't look like test.skip is available with createHarness()
27+
// test.skip('we require more minerals', function (t) {
28+
// t.plan(1);
29+
// t.fail('should not fail test.skip()');
30+
// });
31+
32+
test('we require more vespene gas', { skip: true }, function (t) {
33+
t.plan(1);
34+
t.fail('should not fail test with { skip: true}');
35+
});
36+
37+
test('skip assertions', function (t) {
38+
t.plan(1);
39+
t.skip('not enough pylons');
40+
});
41+
42+
test('skip subtests', function (t) {
43+
// doesn't look like test.skip is available with createHarness()
44+
// test.skip('build more farms', function (t) {
45+
// t.plan(1)
46+
// t.fail('should not run subtest with test.skip()');
47+
// });
48+
test('we require more ziggurats', { skip: true }, function (t) {
49+
t.plan(1)
50+
t.fail('should not run subtest with { skip: true }');
51+
});
52+
t.end();
53+
});
54+
});

test/skip.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,33 @@ tap.test('test SKIP comment', function (assert) {
2828
});
2929
});
3030

31+
test('does not skip with { skip: false }', function(t) {
32+
t.equal(ran, 1, 'should have run the previous test');
33+
t.end();
34+
})
35+
3136
test('skip this', { skip: true }, function(t) {
3237
t.fail('this should not even run');
3338
ran++;
3439
t.end();
3540
});
3641

42+
test('does skip with { skip: true }', function(t) {
43+
t.equal(ran, 1, 'should not have run the previous test');
44+
t.end();
45+
})
46+
3747
test.skip('skip this too', function(t) {
3848
t.fail('this should not even run');
3949
ran++;
4050
t.end();
4151
});
4252

53+
test('does skip with test.skip', function(t) {
54+
t.equal(ran, 1, 'should not have run the previous test');
55+
t.end();
56+
})
57+
4358
test('skip subtest', function(t) {
4459
ran++;
4560
t.test('skip this', { skip: true }, function(t) {

0 commit comments

Comments
 (0)