Skip to content

Commit 9476825

Browse files
committed
cmd,tap: make tap readable stream and pipe to stdout and file if outfile
Semver: major
1 parent 2f0c461 commit 9476825

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

bin/cmd.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ if (parsed.list) {
9696
}
9797

9898
if (parsed.tap) {
99-
const stream = parsed.out
100-
? fs.createWriteStream(parsed.out)
101-
: process.stdout
102-
103-
const tap = new Tap(stream)
104-
var isEnding = false
99+
const tap = new Tap()
100+
tap.pipe(process.stdout)
101+
if (parsed.out) tap.pipe(fs.createWriteStream(parsed.out))
102+
var count = 0
103+
var total = args.length
105104

106105
v.on('commit', (c) => {
106+
count++
107107
const test = tap.test(c.commit.sha)
108108
formatTap(test, c.commit, c.messages, v)
109-
if (isEnding) {
109+
if (count === total) {
110110
setImmediate(() => {
111111
tap.end()
112112
if (tap.status === 'fail')
@@ -116,10 +116,7 @@ if (parsed.tap) {
116116
})
117117

118118
function run() {
119-
if (!args.length) {
120-
isEnding = true
121-
return
122-
}
119+
if (!args.length) return
123120
const sha = args.shift()
124121
load(sha, (err, data) => {
125122
if (err) throw err

lib/tap.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ class Test {
4949
}
5050
}
5151

52-
module.exports = class Tap {
53-
constructor(stream) {
54-
this.stream = stream
52+
const Readable = require('stream').Readable
53+
54+
module.exports = class Tap extends Readable {
55+
constructor() {
56+
super()
5557
this._wroteVersion = false
5658
this._count = 0
5759
this._passes = 0
@@ -90,14 +92,16 @@ module.exports = class Tap {
9092
}
9193

9294
write(str = '') {
93-
this.stream.write(`${str}\n`)
95+
this.push(`${str}\n`)
9496
}
9597

9698
test(name) {
9799
const t = new Test(this, name)
98100
return t
99101
}
100102

103+
_read() {}
104+
101105
end() {
102106
this.write()
103107
this.write(`0..${this._count}`)
@@ -109,5 +113,7 @@ module.exports = class Tap {
109113
if (this._failures) {
110114
this.write(`# fail ${this._failures}`)
111115
}
116+
117+
this.push(null)
112118
}
113119
}

0 commit comments

Comments
 (0)