Skip to content

Commit

Permalink
Merge pull request #318 from dwyl/master
Browse files Browse the repository at this point in the history
[Tests] [Dev Deps] Update to latest version of devDependencies tap (v7) and tap-parser (v2)
  • Loading branch information
ljharb authored Sep 2, 2016
2 parents 6978df4 + 44d1f6f commit bc6ecea
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 449 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"concat-stream": "~1.5.1",
"falafel": "~1.2.0",
"js-yaml": "~3.6.1",
"tap": "~0.7.1",
"tap-parser": "~1.2.2"
"tap": "~7.0.0",
"tap-parser": "~2.0.0"
},
"scripts": {
"test": "tap test/*.js"
Expand Down
23 changes: 9 additions & 14 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Please note that all modules loaded using the `-r` flag will run *before* any te

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

## reporters for humans
## pretty reporters

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

Expand All @@ -98,30 +98,26 @@ that will output something pretty if you pipe TAP into them:
- https://github.com/scottcorgan/tap-spec
- https://github.com/scottcorgan/tap-dot
- https://github.com/substack/faucet
- https://github.com/juliangruber/tap-bail
- https://github.com/kirbysayshi/tap-browser-color
- https://github.com/gummesson/tap-json
- https://github.com/gummesson/tap-min
- https://github.com/calvinmetcalf/tap-nyan
- https://github.com/clux/tap-pessimist
- https://www.npmjs.org/package/tap-pessimist
- https://github.com/toolness/tap-prettify
- https://github.com/shuhei/colortape
- https://github.com/aghassemi/tap-xunit
- https://github.com/namuol/tap-difflet
- https://github.com/gritzko/tape-dom
- https://github.com/axross/tap-diff
- https://github.com/axross/tap-notify
- https://github.com/zoubin/tap-summary

You use these reporters by piping the tape output into them. For example,
try `node test/index.js | tap-spec`.

## reporters for other file formats

- https://github.com/gummesson/tap-json
- https://github.com/aghassemi/tap-xunit
- https://github.com/gritzko/tape-dom
- https://github.com/Hypercubed/tap-markdown

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

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

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.

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

# methods

Expand Down
42 changes: 17 additions & 25 deletions test/array.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

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

var test = tape.createHarness();
var tc = tap.createConsumer();

var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
tt.same(rs, [
test.createStream().pipe(concat(function (rows) {
tt.same(rows.toString('utf8'), [
'TAP version 13',
'array',
{ id: 1, ok: true, name: 'should be equivalent' },
{ id: 2, ok: true, name: 'should be equivalent' },
{ id: 3, ok: true, name: 'should be equivalent' },
{ id: 4, ok: true, name: 'should be equivalent' },
{ id: 5, ok: true, name: 'should be equivalent' },
'tests 5',
'pass 5',
'ok'
]);
});

test.createStream().pipe(tc);
'# array',
'ok 1 should be equivalent',
'ok 2 should be equivalent',
'ok 3 should be equivalent',
'ok 4 should be equivalent',
'ok 5 should be equivalent',
'',
'1..5',
'# tests 5',
'# pass 5',
'',
'# ok'
].join('\n') + '\n');
}));

test('array', function (t) {
t.plan(5);
Expand Down
50 changes: 22 additions & 28 deletions test/default-messages.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
var tap = require('tap');
var path = require('path');
var spawn = require('child_process').spawn;
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

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

var tc = tap.createConsumer();
var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]);

ps.stdout.pipe(concat(function (rows) {

var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
t.same(rs, [
t.same(rows.toString('utf8'), [
'TAP version 13',
'default messages',
{ id: 1, ok: true, name: 'should be truthy' },
{ id: 2, ok: true, name: 'should be falsy' },
{ id: 3, ok: true, name: 'should be equal' },
{ id: 4, ok: true, name: 'should not be equal' },
{ id: 5, ok: true, name: 'should be equivalent' },
{ id: 6, ok: true, name: 'should be equivalent' },
{ id: 7, ok: true, name: 'should be equivalent' },
'tests 7',
'pass 7',
'ok'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]);
ps.stdout.pipe(tc);
'# default messages',
'ok 1 should be truthy',
'ok 2 should be falsy',
'ok 3 should be equal',
'ok 4 should not be equal',
'ok 5 should be equivalent',
'ok 6 should be equivalent',
'ok 7 should be equivalent',
'',
'1..7',
'# tests 7',
'# pass 7',
'',
'# ok'
].join('\n') + '\n\n');
}));
});
3 changes: 2 additions & 1 deletion test/double_end.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var test = require('tap').test;
var path = require('path');
var concat = require('concat-stream');
var spawn = require('child_process').spawn;

test(function (t) {
t.plan(2);
var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]);
var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
ps.on('exit', function (code) {
t.equal(code, 1);
});
Expand Down
79 changes: 50 additions & 29 deletions test/end-as-callback.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
var tap = require("tap");
var tape = require("../");
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

tap.test("tape assert.end as callback", function (tt) {
var test = tape.createHarness({ exit: false })
var tc = tap.createConsumer()

var rows = []
tc.on("data", function (r) { rows.push(r) })
tc.on("end", function () {
var rs = rows.map(function (r) {
return r && typeof r === "object" ?
{ id: r.id, ok: r.ok, name: trim(r.name) } :
r
})

tt.deepEqual(rs, [
"TAP version 13",
"do a task and write",
{ id: 1, ok: true, name: "null" },
{ id: 2, ok: true, name: "should be equal" },
"do a task and write fail",
{ id: 3, ok: true, name: "null" },
{ id: 4, ok: true, name: "should be equal" },
{ id: 5, ok: false, name: "Error: fail" },
"tests 5",
"pass 4",
"fail 1"
])


test.createStream().pipe(concat(function (rows) {
tt.equal(rows.toString('utf8'), [
'TAP version 13',
'# do a task and write',
'ok 1 null',
'ok 2 should be equal',
'# do a task and write fail',
'ok 3 null',
'ok 4 should be equal',
'not ok 5 Error: fail',
getStackTrace(rows), // tap error stack
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1'
].join('\n') + '\n');
tt.end()
})

test.createStream().pipe(tc)
}));

test("do a task and write", function (assert) {
fakeAsyncTask("foo", function (err, value) {
Expand Down Expand Up @@ -64,3 +55,33 @@ function fakeAsyncWrite(name, cb) {
function fakeAsyncWriteFail(name, cb) {
cb(new Error("fail"))
}

/**
* extract the stack trace for the failed test.
* this will change dependent on the environment
* so no point hard-coding it in the test assertion
* see: https://git.io/v6hGG for example
* @param String rows - the tap output lines
* @returns String stacktrace - just the error stack part
*/
function getStackTrace(rows) {
var stacktrace = ' ---\n';
var extract = false;
rows.toString('utf8').split('\n').forEach(function (row) {
if (!extract) {
if (row.indexOf('---') > -1) { // start of stack trace
extract = true;
}
} else {
if (row.indexOf('...') > -1) { // end of stack trace
extract = false;
stacktrace += ' ...';
} else {
stacktrace += row + '\n';
}

}
});
// console.log(stacktrace);
return stacktrace;
}
Loading

0 comments on commit bc6ecea

Please sign in to comment.