Skip to content

Commit 6d9ee1e

Browse files
committed
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 0dc9313 commit 6d9ee1e

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

lib/results.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Results () {
2020
this.count = 0;
2121
this.fail = 0;
2222
this.pass = 0;
23+
this.skip = 0;
2324
this._stream = through();
2425
this.tests = [];
2526
}
@@ -107,7 +108,8 @@ Results.prototype._watch = function (t) {
107108
write(encodeResult(res, self.count + 1));
108109
self.count ++;
109110

110-
if (res.ok) self.pass ++
111+
if (res.skip) self.skip ++
112+
else if (res.ok) self.pass ++
111113
else self.fail ++
112114
});
113115

@@ -122,6 +124,7 @@ Results.prototype.close = function () {
122124

123125
write('\n1..' + self.count + '\n');
124126
write('# tests ' + self.count + '\n');
127+
if (self.skip) write('# skip ' + self.skip + '\n');
125128
write('# pass ' + self.pass + '\n');
126129
if (self.fail) write('# fail ' + self.fail + '\n')
127130
else write('\n# ok\n')
@@ -132,11 +135,9 @@ Results.prototype.close = function () {
132135
function encodeResult (res, count) {
133136
var output = '';
134137
output += (res.ok ? 'ok ' : 'not ok ') + count;
135-
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
136-
137138
if (res.skip) output += ' # SKIP';
138139
else if (res.todo) output += ' # TODO';
139-
140+
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
140141
output += '\n';
141142
if (res.ok) return output;
142143

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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ test('do not skip this', { skip: false }, function(t) {
66
ran ++;
77
t.end();
88
});
9+
test('does not skip with { skip: false }', function(t) {
10+
t.equal(ran, 1, 'should have run the previous test');
11+
t.end();
12+
})
913

1014
test('skip this', { skip: true }, function(t) {
1115
t.fail('this should not even run');
12-
ran++;
16+
ran ++;
1317
t.end();
1418
});
19+
test('does skip with { skip: true }', function(t) {
20+
t.equal(ran, 1, 'should not have run the previous test');
21+
t.end();
22+
})
1523

1624
test.skip('skip this too', function(t) {
1725
t.fail('this should not even run');
1826
ran++;
1927
t.end();
2028
});
29+
test('does skip with test.skip', function(t) {
30+
t.equal(ran, 1, 'should not have run the previous test');
31+
t.end();
32+
})
2133

2234
test('skip subtest', function(t) {
2335
ran ++;

0 commit comments

Comments
 (0)