diff --git a/.eslintignore b/.eslintignore index 404abb22..ed88d37f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ coverage/ +.nyc_output/ diff --git a/bin/tape b/bin/tape index 35e1e791..436884d9 100755 --- a/bin/tape +++ b/bin/tape @@ -27,9 +27,7 @@ if (typeof opts.require === 'string') { opts.require.forEach(function (module) { var options = { basedir: cwd, extensions: Object.keys(require.extensions) }; if (module) { - /* This check ensures we ignore `-r ""`, trailing `-r`, or - * other silly things the user might (inadvertently) be doing. - */ + // This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing. require(resolveModule(module, options)); } }); diff --git a/example/array.js b/example/array.js index cb17d42b..40be4847 100644 --- a/example/array.js +++ b/example/array.js @@ -19,10 +19,10 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[ 1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( diff --git a/example/nested.js b/example/nested.js index 0e4e1cbd..59dbd54b 100644 --- a/example/nested.js +++ b/example/nested.js @@ -7,8 +7,8 @@ test('nested array test', function (t) { t.plan(6); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; g([ xs, ys ]); } + ')()'; diff --git a/example/too_many_fail.js b/example/too_many_fail.js index e374008f..2ae76502 100644 --- a/example/too_many_fail.js +++ b/example/too_many_fail.js @@ -7,8 +7,8 @@ test('array', function (t) { t.plan(3); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; g([ xs, ys ]); } + ')()'; @@ -19,10 +19,10 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -31,7 +31,7 @@ test('array', function (t) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/array.js b/test/array.js index 502b3f97..39be3f61 100644 --- a/test/array.js +++ b/test/array.js @@ -32,9 +32,9 @@ tap.test('array test', function (tt) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -44,10 +44,10 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -56,7 +56,7 @@ tap.test('array test', function (tt) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/async-await.js b/test/async-await.js index 8a6a3ebc..813c3fda 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -14,7 +14,7 @@ if (Number(majorVersion) < 8) { tap.test('async1', function (t) { runProgram('async-await', 'async1.js', function (r) { - t.same(r.stdout.toString('utf8'), [ + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ 'TAP version 13', '# async1', 'ok 1 before await', @@ -24,8 +24,10 @@ tap.test('async1', function (t) { '# tests 2', '# pass 2', '', - '# ok' - ].join('\n') + '\n\n'); + '# ok', + '', + '' + ]); t.same(r.exitCode, 0); t.same(r.stderr.toString('utf8'), ''); t.end(); @@ -39,7 +41,7 @@ tap.test('async2', function (t) { return !(/^(\s+)at(\s+)$/).test(line); }); - t.same(stripFullStack(lines.join('\n')), [ + t.deepEqual(stripFullStack(lines.join('\n')), [ 'TAP version 13', '# async2', 'ok 1 before await', @@ -70,7 +72,7 @@ tap.test('async2', function (t) { tap.test('async3', function (t) { runProgram('async-await', 'async3.js', function (r) { - t.same(r.stdout.toString('utf8'), [ + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ 'TAP version 13', '# async3', 'ok 1 before await', @@ -80,8 +82,10 @@ tap.test('async3', function (t) { '# tests 2', '# pass 2', '', - '# ok' - ].join('\n') + '\n\n'); + '# ok', + '', + '' + ]); t.same(r.exitCode, 0); t.same(r.stderr.toString('utf8'), ''); t.end(); @@ -90,7 +94,7 @@ tap.test('async3', function (t) { tap.test('async4', function (t) { runProgram('async-await', 'async4.js', function (r) { - t.same(stripFullStack(r.stdout.toString('utf8')), [ + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ 'TAP version 13', '# async4', 'ok 1 before await', diff --git a/test/comment.js b/test/comment.js index b9933b53..68843563 100644 --- a/test/comment.js +++ b/test/comment.js @@ -10,7 +10,7 @@ tap.test('no comment', function (assert) { assert.plan(1); var verify = function (output) { - assert.equal(output.toString('utf8'), [ + assert.deepEqual(output.toString('utf8').split('\n'), [ 'TAP version 13', '# no comment', '', @@ -20,7 +20,7 @@ tap.test('no comment', function (assert) { '', '# ok', '' - ].join('\n')); + ]); }; var test = tape.createHarness(); diff --git a/test/deep.js b/test/deep.js index 8f8862bf..8e41a2fa 100644 --- a/test/deep.js +++ b/test/deep.js @@ -4,16 +4,16 @@ var test = require('../'); test('deep strict equal', function (t) { t.notDeepEqual( - [ { a: '3' } ], - [ { a: 3 } ] + [{ a: '3' }], + [{ a: 3 }] ); t.end(); }); test('deep loose equal', function (t) { t.deepLooseEqual( - [ { a: '3' } ], - [ { a: 3 } ] + [{ a: '3' }], + [{ a: 3 }] ); t.end(); }); diff --git a/test/exit/fail.js b/test/exit/fail.js index 45fc1789..930f51df 100644 --- a/test/exit/fail.js +++ b/test/exit/fail.js @@ -7,9 +7,9 @@ test('array', function (t) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -19,10 +19,10 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -31,7 +31,7 @@ test('array', function (t) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); } ); }); diff --git a/test/exit/ok.js b/test/exit/ok.js index 1c68c15e..7649d940 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -8,9 +8,9 @@ test('array', function (t) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -20,10 +20,10 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -32,7 +32,7 @@ test('array', function (t) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/exit/too_few.js b/test/exit/too_few.js index cd347e54..33bc0855 100644 --- a/test/exit/too_few.js +++ b/test/exit/too_few.js @@ -7,9 +7,9 @@ test('array', function (t) { t.plan(6); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -19,10 +19,10 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -31,7 +31,7 @@ test('array', function (t) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/fail.js b/test/fail.js index 78642c84..a2715dcf 100644 --- a/test/fail.js +++ b/test/fail.js @@ -49,9 +49,9 @@ tap.test('array test', function (tt) { t.plan(5); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -61,10 +61,10 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -73,7 +73,7 @@ tap.test('array test', function (tt) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); } ); }); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 80a7da04..66b805d9 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -9,7 +9,7 @@ tap.test('nested sync test without plan or end', function (tt) { var test = tape.createHarness(); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(rows.toString('utf8').split('\n'), [ 'TAP version 13', '# nested without plan or end', '# first', @@ -21,8 +21,9 @@ tap.test('nested sync test without plan or end', function (tt) { '# tests 2', '# pass 2', '', - '# ok' - ].join('\n') + '\n'); + '# ok', + '' + ]); }; test.createStream().pipe(concat(tc)); diff --git a/test/nested.js b/test/nested.js index 2dd19583..6348a250 100644 --- a/test/nested.js +++ b/test/nested.js @@ -10,7 +10,7 @@ tap.test('array test', function (tt) { var test = tape.createHarness(); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(rows.toString('utf8').split('\n'), [ 'TAP version 13', '# nested array test', 'ok 1 should be deeply equivalent', @@ -28,8 +28,9 @@ tap.test('array test', function (tt) { '# tests 8', '# pass 8', '', - '# ok' - ].join('\n') + '\n'); + '# ok', + '' + ]); }; test.createStream().pipe(concat(tc)); @@ -38,9 +39,9 @@ tap.test('array test', function (tt) { t.plan(6); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -59,10 +60,10 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -71,7 +72,7 @@ tap.test('array test', function (tt) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/test/only.js b/test/only.js index 4c4fc63a..4011d86a 100644 --- a/test/only.js +++ b/test/only.js @@ -9,7 +9,7 @@ tap.test('tape only test', function (tt) { var ran = []; var tc = function (rows) { - tt.deepEqual(rows.toString('utf8'), [ + tt.deepEqual(rows.toString('utf8').split('\n'), [ 'TAP version 13', '# run success', 'ok 1 assert name', @@ -18,9 +18,10 @@ tap.test('tape only test', function (tt) { '# tests 1', '# pass 1', '', - '# ok' - ].join('\n') + '\n'); - tt.deepEqual(ran, [ 3 ]); + '# ok', + '' + ]); + tt.deepEqual(ran, [3]); tt.end(); }; diff --git a/test/promise_fail.js b/test/promise_fail.js index f45019da..97039391 100644 --- a/test/promise_fail.js +++ b/test/promise_fail.js @@ -81,7 +81,7 @@ tap.test('subtest callback returning rejected promise should cause that subtest .replace(/.+at (?:Test\.)?\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '') .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n'); - tt.same(strippedString, [ + tt.same(stripFullStack(strippedString), [ 'TAP version 13', '# promise', '# sub test that should fail', @@ -102,6 +102,6 @@ tap.test('subtest callback returning rejected promise should cause that subtest '# fail 1', '', '' - ].join('\n')); + ]); })); }); diff --git a/test/require.js b/test/require.js index 14014cdd..6cfed91a 100644 --- a/test/require.js +++ b/test/require.js @@ -3,12 +3,13 @@ var tap = require('tap'); var spawn = require('child_process').spawn; var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; tap.test('requiring a single module', function (t) { t.plan(2); var tc = function (rows) { - t.same(rows.toString('utf8'), [ + t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# module-a', 'ok 1 loaded module a', @@ -20,8 +21,10 @@ tap.test('requiring a single module', function (t) { '# tests 3', '# pass 3', '', - '# ok' - ].join('\n') + '\n\n'); + '# ok', + '', + '' + ]); }; var ps = tape('-r ./require/a require/test-a.js'); diff --git a/test/stackTrace.js b/test/stackTrace.js index 99afa1bf..dd5e36cd 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -29,23 +29,23 @@ tap.test('preserves stack trace with newlines', function (tt) { stream.pipe(concat(function (body) { var strippedBody = stripAt(body.toString('utf8')); - tt.equal( - strippedBody, - 'TAP version 13\n' - + '# multiline stack trace\n' - + 'not ok 1 Error: Preserve stack\n' - + ' ---\n' - + ' operator: error\n' - + ' stack: |-\n' - + ' foo\n' - + ' bar\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + tt.deepEqual(strippedBody.split('\n'), [ + 'TAP version 13', + '# multiline stack trace', + 'not ok 1 Error: Preserve stack', + ' ---', + ' operator: error', + ' stack: |-', + ' foo', + ' bar', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); tt.deepEqual(getDiag(strippedBody), { stack: stackTrace, @@ -187,25 +187,24 @@ tap.test('preserves stack trace for failed assertions', function (tt) { stream.pipe(concat(function (body) { var strippedBody = stripAt(body.toString('utf8')); - tt.equal( - strippedBody, - 'TAP version 13\n' - + '# t.equal stack trace\n' - + 'not ok 1 true should be false\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: false\n' - + ' actual: true\n' - + ' stack: |-\n' - + ' ' - + stack.replace(/\n/g, '\n ') + '\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + tt.deepEqual(strippedBody.split('\n'), [].concat( + 'TAP version 13', + '# t.equal stack trace', + 'not ok 1 true should be false', + ' ---', + ' operator: equal', + ' expected: false', + ' actual: true', + ' stack: |-', + stack.split('\n').map(function (x) { return ' ' + x; }), + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + )); tt.deepEqual(getDiag(strippedBody), { stack: stack, @@ -251,25 +250,24 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun stream.pipe(concat(function (body) { var strippedBody = stripAt(body.toString('utf8')); - tt.equal( - strippedBody, - 'TAP version 13\n' - + '# t.equal stack trace\n' - + 'not ok 1 false should be true\n' - + ' ---\n' - + ' operator: equal\n' - + ' expected: true\n' - + ' actual: false\n' - + ' stack: |-\n' - + ' ' - + stack.replace(/\n/g, '\n ') + '\n' - + ' ...\n' - + '\n' - + '1..1\n' - + '# tests 1\n' - + '# pass 0\n' - + '# fail 1\n' - ); + tt.deepEqual(strippedBody.split('\n'), [].concat( + 'TAP version 13', + '# t.equal stack trace', + 'not ok 1 false should be true', + ' ---', + ' operator: equal', + ' expected: true', + ' actual: false', + ' stack: |-', + stack.split('\n').map(function (x) { return ' ' + x; }), + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + )); tt.deepEqual(getDiag(strippedBody), { stack: stack, diff --git a/test/too_many.js b/test/too_many.js index f6ba5582..dae8f36a 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -50,9 +50,9 @@ tap.test('array test', function (tt) { t.plan(3); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -62,10 +62,10 @@ tap.test('array test', function (tt) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] ]; Function(['fn', 'g'], output)( @@ -74,7 +74,7 @@ tap.test('array test', function (tt) { return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); });