Skip to content

Commit 4cab9d5

Browse files
committed
Add test running time
1 parent 5aa8653 commit 4cab9d5

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

example/clip.gif

255 KB
Loading

example/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('callback support', function(t, cb) {
8585
})
8686
})
8787

88-
test('check `https://github.com/zoubin/task-tape` for more information', function(t) {
88+
test('check `task-tape` for more information', function(t) {
8989
t.task(function (cb) {
9090
next(function () {
9191
t.equal(

index.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ var duplexer = require('duplexer2')
33
var parser = require('tap-out')
44
var format = require('ansi-escape')
55
var symbols = require('figures')
6+
var prettyMs = require('pretty-ms')
67
var LF = '\n'
78

89
module.exports = function () {
910
var tap = parser()
1011
var output = through()
1112
var test
1213

14+
var duration = 0
1315
output.push(LF + splitter(' Tests '))
1416
tap.on('test', function (res) {
1517
update()
@@ -18,8 +20,14 @@ module.exports = function () {
1820
pass: 0,
1921
fail: 0,
2022
get title() {
21-
return this.name + ' [pass: ' + this.pass + ', fail: ' + this.fail + ']'
23+
return this.name +
24+
' [' +
25+
'pass: ' + this.pass +
26+
', fail: ' + this.fail +
27+
(test.end ? ', duration: ' + prettyMs(test.duration) : '') +
28+
']'
2229
},
30+
start: new Date(),
2331
}
2432
output.push(LF + format.cha.eraseLine.escape('# ' + test.title))
2533
})
@@ -36,7 +44,7 @@ module.exports = function () {
3644

3745
tap.on('output', function (res) {
3846
update()
39-
output.push(formatSummary(res))
47+
output.push(formatSummary(res, { duration: duration }))
4048
if (res.fail.length) {
4149
dup.failed = true
4250
output.push(formatFail(res))
@@ -50,6 +58,9 @@ module.exports = function () {
5058

5159
function update() {
5260
if (test) {
61+
test.end = new Date()
62+
test.duration = test.end - test.start
63+
duration += test.duration
5364
if (test.fail) {
5465
output.push(format.cha.red.eraseLine.escape(symbols.cross + ' ' + test.title))
5566
} else {
@@ -62,9 +73,10 @@ module.exports = function () {
6273
return dup
6374
}
6475

65-
function formatSummary(res) {
76+
function formatSummary(res, extra) {
6677
var output = [LF]
6778
output.push(splitter(' Summary '))
79+
output.push(format.cyan.escape('duration: ' + prettyMs(extra.duration)))
6880
output.push(format.cyan.escape('assertions: ' + res.asserts.length))
6981
if (res.pass.length) {
7082
output.push(format.green.escape('pass: ' + res.pass.length))

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"ansi-escape": "^1.0.1",
2929
"duplexer2": "^0.1.4",
3030
"figures": "^1.4.0",
31+
"pretty-ms": "^2.1.0",
3132
"tap-out": "^1.4.1",
3233
"through2": "^2.0.0"
3334
},

0 commit comments

Comments
 (0)