Skip to content

Commit

Permalink
complete double end test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 5, 2014
1 parent 8d25028 commit 45add17
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
53 changes: 23 additions & 30 deletions test/double_end.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
var tape = require('../');
var tap = require('tap');
var test = require('tap').test;
var concat = require('concat-stream');
var spawn = require('child_process').spawn;

tap.test(function (t) {
t.plan(1);

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

var rows = [];
tc.on('data', function (row) { rows.push(row) });
tc.on('end', function () {
t.deepEqual(rows, [
'TAP version 13',
'double end',
{ id: 1, ok: true, name: 'should be equivalent' },
{ id: 2, ok: false, name: '.end() called twice' },
'tests 2',
'pass 1',
'fail 1',
]);
});

test.createStream().pipe(tc);

test('double end', function (tt) {
tt.equal(1 + 1, 2);
tt.end();
setTimeout(function () {
tt.end();
}, 5);
test(function (t) {
t.plan(2);
var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]);
ps.on('exit', function (code) {
t.equal(code, 1);
});
ps.stdout.pipe(concat(function (body) {
t.equal(body.toString('utf8'), [
'TAP version 13',
'# double end',
'ok 1 should be equal',
'not ok 2 .end() called twice',
' ---',
' operator: fail',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1',
].join('\n') + '\n\n');
}));
});
9 changes: 9 additions & 0 deletions test/double_end/double.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var test = require('../../');

test('double end', function (t) {
t.equal(1 + 1, 2);
t.end();
setTimeout(function () {
t.end();
}, 5);
});

0 comments on commit 45add17

Please sign in to comment.