Skip to content

Commit bc6ecea

Browse files
authored
Merge pull request #318 from dwyl/master
[Tests] [Dev Deps] Update to latest version of devDependencies tap (v7) and tap-parser (v2)
2 parents 6978df4 + 44d1f6f commit bc6ecea

17 files changed

+359
-449
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"concat-stream": "~1.5.1",
2727
"falafel": "~1.2.0",
2828
"js-yaml": "~3.6.1",
29-
"tap": "~0.7.1",
30-
"tap-parser": "~1.2.2"
29+
"tap": "~7.0.0",
30+
"tap-parser": "~2.0.0"
3131
},
3232
"scripts": {
3333
"test": "tap test/*.js"

readme.markdown

+9-14
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Please note that all modules loaded using the `-r` flag will run *before* any te
8888

8989
tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape.
9090

91-
## reporters for humans
91+
## pretty reporters
9292

9393
The default TAP output is good for machines and humans that are robots.
9494

@@ -98,30 +98,26 @@ that will output something pretty if you pipe TAP into them:
9898
- https://github.com/scottcorgan/tap-spec
9999
- https://github.com/scottcorgan/tap-dot
100100
- https://github.com/substack/faucet
101+
- https://github.com/juliangruber/tap-bail
101102
- https://github.com/kirbysayshi/tap-browser-color
103+
- https://github.com/gummesson/tap-json
102104
- https://github.com/gummesson/tap-min
103105
- https://github.com/calvinmetcalf/tap-nyan
104-
- https://github.com/clux/tap-pessimist
106+
- https://www.npmjs.org/package/tap-pessimist
105107
- https://github.com/toolness/tap-prettify
106108
- https://github.com/shuhei/colortape
109+
- https://github.com/aghassemi/tap-xunit
107110
- https://github.com/namuol/tap-difflet
111+
- https://github.com/gritzko/tape-dom
108112
- https://github.com/axross/tap-diff
109113
- https://github.com/axross/tap-notify
110114
- https://github.com/zoubin/tap-summary
111-
112-
You use these reporters by piping the tape output into them. For example,
113-
try `node test/index.js | tap-spec`.
114-
115-
## reporters for other file formats
116-
117-
- https://github.com/gummesson/tap-json
118-
- https://github.com/aghassemi/tap-xunit
119-
- https://github.com/gritzko/tape-dom
120115
- https://github.com/Hypercubed/tap-markdown
121116

122-
## failing assertions
117+
To use them, try `node test/index.js | tap-spec` or pipe it into one
118+
of the modules of your choice!
123119

124-
If any assertions fail, tape will continue. To terminate on the first failure, see [tap-bail](https://github.com/juliangruber/tap-bail).
120+
## uncaught exceptions
125121

126122
By default, uncaught exceptions in your tests will not be intercepted, and will cause tape to crash. If you find this behavior undesirable, use [tape-catch](https://github.com/michaelrhodes/tape-catch) to report any exceptions as TAP errors.
127123

@@ -130,7 +126,6 @@ By default, uncaught exceptions in your tests will not be intercepted, and will
130126
- CoffeeScript support with https://www.npmjs.com/package/coffeetape
131127
- Promise support with https://www.npmjs.com/package/blue-tape
132128
- ES6 support with https://www.npmjs.com/package/babel-tape-runner
133-
- Inclue time information with https://github.com/diasdavid/timed-tape
134129

135130
# methods
136131

test/array.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
var falafel = require('falafel');
22
var tape = require('../');
33
var tap = require('tap');
4-
var trim = require('string.prototype.trim');
4+
var concat = require('concat-stream');
55

66
tap.test('array test', function (tt) {
77
tt.plan(1);
88

99
var test = tape.createHarness();
10-
var tc = tap.createConsumer();
1110

12-
var rows = [];
13-
tc.on('data', function (r) { rows.push(r) });
14-
tc.on('end', function () {
15-
var rs = rows.map(function (r) {
16-
if (r && typeof r === 'object') {
17-
return { id : r.id, ok : r.ok, name : trim(r.name) };
18-
}
19-
else return r;
20-
});
21-
tt.same(rs, [
11+
test.createStream().pipe(concat(function (rows) {
12+
tt.same(rows.toString('utf8'), [
2213
'TAP version 13',
23-
'array',
24-
{ id: 1, ok: true, name: 'should be equivalent' },
25-
{ id: 2, ok: true, name: 'should be equivalent' },
26-
{ id: 3, ok: true, name: 'should be equivalent' },
27-
{ id: 4, ok: true, name: 'should be equivalent' },
28-
{ id: 5, ok: true, name: 'should be equivalent' },
29-
'tests 5',
30-
'pass 5',
31-
'ok'
32-
]);
33-
});
34-
35-
test.createStream().pipe(tc);
14+
'# array',
15+
'ok 1 should be equivalent',
16+
'ok 2 should be equivalent',
17+
'ok 3 should be equivalent',
18+
'ok 4 should be equivalent',
19+
'ok 5 should be equivalent',
20+
'',
21+
'1..5',
22+
'# tests 5',
23+
'# pass 5',
24+
'',
25+
'# ok'
26+
].join('\n') + '\n');
27+
}));
3628

3729
test('array', function (t) {
3830
t.plan(5);

test/default-messages.js

+22-28
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
var tap = require('tap');
2+
var path = require('path');
23
var spawn = require('child_process').spawn;
3-
var trim = require('string.prototype.trim');
4+
var concat = require('concat-stream');
45

56
tap.test('default messages', function (t) {
67
t.plan(1);
78

8-
var tc = tap.createConsumer();
9+
var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]);
10+
11+
ps.stdout.pipe(concat(function (rows) {
912

10-
var rows = [];
11-
tc.on('data', function (r) { rows.push(r) });
12-
tc.on('end', function () {
13-
var rs = rows.map(function (r) {
14-
if (r && typeof r === 'object') {
15-
return { id : r.id, ok : r.ok, name : trim(r.name) };
16-
}
17-
else return r;
18-
});
19-
t.same(rs, [
13+
t.same(rows.toString('utf8'), [
2014
'TAP version 13',
21-
'default messages',
22-
{ id: 1, ok: true, name: 'should be truthy' },
23-
{ id: 2, ok: true, name: 'should be falsy' },
24-
{ id: 3, ok: true, name: 'should be equal' },
25-
{ id: 4, ok: true, name: 'should not be equal' },
26-
{ id: 5, ok: true, name: 'should be equivalent' },
27-
{ id: 6, ok: true, name: 'should be equivalent' },
28-
{ id: 7, ok: true, name: 'should be equivalent' },
29-
'tests 7',
30-
'pass 7',
31-
'ok'
32-
]);
33-
});
34-
35-
var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]);
36-
ps.stdout.pipe(tc);
15+
'# default messages',
16+
'ok 1 should be truthy',
17+
'ok 2 should be falsy',
18+
'ok 3 should be equal',
19+
'ok 4 should not be equal',
20+
'ok 5 should be equivalent',
21+
'ok 6 should be equivalent',
22+
'ok 7 should be equivalent',
23+
'',
24+
'1..7',
25+
'# tests 7',
26+
'# pass 7',
27+
'',
28+
'# ok'
29+
].join('\n') + '\n\n');
30+
}));
3731
});

test/double_end.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var test = require('tap').test;
2+
var path = require('path');
23
var concat = require('concat-stream');
34
var spawn = require('child_process').spawn;
45

56
test(function (t) {
67
t.plan(2);
7-
var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]);
8+
var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
89
ps.on('exit', function (code) {
910
t.equal(code, 1);
1011
});

test/end-as-callback.js

+50-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
var tap = require("tap");
22
var tape = require("../");
3-
var trim = require('string.prototype.trim');
3+
var concat = require('concat-stream');
44

55
tap.test("tape assert.end as callback", function (tt) {
66
var test = tape.createHarness({ exit: false })
7-
var tc = tap.createConsumer()
8-
9-
var rows = []
10-
tc.on("data", function (r) { rows.push(r) })
11-
tc.on("end", function () {
12-
var rs = rows.map(function (r) {
13-
return r && typeof r === "object" ?
14-
{ id: r.id, ok: r.ok, name: trim(r.name) } :
15-
r
16-
})
17-
18-
tt.deepEqual(rs, [
19-
"TAP version 13",
20-
"do a task and write",
21-
{ id: 1, ok: true, name: "null" },
22-
{ id: 2, ok: true, name: "should be equal" },
23-
"do a task and write fail",
24-
{ id: 3, ok: true, name: "null" },
25-
{ id: 4, ok: true, name: "should be equal" },
26-
{ id: 5, ok: false, name: "Error: fail" },
27-
"tests 5",
28-
"pass 4",
29-
"fail 1"
30-
])
31-
7+
8+
test.createStream().pipe(concat(function (rows) {
9+
tt.equal(rows.toString('utf8'), [
10+
'TAP version 13',
11+
'# do a task and write',
12+
'ok 1 null',
13+
'ok 2 should be equal',
14+
'# do a task and write fail',
15+
'ok 3 null',
16+
'ok 4 should be equal',
17+
'not ok 5 Error: fail',
18+
getStackTrace(rows), // tap error stack
19+
'',
20+
'1..5',
21+
'# tests 5',
22+
'# pass 4',
23+
'# fail 1'
24+
].join('\n') + '\n');
3225
tt.end()
33-
})
34-
35-
test.createStream().pipe(tc)
26+
}));
3627

3728
test("do a task and write", function (assert) {
3829
fakeAsyncTask("foo", function (err, value) {
@@ -64,3 +55,33 @@ function fakeAsyncWrite(name, cb) {
6455
function fakeAsyncWriteFail(name, cb) {
6556
cb(new Error("fail"))
6657
}
58+
59+
/**
60+
* extract the stack trace for the failed test.
61+
* this will change dependent on the environment
62+
* so no point hard-coding it in the test assertion
63+
* see: https://git.io/v6hGG for example
64+
* @param String rows - the tap output lines
65+
* @returns String stacktrace - just the error stack part
66+
*/
67+
function getStackTrace(rows) {
68+
var stacktrace = ' ---\n';
69+
var extract = false;
70+
rows.toString('utf8').split('\n').forEach(function (row) {
71+
if (!extract) {
72+
if (row.indexOf('---') > -1) { // start of stack trace
73+
extract = true;
74+
}
75+
} else {
76+
if (row.indexOf('...') > -1) { // end of stack trace
77+
extract = false;
78+
stacktrace += ' ...';
79+
} else {
80+
stacktrace += row + '\n';
81+
}
82+
83+
}
84+
});
85+
// console.log(stacktrace);
86+
return stacktrace;
87+
}

0 commit comments

Comments
 (0)