Skip to content

Commit 1b2caa4

Browse files
committed
Support empty buffered tests as skips
This requires an update to the parser, which also allows removing a lot of dead code.
1 parent 86e82fa commit 1b2caa4

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

lib/test.js

+23-30
Original file line numberDiff line numberDiff line change
@@ -747,42 +747,14 @@ function childStream (self, child, parser) {
747747
bailOnFail(self, child, parser)
748748
}
749749

750-
// The only thing that's actually *required* to be a valid TAP output
751-
// is a plan and/or at least one ok/not-ok line. If we don't get any
752-
// of those, then emit a bogus 1..0 so empty TAP streams read as a
753-
// skipped test, instead of error.
754-
var sawTests = false
755-
756-
parser.once('plan', function () {
757-
sawTests = true
758-
})
759-
760-
parser.once('assert', function () {
761-
sawTests = true
762-
})
763-
764-
child.on('data', function (c) {
765-
parser.write(c)
766-
})
767-
768-
child.on('end', function () {
769-
if (!sawTests) {
770-
parser.write('1..0\n')
771-
}
772-
parser.end()
773-
})
750+
child.pipe(parser)
774751
}
775752

776753
emitter.on('bailout', function (reason) {
777754
rootBail(self, reason)
778-
bailedOut = true
779755
})
780756

781757
emitter.on('line', function (line) {
782-
if (bailedOut) {
783-
return
784-
}
785-
786758
if (line.match(/^TAP version \d+\n$/)) {
787759
return
788760
}
@@ -971,7 +943,24 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
971943

972944
var ok = results.ok && !code && !signal
973945
if (extra.buffered) {
974-
self.ok(ok, name + ' {', { diagnostic: false })
946+
if (extra.skip) {
947+
if (typeof extra.skip === 'string') {
948+
extra.skip += ' {'
949+
} else {
950+
extra.skip = ' {'
951+
}
952+
} else if (extra.todo) {
953+
if (typeof extra.todo === 'string') {
954+
extra.todo += ' {'
955+
} else {
956+
extra.todo = ' {'
957+
}
958+
} else {
959+
name += ' {'
960+
}
961+
extra.diagnostic = false
962+
963+
self.ok(ok, name, extra)
975964
var b = buffer.trim().split('\n').join('\n ') + '\n'
976965
b = b.split('\n \n').join('\n\n')
977966
b += ' ' + time + '\n'
@@ -1641,6 +1630,10 @@ Test.prototype.push = function (c, e) {
16411630
var lines = this._lineBuf.split('\n')
16421631
this._lineBuf = lines.pop()
16431632
lines.forEach(function (line) {
1633+
if (this._bailedOut) {
1634+
return
1635+
}
1636+
16441637
if (!line.trim())
16451638
line = ''
16461639

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"readable-stream": "^2.0.2",
2929
"signal-exit": "^3.0.0",
3030
"stack-utils": "^0.4.0",
31-
"tap-mocha-reporter": "^2.0.0",
32-
"tap-parser": "^2.2.0",
31+
"tap-mocha-reporter": "^3.0.0",
32+
"tap-parser": "^3.0.1",
3333
"tmatch": "^3.0.0"
3434
},
3535
"keywords": [

test/only-non-tap-output.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ if (process.argv[2] === 'child') {
33
} else if (process.argv[2] !== 'silent') {
44
var t = require('../')
55
var Test = t.Test
6-
var tt = new Test({ buffered: false })
6+
7+
t.test('buffered', { buffered: true }, runTest)
8+
t.test('unbuffered', { buffered: false }, runTest)
9+
}
10+
11+
function runTest (t) {
12+
t.plan(3)
13+
var tt = new Test()
714

815
var out = ''
916
tt.on('data', function (c) {

test/test/spawn-empty-bail-buffer.tap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TAP version 13
2-
ok 1 - ___/.*/~~~spawn-empty.js child {
3-
2+
ok 1 - ___/.*/~~~spawn-empty.js child # SKIP No tests found {
3+
1..0
44
___/# time=[0-9.]+(ms)?/~~~
55
}
66

test/test/spawn-empty-buffer.tap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TAP version 13
2-
ok 1 - ___/.*/~~~spawn-empty.js child {
3-
2+
ok 1 - ___/.*/~~~spawn-empty.js child # SKIP No tests found {
3+
1..0
44
___/# time=[0-9.]+(ms)?/~~~
55
}
66

0 commit comments

Comments
 (0)