Skip to content

Commit

Permalink
Support empty buffered tests as skips
Browse files Browse the repository at this point in the history
This requires an update to the parser, which also allows removing a lot
of dead code.
  • Loading branch information
isaacs committed Dec 30, 2016
1 parent 86e82fa commit 1b2caa4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
53 changes: 23 additions & 30 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,42 +747,14 @@ function childStream (self, child, parser) {
bailOnFail(self, child, parser)
}

// The only thing that's actually *required* to be a valid TAP output
// is a plan and/or at least one ok/not-ok line. If we don't get any
// of those, then emit a bogus 1..0 so empty TAP streams read as a
// skipped test, instead of error.
var sawTests = false

parser.once('plan', function () {
sawTests = true
})

parser.once('assert', function () {
sawTests = true
})

child.on('data', function (c) {
parser.write(c)
})

child.on('end', function () {
if (!sawTests) {
parser.write('1..0\n')
}
parser.end()
})
child.pipe(parser)
}

emitter.on('bailout', function (reason) {
rootBail(self, reason)
bailedOut = true
})

emitter.on('line', function (line) {
if (bailedOut) {
return
}

if (line.match(/^TAP version \d+\n$/)) {
return
}
Expand Down Expand Up @@ -971,7 +943,24 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe

var ok = results.ok && !code && !signal
if (extra.buffered) {
self.ok(ok, name + ' {', { diagnostic: false })
if (extra.skip) {
if (typeof extra.skip === 'string') {
extra.skip += ' {'
} else {
extra.skip = ' {'
}
} else if (extra.todo) {
if (typeof extra.todo === 'string') {
extra.todo += ' {'
} else {
extra.todo = ' {'
}
} else {
name += ' {'
}
extra.diagnostic = false

self.ok(ok, name, extra)
var b = buffer.trim().split('\n').join('\n ') + '\n'
b = b.split('\n \n').join('\n\n')
b += ' ' + time + '\n'
Expand Down Expand Up @@ -1641,6 +1630,10 @@ Test.prototype.push = function (c, e) {
var lines = this._lineBuf.split('\n')
this._lineBuf = lines.pop()
lines.forEach(function (line) {
if (this._bailedOut) {
return
}

if (!line.trim())
line = ''

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"readable-stream": "^2.0.2",
"signal-exit": "^3.0.0",
"stack-utils": "^0.4.0",
"tap-mocha-reporter": "^2.0.0",
"tap-parser": "^2.2.0",
"tap-mocha-reporter": "^3.0.0",
"tap-parser": "^3.0.1",
"tmatch": "^3.0.0"
},
"keywords": [
Expand Down
9 changes: 8 additions & 1 deletion test/only-non-tap-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ if (process.argv[2] === 'child') {
} else if (process.argv[2] !== 'silent') {
var t = require('../')
var Test = t.Test
var tt = new Test({ buffered: false })

t.test('buffered', { buffered: true }, runTest)
t.test('unbuffered', { buffered: false }, runTest)
}

function runTest (t) {
t.plan(3)
var tt = new Test()

var out = ''
tt.on('data', function (c) {
Expand Down
4 changes: 2 additions & 2 deletions test/test/spawn-empty-bail-buffer.tap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TAP version 13
ok 1 - ___/.*/~~~spawn-empty.js child {

ok 1 - ___/.*/~~~spawn-empty.js child # SKIP No tests found {
1..0
___/# time=[0-9.]+(ms)?/~~~
}

Expand Down
4 changes: 2 additions & 2 deletions test/test/spawn-empty-buffer.tap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TAP version 13
ok 1 - ___/.*/~~~spawn-empty.js child {

ok 1 - ___/.*/~~~spawn-empty.js child # SKIP No tests found {
1..0
___/# time=[0-9.]+(ms)?/~~~
}

Expand Down

0 comments on commit 1b2caa4

Please sign in to comment.