Skip to content

Commit 5f4d033

Browse files
author
George Adams
committed
reporter: update to use TAP 13
Use yamlish instead of # to match community: nodejs/node#9262
1 parent a7346e3 commit 5f4d033

7 files changed

Lines changed: 60 additions & 7 deletions

File tree

lib/reporter/tap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ function generateTest(mod, count) {
1111
if (mod.error && mod.error.message) {
1212
mod.error = mod.error.message;
1313
}
14+
var output = '';
1415
var error = mod.error ? [directive, mod.error].join(' ') : '';
15-
var output = mod.testOutput ? '\n' + util.sanitizeOutput(mod.testOutput, '# ') : '';
16+
if (mod.testOutput && mod.testOutput.length > 0) {
17+
output = '\n ---\n' + util.sanitizeOutput(mod.testOutput, ' #') + '\n ...';
18+
}
1619
return [result, count + 1, '-', mod.name, 'v' + mod.version + error + output].join(' ');
1720
}
1821

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
"nyc": "^8.4.0",
6565
"opener": "^1.4.1",
6666
"rewire": "^2.4.0",
67-
"tap": "^8.0.0"
67+
"tap": "^8.0.0",
68+
"tap-parser": "^3.0.3",
69+
"string-to-stream": "^1.1.0"
6870
}
6971
}

test/fixtures/parsed-tap.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"bailout": false,
3+
"count": 3,
4+
"fail": 1,
5+
"failures": [
6+
{
7+
"diag": null,
8+
"id": 3,
9+
"name": "iFail v3.0.1 I dun wurk",
10+
"ok": false
11+
}
12+
],
13+
"ok": false,
14+
"pass": 2,
15+
"plan": {
16+
"comment": "",
17+
"start": 1,
18+
"skipAll": false,
19+
"skipReason": "",
20+
"end": 3
21+
},
22+
"skip": 1,
23+
"todo": 0
24+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
TAP version 13
22
ok 1 - iPass v4.2.2
33
ok 2 - iFlakyFail v3.3.3 # SKIP I dun wurk
4-
# Thanks for testing!
4+
---
5+
# Thanks for testing!
6+
...
57
not ok 3 - iFail v3.0.1 I dun wurk
6-
# Thanks for testing!
8+
---
9+
# Thanks for testing!
10+
...
711
1..3

test/fixtures/test-out-tap-passing-append.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ This is a test!
22
TAP version 13
33
ok 1 - iPass v4.2.2
44
ok 2 - iFlakyPass v3.0.1
5-
# Thanks for testing!
5+
---
6+
# Thanks for testing!
7+
...
68
1..2
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
TAP version 13
22
ok 1 - iPass v4.2.2
33
ok 2 - iFlakyPass v3.0.1
4-
# Thanks for testing!
4+
---
5+
# Thanks for testing!
6+
...
57
1..2

test/reporter/test-reporter-tap.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var os = require('os');
77
var test = require('tap').test;
88
var mkdirp = require('mkdirp');
99
var rimraf = require('rimraf');
10+
var parser = require('tap-parser');
11+
var str = require('string-to-stream');
1012

1113
var tap = require('../../lib/reporter/tap');
1214
var fixtures = require('../fixtures/reporter-fixtures');
@@ -23,10 +25,10 @@ var passingInput = [
2325
fixtures.iPass,
2426
fixtures.iFlakyPass
2527
];
26-
2728
var passingExpectedPath = path.join(fixturesPath, 'test-out-tap-passing.txt');
2829
var passingExpectedPathAppend = path.join(fixturesPath, 'test-out-tap-passing-append.txt');
2930

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

@@ -70,6 +72,20 @@ test('reporter.tap(): failing', function (t) {
7072
t.end();
7173
});
7274

75+
test('reporter.tap(): parser', function (t) {
76+
var output = '';
77+
function logger(message) {
78+
output += message;
79+
}
80+
81+
tap(logger, failingInput);
82+
var p = parser(function (results) {
83+
t.deepEquals(results, tapParserExpected), 'the tap parser should correctly parse the tap file';
84+
t.end();
85+
});
86+
str(output).pipe(p);
87+
});
88+
7389
test('reporter.tap(): write to disk', function (t) {
7490
tap(outputFile, passingInput);
7591
var expected = fs.readFileSync(outputFile, 'utf8');

0 commit comments

Comments
 (0)