From 78e4ffd6e5108907ed1389546e78414d88e42cc4 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:46:04 +0100 Subject: [PATCH] update test/exit.js to use concat-stream instead of tap.createConsumer (method unvailable in tap v7) for #312 --- test/exit.js | 207 ++++++++++++++++++++++++--------------------------- 1 file changed, 97 insertions(+), 110 deletions(-) diff --git a/test/exit.js b/test/exit.js index b398ca12..963e6b08 100644 --- a/test/exit.js +++ b/test/exit.js @@ -1,38 +1,34 @@ 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); }); @@ -40,34 +36,31 @@ 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; - }); - 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); }); @@ -75,35 +68,32 @@ 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; - }); - 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); }); @@ -111,33 +101,30 @@ 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; - }); - 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); });