Skip to content

Commit

Permalink
reporter: update to use TAP 13
Browse files Browse the repository at this point in the history
Use yamlish instead of # to match community:
nodejs/node#9262
  • Loading branch information
George Adams authored and Myles Borins committed Nov 24, 2016
1 parent 0eb9d35 commit 807ad62
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
5 changes: 4 additions & 1 deletion lib/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ function generateTest(mod, count) {
if (mod.error && mod.error.message) {
mod.error = mod.error.message;
}
var output = '';
var error = mod.error ? [directive, mod.error].join(' ') : '';
var output = mod.testOutput ? '\n' + util.sanitizeOutput(mod.testOutput, '# ') : '';
if (mod.testOutput && mod.testOutput.length > 0) {
output = '\n ---\n' + util.sanitizeOutput(mod.testOutput, ' #') + '\n ...';
}
return [result, count + 1, '-', mod.name, 'v' + mod.version + error + output].join(' ');
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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"
}
}
24 changes: 24 additions & 0 deletions test/fixtures/parsed-tap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"bailout": false,
"count": 3,
"fail": 1,
"failures": [
{
"diag": null,
"id": 3,
"name": "iFail v3.0.1 I dun wurk",
"ok": false
}
],
"ok": false,
"pass": 2,
"plan": {
"comment": "",
"start": 1,
"skipAll": false,
"skipReason": "",
"end": 3
},
"skip": 1,
"todo": 0
}
8 changes: 6 additions & 2 deletions test/fixtures/test-out-tap-failing.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion test/fixtures/test-out-tap-passing-append.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion test/fixtures/test-out-tap-passing.txt
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions test/reporter/test-reporter-tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -27,6 +29,7 @@ var passingInput = [
var passingExpectedPath = path.join(fixturesPath, 'test-out-tap-passing.txt');
var passingExpectedPathAppend = path.join(fixturesPath, 'test-out-tap-passing-append.txt');

var tapParserExpected = require('../fixtures/parsed-tap.json');
var passingExpected = fs.readFileSync(passingExpectedPath, 'utf-8');
var passingExpectedAppend = fs.readFileSync(passingExpectedPathAppend, 'utf-8');

Expand Down Expand Up @@ -70,6 +73,20 @@ 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) {
t.deepEquals(results, 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');
Expand Down

0 comments on commit 807ad62

Please sign in to comment.