Skip to content

Commit 807ad62

Browse files
George AdamsMyles Borins
authored andcommitted
reporter: update to use TAP 13
Use yamlish instead of # to match community: nodejs/node#9262
1 parent 0eb9d35 commit 807ad62

File tree

7 files changed

+60
-6
lines changed

7 files changed

+60
-6
lines changed

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
@@ -63,6 +63,8 @@
6363
"nyc": "^8.4.0",
6464
"opener": "^1.4.1",
6565
"rewire": "^2.4.0",
66-
"tap": "^8.0.0"
66+
"tap": "^8.0.0",
67+
"tap-parser": "^3.0.3",
68+
"string-to-stream": "^1.1.0"
6769
}
6870
}

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 & 0 deletions
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');
@@ -27,6 +29,7 @@ var passingInput = [
2729
var passingExpectedPath = path.join(fixturesPath, 'test-out-tap-passing.txt');
2830
var passingExpectedPathAppend = path.join(fixturesPath, 'test-out-tap-passing-append.txt');
2931

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

@@ -70,6 +73,20 @@ test('reporter.tap(): failing', function (t) {
7073
t.end();
7174
});
7275

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

0 commit comments

Comments
 (0)