Skip to content

Commit 6e58096

Browse files
committed
Add plans to summary, counts unfinished plans as fails
1 parent f431390 commit 6e58096

File tree

5 files changed

+106
-8
lines changed

5 files changed

+106
-8
lines changed

example/run-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
var exec = require('child_process').exec
22

3-
var tapeCmd = require.resolve('../node_modules/task-tape/bin/task-tape')
3+
var tapeCmd = require.resolve('../node_modules/.bin/tape')
44
var tapCmd = require.resolve('../bin/cmd')
55
var tests = require.resolve('./test')
6-
var extra = '--no-ansi --no-progress --markdown'
6+
var extra = ''
77

88
exec([tapeCmd, tests, '|', tapCmd, extra].join(' ')).stdout.pipe(process.stdout)

example/test-error.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// https://gist.github.com/Hypercubed/f0e4514bc9aec5cc5c9e814bbc1dab2d
2+
// f431390d24fa067fb262d4ea03de3d77911b95bf
3+
var test = require('tape')
4+
var math = require('./math')
5+
6+
test('t.plan', function(t) {
7+
t.plan(3)
8+
9+
t.equal(
10+
math.toFixed(2.385, 2),
11+
'2.39'
12+
)
13+
next(function () {
14+
t.equal(
15+
math.toFixed(2.384, 2),
16+
'2.38'
17+
)
18+
t.whatIsThisFunction(); // causes an uncaught error
19+
t.equal(
20+
math.toFixed(2, 2),
21+
'2.00'
22+
)
23+
})
24+
})
25+
26+
function next(fn) {
27+
setTimeout(function() {
28+
fn()
29+
}, 100)
30+
}

example/test-pass.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var test = require('tape')
2+
var math = require('./math')
3+
4+
test('t.plan', function(t) {
5+
t.plan(3)
6+
7+
t.equal(
8+
math.toFixed(2.385, 2),
9+
'2.39'
10+
)
11+
next(function () {
12+
t.equal(
13+
math.toFixed(2.384, 2),
14+
'2.38'
15+
)
16+
t.equal(
17+
math.toFixed(2, 2),
18+
'2.00'
19+
)
20+
})
21+
})
22+
23+
test('t.end', function(t) {
24+
t.equal(
25+
math.precision(0),
26+
0
27+
)
28+
t.equal(
29+
math.precision(0.1),
30+
1
31+
)
32+
var plan = 10
33+
;(function NEXT() {
34+
next(function () {
35+
t.equal(
36+
math.precision(0.1),
37+
1
38+
)
39+
plan--
40+
if (plan) {
41+
NEXT()
42+
} else {
43+
console.log('DONE')
44+
t.end()
45+
}
46+
})
47+
})()
48+
})
49+
50+
function next(fn) {
51+
setTimeout(function() {
52+
fn()
53+
}, 100)
54+
}

lib/summarize.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,27 @@ module.exports = function () {
4444
tap.on('output', function (res) {
4545
handleTestEnd()
4646

47-
if (res.fail.length) {
48-
dup.failed = true
47+
var planned = res.plans.reduce(function (p, c) {
48+
return c.to - c.from + 1 + p;
49+
}, 0)
50+
51+
var failed = res.fail.length
52+
var asserts = res.asserts.length
53+
54+
if (planned > asserts) {
55+
failed += planned - asserts
4956
}
5057

51-
if (res.plans.length < 1) {
58+
if (failed || planned === 0 || planned < asserts) {
5259
dup.failed = true
53-
process.exit(1)
5460
}
5561

5662
dup.emit('summary', {
5763
duration: duration,
64+
planned: planned,
5865
assertions: res.asserts.length,
5966
pass: res.pass.length,
60-
fail: res.fail.length,
67+
fail: failed,
6168
comments: res.comments.length,
6269
}, res.fail.reduce(function (o, assertion) {
6370
var name = getTest(assertion.test, res.tests).name

lib/summary.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ module.exports = function (opts) {
7575
var output = [LF]
7676
output.push(splitter(' Summary '))
7777
output.push(format.cyan.escape(LIST + 'duration: ' + prettyMs(res.duration)))
78+
if (res.planned < 1) {
79+
output.push(format.red.escape(LIST + 'planned: NA (plans must appear once in output)'))
80+
} else if (res.assertions !== res.planned) {
81+
output.push(format.red.escape(LIST + 'planned: ' + res.planned + " (plans don't match final assertions)"))
82+
} else {
83+
output.push(format.cyan.escape(LIST + 'planned: ' + res.planned))
84+
}
7885
output.push(format.cyan.escape(LIST + 'assertions: ' + res.assertions))
7986
if (res.pass) {
8087
output.push(format.green.escape(LIST + 'pass: ' + res.pass))
@@ -103,7 +110,7 @@ module.exports = function (opts) {
103110
var max = 80
104111
var left = max - len >> 1
105112
return format.yellow.escape(
106-
repeat('-', left) + (s || '') + repeat('-', max - len - left)
113+
repeat('-', left) + (s || '') + repeat('-', max - len - left) + LF
107114
)
108115
}
109116

0 commit comments

Comments
 (0)