diff --git a/lib/reporter/tap.js b/lib/reporter/tap.js index b424cd7bb..f21781f72 100644 --- a/lib/reporter/tap.js +++ b/lib/reporter/tap.js @@ -12,7 +12,11 @@ function generateTest(mod, count) { mod.error = mod.error.message; } var error = mod.error ? [directive, mod.error].join(' ') : ''; - var output = mod.testOutput ? '\n' + util.sanitizeOutput(mod.testOutput, '# ') : ''; + if (mod.testOutput && mod.testOutput.length > 0) { + var output = '\n ---\n' + util.sanitizeOutput(mod.testOutput, ' #') + '\n ...'; + } else { + output = ''; + } return [result, count + 1, '-', mod.name, 'v' + mod.version + error + output].join(' '); } diff --git a/package.json b/package.json index e35fc78d2..9ef9928b8 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,8 @@ "nyc": "^8.4.0", "opener": "^1.4.1", "rewire": "^2.4.0", - "tap": "^8.0.0" + "tap": "^8.0.0", + "tap-parser": "^3.0.3", + "string-to-stream": "^1.1.0" } } diff --git a/test/fixtures/tap-parser.txt b/test/fixtures/tap-parser.txt new file mode 100644 index 000000000..c17d71b5e --- /dev/null +++ b/test/fixtures/tap-parser.txt @@ -0,0 +1,18 @@ +{ + "ok": false, + "count": 3, + "pass": 2, + "fail": 1, + "skip": 1, + "plan": { + "start": 1, + "end": 3 + }, + "failures": [ + { + "ok": false, + "id": 3, + "name": "iFail v3.0.1 I dun wurk" + } + ] +} diff --git a/test/fixtures/test-out-tap-failing.txt b/test/fixtures/test-out-tap-failing.txt index ba50f1a0f..43e93cfb0 100644 --- a/test/fixtures/test-out-tap-failing.txt +++ b/test/fixtures/test-out-tap-failing.txt @@ -1,7 +1,11 @@ TAP version 13 ok 1 - iPass v4.2.2 ok 2 - iFlakyFail v3.3.3 # SKIP I dun wurk -# Thanks for testing! + --- + # Thanks for testing! + ... not ok 3 - iFail v3.0.1 I dun wurk -# Thanks for testing! + --- + # Thanks for testing! + ... 1..3 diff --git a/test/fixtures/test-out-tap-passing-append.txt b/test/fixtures/test-out-tap-passing-append.txt index 407e0fdb3..591de7e9c 100644 --- a/test/fixtures/test-out-tap-passing-append.txt +++ b/test/fixtures/test-out-tap-passing-append.txt @@ -2,5 +2,7 @@ This is a test! TAP version 13 ok 1 - iPass v4.2.2 ok 2 - iFlakyPass v3.0.1 -# Thanks for testing! + --- + # Thanks for testing! + ... 1..2 diff --git a/test/fixtures/test-out-tap-passing.txt b/test/fixtures/test-out-tap-passing.txt index c77f22378..22e710bd0 100644 --- a/test/fixtures/test-out-tap-passing.txt +++ b/test/fixtures/test-out-tap-passing.txt @@ -1,5 +1,7 @@ TAP version 13 ok 1 - iPass v4.2.2 ok 2 - iFlakyPass v3.0.1 -# Thanks for testing! + --- + # Thanks for testing! + ... 1..2 diff --git a/test/reporter/test-reporter-tap.js b/test/reporter/test-reporter-tap.js index 6f680465c..8ebb62bed 100644 --- a/test/reporter/test-reporter-tap.js +++ b/test/reporter/test-reporter-tap.js @@ -7,6 +7,8 @@ var os = require('os'); var test = require('tap').test; var mkdirp = require('mkdirp'); var rimraf = require('rimraf'); +var parser = require('tap-parser'); +var str = require('string-to-stream'); var tap = require('../../lib/reporter/tap'); var fixtures = require('../fixtures/reporter-fixtures'); @@ -24,9 +26,11 @@ var passingInput = [ fixtures.iFlakyPass ]; +var tapParser = path.join(fixturesPath, 'tap-parser.txt'); var passingExpectedPath = path.join(fixturesPath, 'test-out-tap-passing.txt'); var passingExpectedPathAppend = path.join(fixturesPath, 'test-out-tap-passing-append.txt'); +var tapParserExpected = fs.readFileSync(tapParser, 'utf-8'); var passingExpected = fs.readFileSync(passingExpectedPath, 'utf-8'); var passingExpectedAppend = fs.readFileSync(passingExpectedPathAppend, 'utf-8'); @@ -70,6 +74,21 @@ test('reporter.tap(): failing', function (t) { t.end(); }); +test('reporter.tap(): parser', function (t) { + var output = ''; + function logger(message) { + output += message; + } + + tap(logger, failingInput); + var p = parser(function (results) { + var expected = JSON.stringify(results, null, 2) + '\n'; + t.equals(expected, tapParserExpected), 'the tap parser should correctly parse the tap file'; + t.end(); + }); + str(output).pipe(p); +}); + test('reporter.tap(): write to disk', function (t) { tap(outputFile, passingInput); var expected = fs.readFileSync(outputFile, 'utf8');