Skip to content

Commit

Permalink
update test/exit.js to use concat-stream instead of tap.createConsume…
Browse files Browse the repository at this point in the history
…r (method unvailable in tap v7) for #312
  • Loading branch information
nelsonic committed Sep 2, 2016
1 parent e3115ff commit 78e4ffd
Showing 1 changed file with 97 additions and 110 deletions.
207 changes: 97 additions & 110 deletions test/exit.js
Original file line number Diff line number Diff line change
@@ -1,143 +1,130 @@
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('exit ok', function (t) {
t.plan(2);

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;
});
t.same(rs, [

var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'array',
'hi',
{ 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'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]);
ps.stdout.pipe(tc);
'# array',
'# hi',
'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',
'', // yes, these double-blank-lines at the end are required.
'' // if you can figure out how to remove them, please do!
].join('\n'));
}

var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});

tap.test('exit fail', function (t) {
t.plan(2);

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;
});
t.same(rs, [

var tc = function (rows) {
t.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: false, name: 'should be equivalent' },
'tests 5',
'pass 4',
'fail 1'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/exit/fail.js' ]);
ps.stdout.pipe(tc);
'# array',
'ok 1 should be equivalent',
'ok 2 should be equivalent',
'ok 3 should be equivalent',
'ok 4 should be equivalent',
'not ok 5 should be equivalent',
' ---',
' operator: deepEqual',
' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
' ...',
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1'
].join('\n') + '\n\n');
};

var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
});

tap.test('too few exit', function (t) {
t.plan(2);

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;
});
t.same(rs, [

var tc = function (rows) {
t.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' },
{ id: 6, ok: false, name: 'plan != count' },
'tests 6',
'pass 5',
'fail 1'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/exit/too_few.js' ]);
ps.stdout.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',
'not ok 6 plan != count',
' ---',
' operator: fail',
' expected: 6',
' actual: 5',
' ...',
'',
'1..6',
'# tests 6',
'# pass 5',
'# fail 1'
].join('\n') + '\n\n');
};

var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
});

tap.test('more planned in a second test', function (t) {
t.plan(2);

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;
});
t.same(rs, [

var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'first',
{ id: 1, ok: true, name: 'should be truthy' },
'second',
{ id: 2, ok: true, name: 'should be truthy' },
{ id: 3, ok: false, name: 'plan != count' },
'tests 3',
'pass 2',
'fail 1'
]);
});

var ps = spawn(process.execPath, [ __dirname + '/exit/second.js' ]);
ps.stdout.pipe(tc);
'# first',
'ok 1 should be truthy',
'# second',
'ok 2 should be truthy',
'not ok 3 plan != count',
' ---',
' operator: fail',
' expected: 2',
' actual: 1',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1'
].join('\n') + '\n\n');
};

var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
Expand Down

0 comments on commit 78e4ffd

Please sign in to comment.