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 (depracated) tape-testing#312
  • Loading branch information
nelsonic committed Aug 28, 2016
1 parent f944fbb commit c33c0bf
Showing 1 changed file with 91 additions and 91 deletions.
182 changes: 91 additions & 91 deletions test/exit.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
var tap = require('tap');
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;
});
var tc = function (rows) {

var rs = rows.toString('utf8').split('\n');
t.same(rs, [
'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'
'# 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',
'',
''
]);
});
}

var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]);
ps.stdout.pipe(tc);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
Expand All @@ -41,33 +38,34 @@ tap.test('exit ok', function (t) {
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;
});
var tc = function (rows) {

var rs = rows.toString('utf8').split('\n');
t.same(rs, [
'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'
'# 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',
'',
''
]);
});
};

var ps = spawn(process.execPath, [ __dirname + '/exit/fail.js' ]);
ps.stdout.pipe(tc);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
Expand All @@ -76,34 +74,35 @@ tap.test('exit fail', function (t) {
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;
});
var tc = function (rows) {

var rs = rows.toString('utf8').split('\n');
t.same(rs, [
'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'
'# 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',
'',
''
]);
});
};

var ps = spawn(process.execPath, [ __dirname + '/exit/too_few.js' ]);
ps.stdout.pipe(tc);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
Expand All @@ -112,33 +111,34 @@ tap.test('too few exit', function (t) {
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;
});
var tc = function (rows) {

var rs = rows.toString('utf8').split('\n');
t.same(rs, [
'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'
'# 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',
'',
'',
]);
});
};

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

0 comments on commit c33c0bf

Please sign in to comment.