From 2151e06877e65802ef7364bc6bebc21fc45e3699 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 17 Sep 2022 21:33:16 -0700 Subject: [PATCH] [eslint] fix indentation --- .eslintrc | 1 - bin/import-or-require.js | 10 +- bin/tape | 98 +-- example/array.js | 52 +- example/fail.js | 52 +- example/nested.js | 86 +- example/nested_fail.js | 86 +- example/not_enough_fail.js | 52 +- example/stream/object.js | 4 +- example/stream/tap.js | 2 +- example/stream/test/x_fail.js | 4 +- example/stream/test/y.js | 10 +- example/throw_fail.js | 8 +- example/timing.js | 12 +- example/too_many_fail.js | 52 +- example/two.js | 22 +- index.js | 304 +++---- lib/default_stream.js | 62 +- lib/results.js | 362 ++++---- lib/test.js | 1108 ++++++++++++------------ test/add-subtest-async.js | 14 +- test/anonymous-fn.js | 62 +- test/anonymous-fn/test-wrapper.js | 14 +- test/array.js | 108 +-- test/async-await.js | 500 +++++------ test/async-await/async-bug.js | 32 +- test/async-await/async-error.js | 8 +- test/async-await/async1.js | 20 +- test/async-await/async2.js | 18 +- test/async-await/async3.js | 10 +- test/async-await/async4.js | 22 +- test/async-await/async5.js | 100 +-- test/async-await/sync-error.js | 10 +- test/bound.js | 12 +- test/browser/asserts.js | 10 +- test/child_ordering.js | 68 +- test/circular-things.js | 68 +- test/comment.js | 318 +++---- test/common.js | 126 +-- test/create_multiple_streams.js | 50 +- test/deep-equal-failure.js | 354 ++++---- test/deep.js | 48 +- test/default-messages.js | 76 +- test/double_end.js | 98 +-- test/double_end/double.js | 12 +- test/edge-cases.js | 532 ++++++------ test/end-as-callback.js | 106 +-- test/error.js | 54 +- test/exit.js | 444 +++++----- test/exit/fail.js | 52 +- test/exit/missing_end.js | 6 +- test/exit/ok.js | 54 +- test/exit/second.js | 8 +- test/exit/todo.js | 4 +- test/exit/todo_fail.js | 4 +- test/exit/too_few.js | 52 +- test/exposed-harness.js | 6 +- test/fail.js | 124 +-- test/has spaces.js | 58 +- test/ignore/fake_node_modules/stub1.js | 4 +- test/ignore/fake_node_modules/stub2.js | 4 +- test/ignore/test.js | 4 +- test/ignore/test/stub1.js | 4 +- test/ignore/test/stub2.js | 4 +- test/ignore/test/sub/sub.stub1.js | 4 +- test/ignore/test/sub/sub.stub2.js | 4 +- test/ignore/test2.js | 4 +- test/ignore_from_gitignore.js | 192 ++-- test/import.js | 336 +++---- test/import/mjs-a.mjs | 6 +- test/import/mjs-b.mjs | 6 +- test/import/mjs-c.mjs | 6 +- test/import/mjs-d.mjs | 6 +- test/import/mjs-e.mjs | 6 +- test/import/mjs-f.mjs | 6 +- test/import/mjs-g.mjs | 6 +- test/import/mjs-h.mjs | 4 +- test/import/package_type/package-a.js | 6 +- test/import/package_type/package-b.js | 6 +- test/import/package_type/package-c.js | 4 +- test/many.js | 8 +- test/match.js | 456 +++++----- test/max_listeners.js | 2 +- test/max_listeners/source.js | 8 +- test/messages/defaults.js | 26 +- test/nested-async-plan-noend.js | 54 +- test/nested-sync-noplan-noend.js | 68 +- test/nested.js | 134 +-- test/nested2.js | 24 +- test/no_callback.js | 78 +- test/no_only.js | 156 ++-- test/no_only/test-a.js | 4 +- test/no_only/test-b.js | 8 +- test/not-deep-equal-failure.js | 354 ++++---- test/not-equal-failure.js | 106 +-- test/numerics.js | 334 +++---- test/objectMode.js | 106 +-- test/objectModeWithComment.js | 58 +- test/onFailure.js | 24 +- test/onFinish.js | 14 +- test/only-twice.js | 26 +- test/only.js | 80 +- test/only2.js | 4 +- test/only3.js | 10 +- test/only4.js | 6 +- test/only5.js | 6 +- test/order.js | 16 +- test/plan_optional.js | 12 +- test/promise_fail.js | 186 ++-- test/promises/fail.js | 22 +- test/promises/subTests.js | 26 +- test/require.js | 106 +-- test/require/a.js | 4 +- test/require/b.js | 4 +- test/require/test-a.js | 6 +- test/require/test-b.js | 6 +- test/skip.js | 60 +- test/skip_explanation.js | 128 +-- test/stackTrace.js | 536 ++++++------ test/subcount.js | 18 +- test/subtest_and_async.js | 32 +- test/subtest_plan.js | 26 +- test/teardown.js | 596 ++++++------- test/throws.js | 534 ++++++------ test/timeout.js | 14 +- test/timeoutAfter.js | 156 ++-- test/todo.js | 60 +- test/todo_explanation.js | 108 +-- test/todo_single.js | 52 +- test/too_many.js | 126 +-- test/undef.js | 64 +- 131 files changed, 5861 insertions(+), 5862 deletions(-) diff --git a/.eslintrc b/.eslintrc index e7dac3d2..ed08518d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,6 @@ "array-bracket-spacing": "off", "complexity": "off", "func-style": "warn", - "indent": ["error", 4], "no-magic-numbers": "off", "max-lines": "warn", "max-lines-per-function": "warn", diff --git a/bin/import-or-require.js b/bin/import-or-require.js index 99ce1b26..be9e8e50 100644 --- a/bin/import-or-require.js +++ b/bin/import-or-require.js @@ -6,10 +6,10 @@ const getPackageType = require('get-package-type'); // eslint-disable-next-line consistent-return module.exports = function importOrRequire(file) { - const ext = extnamePath(file); + const ext = extnamePath(file); - if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module')) { - return import(pathToFileURL(file).href); - } - require(file); + if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module')) { + return import(pathToFileURL(file).href); + } + require(file); }; diff --git a/bin/tape b/bin/tape index d8c5b095..3f713be2 100755 --- a/bin/tape +++ b/bin/tape @@ -6,30 +6,30 @@ var parseOpts = require('minimist'); var objectKeys = require('object-keys'); var opts = parseOpts(process.argv.slice(2), { - alias: { r: 'require', i: 'ignore' }, - string: ['require', 'ignore'], - boolean: ['only'], - default: { r: [], i: null, only: null } + alias: { r: 'require', i: 'ignore' }, + string: ['require', 'ignore'], + boolean: ['only'], + default: { r: [], i: null, only: null } }); if (typeof opts.only === 'boolean') { - process.env.NODE_TAPE_NO_ONLY_TEST = !opts.only; + process.env.NODE_TAPE_NO_ONLY_TEST = !opts.only; } var cwd = process.cwd(); if (typeof opts.require === 'string') { - opts.require = [opts.require]; + opts.require = [opts.require]; } var resolveModule; opts.require.forEach(function (module) { - var options = { basedir: cwd, extensions: objectKeys(require.extensions) }; - if (module) { - if (!resolveModule) { resolveModule = require('resolve').sync; } - // This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing. - require(resolveModule(module, options)); - } + var options = { basedir: cwd, extensions: objectKeys(require.extensions) }; + if (module) { + if (!resolveModule) { resolveModule = require('resolve').sync; } + // This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing. + require(resolveModule(module, options)); + } }); var resolvePath = require('path').resolve; @@ -37,64 +37,64 @@ var requireResolve = require.resolve; var matcher; if (typeof opts.ignore === 'string') { - var readFileSync = require('fs').readFileSync; - try { - var ignoreStr = readFileSync(resolvePath(cwd, opts.ignore || '.gitignore'), 'utf-8'); - } catch (e) { - console.error(e.message); - process.exit(2); - } - var ignore = require('dotignore'); - matcher = ignore.createMatcher(ignoreStr); + var readFileSync = require('fs').readFileSync; + try { + var ignoreStr = readFileSync(resolvePath(cwd, opts.ignore || '.gitignore'), 'utf-8'); + } catch (e) { + console.error(e.message); + process.exit(2); + } + var ignore = require('dotignore'); + matcher = ignore.createMatcher(ignoreStr); } var glob = require('glob'); var files = opts._.reduce(function (result, arg) { - if (glob.hasMagic(arg)) { - // If glob does not match, `files` will be an empty array. - // Note: `glob.sync` may throw an error and crash the node process. - var globFiles = glob.sync(arg); - - if (!Array.isArray(globFiles)) { - throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.'); - } - - return result.concat(globFiles); - } - return result.concat(arg); + if (glob.hasMagic(arg)) { + // If glob does not match, `files` will be an empty array. + // Note: `glob.sync` may throw an error and crash the node process. + var globFiles = glob.sync(arg); + + if (!Array.isArray(globFiles)) { + throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.'); + } + + return result.concat(globFiles); + } + return result.concat(arg); }, []).filter(function (file) { - return !matcher || !matcher.shouldIgnore(file); + return !matcher || !matcher.shouldIgnore(file); }).map(function (file) { - return requireResolve(resolvePath(cwd, file)); + return requireResolve(resolvePath(cwd, file)); }); var hasImport = require('has-dynamic-import'); hasImport().then(function (hasSupport) { - // the nextTick callback gets called outside the promise chain, avoiding - // promises and unhandled rejections when only loading commonjs files - process.nextTick(importFiles, hasSupport); + // the nextTick callback gets called outside the promise chain, avoiding + // promises and unhandled rejections when only loading commonjs files + process.nextTick(importFiles, hasSupport); }); var tape = require('../'); function importFiles(hasSupport) { - if (!hasSupport) { - return files.forEach(function (x) { require(x); }); - } + if (!hasSupport) { + return files.forEach(function (x) { require(x); }); + } - var importOrRequire = require('./import-or-require'); + var importOrRequire = require('./import-or-require'); - tape.wait(); + tape.wait(); - var filesPromise = files.reduce(function (promise, file) { - return promise ? promise.then(function () { - return importOrRequire(file); - }) : importOrRequire(file); - }, null); + var filesPromise = files.reduce(function (promise, file) { + return promise ? promise.then(function () { + return importOrRequire(file); + }) : importOrRequire(file); + }, null); - return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run(); + return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run(); } // vim: ft=javascript diff --git a/example/array.js b/example/array.js index 40be4847..d4340380 100644 --- a/example/array.js +++ b/example/array.js @@ -4,34 +4,34 @@ var falafel = require('falafel'); var test = require('../'); test('array', function (t) { - t.plan(5); + t.plan(5); - var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); - } + ')()'; + var src = '(' + function () { + var xs = [ 1, 2, [ 3, 4 ] ]; + var ys = [ 5, 6 ]; + g([ xs, ys ]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[ 1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[ 1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + } + ); }); diff --git a/example/fail.js b/example/fail.js index 4373c76b..78dd7bca 100644 --- a/example/fail.js +++ b/example/fail.js @@ -4,34 +4,34 @@ var falafel = require('falafel'); var test = require('../'); test('array', function (t) { - t.plan(5); + t.plan(5); - var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); - } + ')()'; + var src = '(' + function () { + var xs = [ 1, 2, [ 3, 4 ] ]; + var ys = [ 5, 6 ]; + g([ xs, ys ]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] - ]; + var arrays = [ + [ 3, 4 ], + [ 1, 2, [ 3, 4 ] ], + [ 5, 6 ], + [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + } + ); }); diff --git a/example/nested.js b/example/nested.js index 59dbd54b..2c5a6bcb 100644 --- a/example/nested.js +++ b/example/nested.js @@ -4,50 +4,50 @@ var falafel = require('falafel'); var test = require('../'); test('nested array test', function (t) { - t.plan(6); - - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([ xs, ys ]); - } + ')()'; - - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); - - t.test('inside test', function (q) { - q.plan(2); - q.ok(true, 'inside ok'); - - setTimeout(function () { - q.ok(true, 'inside delayed'); - }, 3000); - }); - - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; - - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); + t.plan(6); + + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([ xs, ys ]); + } + ')()'; + + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); + + t.test('inside test', function (q) { + q.plan(2); + q.ok(true, 'inside ok'); + + setTimeout(function () { + q.ok(true, 'inside delayed'); + }, 3000); + }); + + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; + + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); }); test('another', function (t) { - t.plan(1); - setTimeout(function () { - t.ok(true); - }, 100); + t.plan(1); + setTimeout(function () { + t.ok(true); + }, 100); }); diff --git a/example/nested_fail.js b/example/nested_fail.js index 44ea3fd1..ef0e9fd9 100644 --- a/example/nested_fail.js +++ b/example/nested_fail.js @@ -4,50 +4,50 @@ var falafel = require('falafel'); var test = require('../'); test('nested array test', function (t) { - t.plan(5); - - var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); - } + ')()'; - - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); - - t.test('inside test', function (q) { - q.plan(2); - q.ok(true); - - setTimeout(function () { - q.equal(3, 4); - }, 3000); - }); - - var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] - ]; - - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); - } - ); + t.plan(5); + + var src = '(' + function () { + var xs = [ 1, 2, [ 3, 4 ] ]; + var ys = [ 5, 6 ]; + g([ xs, ys ]); + } + ')()'; + + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); + + t.test('inside test', function (q) { + q.plan(2); + q.ok(true); + + setTimeout(function () { + q.equal(3, 4); + }, 3000); + }); + + var arrays = [ + [ 3, 4 ], + [ 1, 2, [ 3, 4 ] ], + [ 5, 6 ], + [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ] + ]; + + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + } + ); }); test('another', function (t) { - t.plan(1); - setTimeout(function () { - t.ok(true); - }, 100); + t.plan(1); + setTimeout(function () { + t.ok(true); + }, 100); }); diff --git a/example/not_enough_fail.js b/example/not_enough_fail.js index ecd2dce1..c9bffd2a 100644 --- a/example/not_enough_fail.js +++ b/example/not_enough_fail.js @@ -4,34 +4,34 @@ var falafel = require('falafel'); var test = require('../'); test('array', function (t) { - t.plan(8); + t.plan(8); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); }); diff --git a/example/stream/object.js b/example/stream/object.js index 39c662ce..ebed86e3 100644 --- a/example/stream/object.js +++ b/example/stream/object.js @@ -4,9 +4,9 @@ var test = require('../../'); var path = require('path'); test.createStream({ objectMode: true }).on('data', function (row) { - console.log(JSON.stringify(row)); + console.log(JSON.stringify(row)); }); process.argv.slice(2).forEach(function (file) { - require(path.resolve(file)); + require(path.resolve(file)); }); diff --git a/example/stream/tap.js b/example/stream/tap.js index 53d7e232..84f1cd8a 100644 --- a/example/stream/tap.js +++ b/example/stream/tap.js @@ -6,5 +6,5 @@ var path = require('path'); test.createStream().pipe(process.stdout); process.argv.slice(2).forEach(function (file) { - require(path.resolve(file)); + require(path.resolve(file)); }); diff --git a/example/stream/test/x_fail.js b/example/stream/test/x_fail.js index 670baa56..40ef5e4d 100644 --- a/example/stream/test/x_fail.js +++ b/example/stream/test/x_fail.js @@ -2,6 +2,6 @@ var test = require('../../../'); test(function (t) { - t.plan(1); - t.equal('beep', 'boop'); + t.plan(1); + t.equal('beep', 'boop'); }); diff --git a/example/stream/test/y.js b/example/stream/test/y.js index 0a0928f2..06194fb0 100644 --- a/example/stream/test/y.js +++ b/example/stream/test/y.js @@ -2,12 +2,12 @@ var test = require('../../../'); test(function (t) { - t.plan(2); - t.equal(1 + 1, 2); - t.ok(true); + t.plan(2); + t.equal(1 + 1, 2); + t.ok(true); }); test('wheee', function (t) { - t.ok(true); - t.end(); + t.ok(true); + t.end(); }); diff --git a/example/throw_fail.js b/example/throw_fail.js index ef82c3ae..eeacc5e4 100644 --- a/example/throw_fail.js +++ b/example/throw_fail.js @@ -3,9 +3,9 @@ var test = require('../'); test('throw', function (t) { - t.plan(2); + t.plan(2); - setTimeout(function () { - throw new Error('doom'); - }, 100); + setTimeout(function () { + throw new Error('doom'); + }, 100); }); diff --git a/example/timing.js b/example/timing.js index ba97963a..f51f64de 100644 --- a/example/timing.js +++ b/example/timing.js @@ -3,12 +3,12 @@ var test = require('../'); test('timing test', function (t) { - t.plan(2); + t.plan(2); - t.equal(typeof Date.now, 'function'); - var start = Date.now(); + t.equal(typeof Date.now, 'function'); + var start = Date.now(); - setTimeout(function () { - t.ok(Date.now() - start > 100); - }, 100); + setTimeout(function () { + t.ok(Date.now() - start > 100); + }, 100); }); diff --git a/example/too_many_fail.js b/example/too_many_fail.js index 2ae76502..8f0c5be4 100644 --- a/example/too_many_fail.js +++ b/example/too_many_fail.js @@ -4,34 +4,34 @@ var falafel = require('falafel'); var test = require('../'); test('array', function (t) { - t.plan(3); + t.plan(3); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([ xs, ys ]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([ xs, ys ]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); }); diff --git a/example/two.js b/example/two.js index de5b213a..79424c13 100644 --- a/example/two.js +++ b/example/two.js @@ -3,18 +3,18 @@ var test = require('../'); test('one', function (t) { - t.plan(2); - t.ok(true); - setTimeout(function () { - t.equal(1 + 3, 4); - }, 100); + t.plan(2); + t.ok(true); + setTimeout(function () { + t.equal(1 + 3, 4); + }, 100); }); test('two', function (t) { - t.plan(3); - t.equal(5, 2 + 3); - setTimeout(function () { - t.equal('a'.charCodeAt(0), 97); - t.ok(true); - }, 50); + t.plan(3); + t.equal(5, 2 + 3); + setTimeout(function () { + t.equal('a'.charCodeAt(0), 97); + t.ok(true); + }, 50); }); diff --git a/index.js b/index.js index f1427b82..4b9fd673 100644 --- a/index.js +++ b/index.js @@ -12,110 +12,110 @@ var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function'; module.exports = (function () { - var wait = false; - var harness; - var lazyLoad = function () { - // eslint-disable-next-line no-invalid-this - return getHarness().apply(this, arguments); - }; - - lazyLoad.wait = function () { - wait = true; - }; - - lazyLoad.run = function () { - var run = getHarness().run; - - if (run) { run(); } - }; - - lazyLoad.only = function () { - return getHarness().only.apply(this, arguments); - }; - - lazyLoad.createStream = function (opts) { - var options = opts || {}; - if (!harness) { - var output = through(); - getHarness({ stream: output, objectMode: options.objectMode }); - return output; - } - return harness.createStream(options); - }; - - lazyLoad.onFinish = function () { - return getHarness().onFinish.apply(this, arguments); - }; - - lazyLoad.onFailure = function () { - return getHarness().onFailure.apply(this, arguments); - }; - - lazyLoad.getHarness = getHarness; - - return lazyLoad; - - function getHarness(opts) { - if (!opts) { opts = {}; } - opts.autoclose = !canEmitExit; - if (!harness) { harness = createExitHarness(opts, wait); } - return harness; - } + var wait = false; + var harness; + var lazyLoad = function () { + // eslint-disable-next-line no-invalid-this + return getHarness().apply(this, arguments); + }; + + lazyLoad.wait = function () { + wait = true; + }; + + lazyLoad.run = function () { + var run = getHarness().run; + + if (run) { run(); } + }; + + lazyLoad.only = function () { + return getHarness().only.apply(this, arguments); + }; + + lazyLoad.createStream = function (opts) { + var options = opts || {}; + if (!harness) { + var output = through(); + getHarness({ stream: output, objectMode: options.objectMode }); + return output; + } + return harness.createStream(options); + }; + + lazyLoad.onFinish = function () { + return getHarness().onFinish.apply(this, arguments); + }; + + lazyLoad.onFailure = function () { + return getHarness().onFailure.apply(this, arguments); + }; + + lazyLoad.getHarness = getHarness; + + return lazyLoad; + + function getHarness(opts) { + if (!opts) { opts = {}; } + opts.autoclose = !canEmitExit; + if (!harness) { harness = createExitHarness(opts, wait); } + return harness; + } }()); function createExitHarness(conf, wait) { - var config = conf || {}; - var harness = createHarness({ - autoclose: defined(config.autoclose, false), - noOnly: defined(conf.noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false)) - }); - var running = false; - var ended = false; - - if (wait) { - harness.run = run; - } else { - run(); - } - - if (config.exit === false) { return harness; } - if (!canEmitExit || !canExit) { return harness; } - - process.on('exit', function (code) { - // let the process exit cleanly. - if (typeof code === 'number' && code !== 0) { - return; - } - - if (!ended) { - var only = harness._results._only; - for (var i = 0; i < harness._tests.length; i++) { - var t = harness._tests[i]; - if (!only || t === only) { - t._exit(); - } - } - } - harness.close(); - - process.removeAllListeners('exit'); // necessary for node v0.6 - process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit - }); - - return harness; - - function run() { - if (running) { return; } - running = true; - var stream = harness.createStream({ objectMode: config.objectMode }); - var es = stream.pipe(config.stream || createDefaultStream()); - if (canEmitExit && es) { // in node v0.4, `es` is `undefined` - // TODO: use `err` arg? - // eslint-disable-next-line no-unused-vars - es.on('error', function (err) { harness._exitCode = 1; }); - } - stream.on('end', function () { ended = true; }); - } + var config = conf || {}; + var harness = createHarness({ + autoclose: defined(config.autoclose, false), + noOnly: defined(conf.noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false)) + }); + var running = false; + var ended = false; + + if (wait) { + harness.run = run; + } else { + run(); + } + + if (config.exit === false) { return harness; } + if (!canEmitExit || !canExit) { return harness; } + + process.on('exit', function (code) { + // let the process exit cleanly. + if (typeof code === 'number' && code !== 0) { + return; + } + + if (!ended) { + var only = harness._results._only; + for (var i = 0; i < harness._tests.length; i++) { + var t = harness._tests[i]; + if (!only || t === only) { + t._exit(); + } + } + } + harness.close(); + + process.removeAllListeners('exit'); // necessary for node v0.6 + process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit + }); + + return harness; + + function run() { + if (running) { return; } + running = true; + var stream = harness.createStream({ objectMode: config.objectMode }); + var es = stream.pipe(config.stream || createDefaultStream()); + if (canEmitExit && es) { // in node v0.4, `es` is `undefined` + // TODO: use `err` arg? + // eslint-disable-next-line no-unused-vars + es.on('error', function (err) { harness._exitCode = 1; }); + } + stream.on('end', function () { ended = true; }); + } } module.exports.createHarness = createHarness; @@ -124,55 +124,55 @@ module.exports.test = module.exports; // tap compat module.exports.test.skip = Test.skip; function createHarness(conf_) { - var results = createResult(); - if (!conf_ || conf_.autoclose !== false) { - results.once('done', function () { results.close(); }); - } - - var test = function (name, conf, cb) { - var t = new Test(name, conf, cb); - test._tests.push(t); - - (function inspectCode(st) { - st.on('test', function sub(st_) { - inspectCode(st_); - }); - st.on('result', function (r) { - if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; } - }); - }(t)); - - results.push(t); - return t; - }; - test._results = results; - - test._tests = []; - - test.createStream = function (opts) { - return results.createStream(opts); - }; - - test.onFinish = function (cb) { - results.on('done', cb); - }; - - test.onFailure = function (cb) { - results.on('fail', cb); - }; - - var only = false; - test.only = function () { - if (only) { throw new Error('there can only be one only test'); } - if (conf_.noOnly) { throw new Error('`only` tests are prohibited'); } - only = true; - var t = test.apply(null, arguments); - results.only(t); - return t; - }; - test._exitCode = 0; - - test.close = function () { results.close(); }; - - return test; + var results = createResult(); + if (!conf_ || conf_.autoclose !== false) { + results.once('done', function () { results.close(); }); + } + + var test = function (name, conf, cb) { + var t = new Test(name, conf, cb); + test._tests.push(t); + + (function inspectCode(st) { + st.on('test', function sub(st_) { + inspectCode(st_); + }); + st.on('result', function (r) { + if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; } + }); + }(t)); + + results.push(t); + return t; + }; + test._results = results; + + test._tests = []; + + test.createStream = function (opts) { + return results.createStream(opts); + }; + + test.onFinish = function (cb) { + results.on('done', cb); + }; + + test.onFailure = function (cb) { + results.on('fail', cb); + }; + + var only = false; + test.only = function () { + if (only) { throw new Error('there can only be one only test'); } + if (conf_.noOnly) { throw new Error('`only` tests are prohibited'); } + only = true; + var t = test.apply(null, arguments); + results.only(t); + return t; + }; + test._exitCode = 0; + + test.close = function () { results.close(); }; + + return test; } diff --git a/lib/default_stream.js b/lib/default_stream.js index 9e6372ec..2b355548 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -4,37 +4,37 @@ var through = require('through'); var fs = require('fs'); module.exports = function () { - var line = ''; - var stream = through(write, flush); - return stream; + var line = ''; + var stream = through(write, flush); + return stream; - function write(buf) { - for (var i = 0; i < buf.length; i++) { - var c = typeof buf === 'string' - ? buf.charAt(i) - : String.fromCharCode(buf[i]); - if (c === '\n') { - flush(); - } else { - line += c; - } - } - } + function write(buf) { + for (var i = 0; i < buf.length; i++) { + var c = typeof buf === 'string' + ? buf.charAt(i) + : String.fromCharCode(buf[i]); + if (c === '\n') { + flush(); + } else { + line += c; + } + } + } - function flush() { - if (fs.writeSync && (/^win/).test(process.platform)) { - try { - fs.writeSync(1, line + '\n'); - } catch (e) { - stream.emit('error', e); - } - } else { - try { - console.log(line); // eslint-disable-line no-console - } catch (e) { - stream.emit('error', e); - } - } - line = ''; - } + function flush() { + if (fs.writeSync && (/^win/).test(process.platform)) { + try { + fs.writeSync(1, line + '\n'); + } catch (e) { + stream.emit('error', e); + } + } else { + try { + console.log(line); // eslint-disable-line no-console + } catch (e) { + stream.emit('error', e); + } + } + line = ''; + } }; diff --git a/lib/results.js b/lib/results.js index c13f2c22..5a120baa 100644 --- a/lib/results.js +++ b/lib/results.js @@ -15,216 +15,216 @@ var $shift = callBound('Array.prototype.shift'); var $push = callBound('Array.prototype.push'); var yamlIndicators = /:|-|\?/; var nextTick = typeof setImmediate !== 'undefined' - ? setImmediate - : process.nextTick; + ? setImmediate + : process.nextTick; module.exports = Results; inherits(Results, EventEmitter); function coalesceWhiteSpaces(str) { - return $replace(String(str), /\s+/g, ' '); + return $replace(String(str), /\s+/g, ' '); } function Results() { - if (!(this instanceof Results)) { return new Results(); } - this.count = 0; - this.fail = 0; - this.pass = 0; - this.todo = 0; - this._stream = through(); - this.tests = []; - this._only = null; - this._isRunning = false; + if (!(this instanceof Results)) { return new Results(); } + this.count = 0; + this.fail = 0; + this.pass = 0; + this.todo = 0; + this._stream = through(); + this.tests = []; + this._only = null; + this._isRunning = false; } Results.prototype.createStream = function (opts) { - if (!opts) { opts = {}; } - var self = this; - var output; - var testId = 0; - if (opts.objectMode) { - output = through(); - self.on('_push', function ontest(t, extra) { - if (!extra) { extra = {}; } - var id = testId++; - t.once('prerun', function () { - var row = { - type: 'test', - name: t.name, - id: id, - skip: t._skip, - todo: t._todo - }; - if (has(extra, 'parent')) { - row.parent = extra.parent; - } - output.queue(row); - }); - t.on('test', function (st) { - ontest(st, { parent: id }); - }); - t.on('result', function (res) { - if (res && typeof res === 'object') { - res.test = id; - res.type = 'assert'; - } - output.queue(res); - }); - t.on('end', function () { - output.queue({ type: 'end', test: id }); - }); - }); - self.on('done', function () { output.queue(null); }); - } else { - output = resumer(); - output.queue('TAP version 13\n'); - self._stream.pipe(output); - } - - if (!this._isRunning) { - this._isRunning = true; - nextTick(function next() { - var t; - while (t = getNextTest(self)) { - t.run(); - if (!t.ended) { - t.once('end', function () { nextTick(next); }); - return; - } - } - self.emit('done'); - }); - } - - return output; + if (!opts) { opts = {}; } + var self = this; + var output; + var testId = 0; + if (opts.objectMode) { + output = through(); + self.on('_push', function ontest(t, extra) { + if (!extra) { extra = {}; } + var id = testId++; + t.once('prerun', function () { + var row = { + type: 'test', + name: t.name, + id: id, + skip: t._skip, + todo: t._todo + }; + if (has(extra, 'parent')) { + row.parent = extra.parent; + } + output.queue(row); + }); + t.on('test', function (st) { + ontest(st, { parent: id }); + }); + t.on('result', function (res) { + if (res && typeof res === 'object') { + res.test = id; + res.type = 'assert'; + } + output.queue(res); + }); + t.on('end', function () { + output.queue({ type: 'end', test: id }); + }); + }); + self.on('done', function () { output.queue(null); }); + } else { + output = resumer(); + output.queue('TAP version 13\n'); + self._stream.pipe(output); + } + + if (!this._isRunning) { + this._isRunning = true; + nextTick(function next() { + var t; + while (t = getNextTest(self)) { + t.run(); + if (!t.ended) { + t.once('end', function () { nextTick(next); }); + return; + } + } + self.emit('done'); + }); + } + + return output; }; Results.prototype.push = function (t) { - var self = this; - $push(self.tests, t); - self._watch(t); - self.emit('_push', t); + var self = this; + $push(self.tests, t); + self._watch(t); + self.emit('_push', t); }; Results.prototype.only = function (t) { - this._only = t; + this._only = t; }; Results.prototype._watch = function (t) { - var self = this; - var write = function (s) { self._stream.queue(s); }; - t.once('prerun', function () { - var premsg = ''; - if (t._skip) { - premsg = 'SKIP '; - } else if (t._todo) { - premsg = 'TODO '; - } - write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n'); - }); - - t.on('result', function (res) { - if (typeof res === 'string') { - write('# ' + res + '\n'); - return; - } - write(encodeResult(res, self.count + 1)); - self.count++; - - if (res.ok || res.todo) { - self.pass++; - } else { - self.fail++; - self.emit('fail'); - } - }); - - t.on('test', function (st) { self._watch(st); }); + var self = this; + var write = function (s) { self._stream.queue(s); }; + t.once('prerun', function () { + var premsg = ''; + if (t._skip) { + premsg = 'SKIP '; + } else if (t._todo) { + premsg = 'TODO '; + } + write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n'); + }); + + t.on('result', function (res) { + if (typeof res === 'string') { + write('# ' + res + '\n'); + return; + } + write(encodeResult(res, self.count + 1)); + self.count++; + + if (res.ok || res.todo) { + self.pass++; + } else { + self.fail++; + self.emit('fail'); + } + }); + + t.on('test', function (st) { self._watch(st); }); }; Results.prototype.close = function () { - var self = this; - if (self.closed) { self._stream.emit('error', new Error('ALREADY CLOSED')); } - self.closed = true; - var write = function (s) { self._stream.queue(s); }; - - write('\n1..' + self.count + '\n'); - write('# tests ' + self.count + '\n'); - write('# pass ' + (self.pass + self.todo) + '\n'); - if (self.todo) { write('# todo ' + self.todo + '\n'); } - if (self.fail) { - write('# fail ' + self.fail + '\n'); - } else { - write('\n# ok\n'); - } - - self._stream.queue(null); + var self = this; + if (self.closed) { self._stream.emit('error', new Error('ALREADY CLOSED')); } + self.closed = true; + var write = function (s) { self._stream.queue(s); }; + + write('\n1..' + self.count + '\n'); + write('# tests ' + self.count + '\n'); + write('# pass ' + (self.pass + self.todo) + '\n'); + if (self.todo) { write('# todo ' + self.todo + '\n'); } + if (self.fail) { + write('# fail ' + self.fail + '\n'); + } else { + write('\n# ok\n'); + } + + self._stream.queue(null); }; function encodeResult(res, count) { - var output = ''; - output += (res.ok ? 'ok ' : 'not ok ') + count; - output += res.name ? ' ' + coalesceWhiteSpaces(res.name) : ''; - - if (res.skip) { - output += ' # SKIP' + (typeof res.skip === 'string' ? ' ' + coalesceWhiteSpaces(res.skip) : ''); - } else if (res.todo) { - output += ' # TODO' + (typeof res.todo === 'string' ? ' ' + coalesceWhiteSpaces(res.todo) : ''); - } - - output += '\n'; - if (res.ok) { return output; } - - var outer = ' '; - var inner = outer + ' '; - output += outer + '---\n'; - output += inner + 'operator: ' + res.operator + '\n'; - - if (has(res, 'expected') || has(res, 'actual')) { - var ex = inspect(res.expected, { depth: res.objectPrintDepth }); - var ac = inspect(res.actual, { depth: res.objectPrintDepth }); - - if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) { - output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n'; - output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n'; - } else { - output += inner + 'expected: ' + ex + '\n'; - output += inner + 'actual: ' + ac + '\n'; - } - } - if (res.at) { - output += inner + 'at: ' + res.at + '\n'; - } - - var actualStack = res.actual && (typeof res.actual === 'object' || typeof res.actual === 'function') ? res.actual.stack : undefined; - var errorStack = res.error && res.error.stack; - var stack = defined(actualStack, errorStack); - if (stack) { - var lines = $split(String(stack), '\n'); - output += inner + 'stack: |-\n'; - for (var i = 0; i < lines.length; i++) { - output += inner + ' ' + lines[i] + '\n'; - } - } - - output += outer + '...\n'; - return output; + var output = ''; + output += (res.ok ? 'ok ' : 'not ok ') + count; + output += res.name ? ' ' + coalesceWhiteSpaces(res.name) : ''; + + if (res.skip) { + output += ' # SKIP' + (typeof res.skip === 'string' ? ' ' + coalesceWhiteSpaces(res.skip) : ''); + } else if (res.todo) { + output += ' # TODO' + (typeof res.todo === 'string' ? ' ' + coalesceWhiteSpaces(res.todo) : ''); + } + + output += '\n'; + if (res.ok) { return output; } + + var outer = ' '; + var inner = outer + ' '; + output += outer + '---\n'; + output += inner + 'operator: ' + res.operator + '\n'; + + if (has(res, 'expected') || has(res, 'actual')) { + var ex = inspect(res.expected, { depth: res.objectPrintDepth }); + var ac = inspect(res.actual, { depth: res.objectPrintDepth }); + + if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) { + output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n'; + output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n'; + } else { + output += inner + 'expected: ' + ex + '\n'; + output += inner + 'actual: ' + ac + '\n'; + } + } + if (res.at) { + output += inner + 'at: ' + res.at + '\n'; + } + + var actualStack = res.actual && (typeof res.actual === 'object' || typeof res.actual === 'function') ? res.actual.stack : undefined; + var errorStack = res.error && res.error.stack; + var stack = defined(actualStack, errorStack); + if (stack) { + var lines = $split(String(stack), '\n'); + output += inner + 'stack: |-\n'; + for (var i = 0; i < lines.length; i++) { + output += inner + ' ' + lines[i] + '\n'; + } + } + + output += outer + '...\n'; + return output; } function getNextTest(results) { - if (!results._only) { - return $shift(results.tests); - } - - do { - var t = $shift(results.tests); - if (t && results._only === t) { - return t; - } - } while (results.tests.length !== 0); - - return void undefined; + if (!results._only) { + return $shift(results.tests); + } + + do { + var t = $shift(results.tests); + if (t && results._only === t) { + return t; + } + } while (results.tests.length !== 0); + + return void undefined; } function invalidYaml(str) { - return $exec(yamlIndicators, str) !== null; + return $exec(yamlIndicators, str) !== null; } diff --git a/lib/test.js b/lib/test.js index 188e0e9b..bcac77d5 100644 --- a/lib/test.js +++ b/lib/test.js @@ -29,8 +29,8 @@ var $shift = callBound('Array.prototype.shift'); module.exports = Test; var nextTick = typeof setImmediate !== 'undefined' - ? setImmediate - : process.nextTick; + ? setImmediate + : process.nextTick; var safeSetTimeout = setTimeout; var safeClearTimeout = clearTimeout; @@ -38,289 +38,289 @@ inherits(Test, EventEmitter); // eslint-disable-next-line no-unused-vars var getTestArgs = function (name_, opts_, cb_) { - var name = '(anonymous)'; - var opts = {}; - var cb; - - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; - var t = typeof arg; - if (t === 'string') { - name = arg; - } else if (t === 'object') { - opts = arg || opts; - } else if (t === 'function') { - cb = arg; - } - } - return { - name: name, - opts: opts, - cb: cb - }; + var name = '(anonymous)'; + var opts = {}; + var cb; + + for (var i = 0; i < arguments.length; i++) { + var arg = arguments[i]; + var t = typeof arg; + if (t === 'string') { + name = arg; + } else if (t === 'object') { + opts = arg || opts; + } else if (t === 'function') { + cb = arg; + } + } + return { + name: name, + opts: opts, + cb: cb + }; }; function Test(name_, opts_, cb_) { - if (!(this instanceof Test)) { - return new Test(name_, opts_, cb_); - } - - var args = getTestArgs(name_, opts_, cb_); - - this.readable = true; - this.name = args.name || '(anonymous)'; - this.assertCount = 0; - this.pendingCount = 0; - this._skip = args.opts.skip || false; - this._todo = args.opts.todo || false; - this._timeout = args.opts.timeout; - this._plan = undefined; - this._cb = args.cb; - this._progeny = []; - this._teardown = []; - this._ok = true; - var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH; - if (args.opts.objectPrintDepth) { - this._objectPrintDepth = args.opts.objectPrintDepth; - } else if (depthEnvVar) { - if (toLowerCase(depthEnvVar) === 'infinity') { - this._objectPrintDepth = Infinity; - } else { - this._objectPrintDepth = depthEnvVar; - } - } else { - this._objectPrintDepth = 5; - } - - for (var prop in this) { - this[prop] = (function bind(self, val) { - if (typeof val === 'function') { - return function bound() { - return val.apply(self, arguments); - }; - } - return val; - }(this, this[prop])); - } + if (!(this instanceof Test)) { + return new Test(name_, opts_, cb_); + } + + var args = getTestArgs(name_, opts_, cb_); + + this.readable = true; + this.name = args.name || '(anonymous)'; + this.assertCount = 0; + this.pendingCount = 0; + this._skip = args.opts.skip || false; + this._todo = args.opts.todo || false; + this._timeout = args.opts.timeout; + this._plan = undefined; + this._cb = args.cb; + this._progeny = []; + this._teardown = []; + this._ok = true; + var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH; + if (args.opts.objectPrintDepth) { + this._objectPrintDepth = args.opts.objectPrintDepth; + } else if (depthEnvVar) { + if (toLowerCase(depthEnvVar) === 'infinity') { + this._objectPrintDepth = Infinity; + } else { + this._objectPrintDepth = depthEnvVar; + } + } else { + this._objectPrintDepth = 5; + } + + for (var prop in this) { + this[prop] = (function bind(self, val) { + if (typeof val === 'function') { + return function bound() { + return val.apply(self, arguments); + }; + } + return val; + }(this, this[prop])); + } } Test.prototype.run = function run() { - this.emit('prerun'); - if (!this._cb || this._skip) { - this._end(); - return; - } - if (this._timeout != null) { - this.timeoutAfter(this._timeout); - } - - var callbackReturn = this._cb(this); - - if ( - typeof Promise === 'function' + this.emit('prerun'); + if (!this._cb || this._skip) { + this._end(); + return; + } + if (this._timeout != null) { + this.timeoutAfter(this._timeout); + } + + var callbackReturn = this._cb(this); + + if ( + typeof Promise === 'function' && callbackReturn && typeof callbackReturn.then === 'function' - ) { - var self = this; - Promise.resolve(callbackReturn).then(function onResolve() { - if (!self.calledEnd) { - self.end(); - } - })['catch'](function onError(err) { - if (err instanceof Error || objectToString(err) === '[object Error]') { - self.ifError(err); - } else { - self.fail(err); - } - self.end(); - }); - return; - } - - this.emit('run'); + ) { + var self = this; + Promise.resolve(callbackReturn).then(function onResolve() { + if (!self.calledEnd) { + self.end(); + } + })['catch'](function onError(err) { + if (err instanceof Error || objectToString(err) === '[object Error]') { + self.ifError(err); + } else { + self.fail(err); + } + self.end(); + }); + return; + } + + this.emit('run'); }; Test.prototype.test = function test(name, opts, cb) { - var self = this; - var t = new Test(name, opts, cb); - $push(this._progeny, t); - this.pendingCount++; - this.emit('test', t); - t.on('prerun', function () { - self.assertCount++; - }); - - if (!self._pendingAsserts()) { - nextTick(function () { - self._end(); - }); - } - - nextTick(function () { - if (!self._plan && self.pendingCount == self._progeny.length) { - self._end(); - } - }); + var self = this; + var t = new Test(name, opts, cb); + $push(this._progeny, t); + this.pendingCount++; + this.emit('test', t); + t.on('prerun', function () { + self.assertCount++; + }); + + if (!self._pendingAsserts()) { + nextTick(function () { + self._end(); + }); + } + + nextTick(function () { + if (!self._plan && self.pendingCount == self._progeny.length) { + self._end(); + } + }); }; Test.prototype.comment = function comment(msg) { - var that = this; - forEach($split(trim(msg), '\n'), function (aMsg) { - that.emit('result', $replace(trim(aMsg), /^#\s*/, '')); - }); + var that = this; + forEach($split(trim(msg), '\n'), function (aMsg) { + that.emit('result', $replace(trim(aMsg), /^#\s*/, '')); + }); }; Test.prototype.plan = function plan(n) { - this._plan = n; - this.emit('plan', n); + this._plan = n; + this.emit('plan', n); }; Test.prototype.timeoutAfter = function timeoutAfter(ms) { - if (!ms) { throw new Error('timeoutAfter requires a timespan'); } - var self = this; - var timeout = safeSetTimeout(function () { - self.fail(self.name + ' timed out after ' + ms + 'ms'); - self.end(); - }, ms); - this.once('end', function () { - safeClearTimeout(timeout); - }); + if (!ms) { throw new Error('timeoutAfter requires a timespan'); } + var self = this; + var timeout = safeSetTimeout(function () { + self.fail(self.name + ' timed out after ' + ms + 'ms'); + self.end(); + }, ms); + this.once('end', function () { + safeClearTimeout(timeout); + }); }; Test.prototype.end = function end(err) { - if (arguments.length >= 1 && !!err) { - this.ifError(err); - } - - if (this.calledEnd) { - this.fail('.end() already called'); - } - this.calledEnd = true; - this._end(); + if (arguments.length >= 1 && !!err) { + this.ifError(err); + } + + if (this.calledEnd) { + this.fail('.end() already called'); + } + this.calledEnd = true; + this._end(); }; Test.prototype.teardown = function teardown(fn) { - if (typeof fn !== 'function') { - this.fail('teardown: ' + inspect(fn) + ' is not a function'); - } else { - this._teardown.push(fn); - } + if (typeof fn !== 'function') { + this.fail('teardown: ' + inspect(fn) + ' is not a function'); + } else { + this._teardown.push(fn); + } }; Test.prototype._end = function _end(err) { - var self = this; - - if (!this._cb && !this._todo && !this._skip) { - this.fail('# TODO ' + this.name); - } - - if (this._progeny.length) { - var t = $shift(this._progeny); - t.on('end', function () { self._end(); }); - t.run(); - return; - } - - function next() { - if (self._teardown.length === 0) { - completeEnd(); - return; - } - var fn = self._teardown.shift(); - var res; - try { - res = fn(); - } catch (e) { - self.fail(e); - } - if (res && typeof res.then === 'function') { - res.then(next, function (_err) { - // TODO: wth? - err = err || _err; - }); - } else { - next(); - } - } - - next(); - - function completeEnd() { - if (!self.ended) { self.emit('end'); } - var pendingAsserts = self._pendingAsserts(); - if (!self._planError && self._plan !== undefined && pendingAsserts) { - self._planError = true; - self.fail('plan != count', { - expected: self._plan, - actual: self.assertCount - }); - } - self.ended = true; - } + var self = this; + + if (!this._cb && !this._todo && !this._skip) { + this.fail('# TODO ' + this.name); + } + + if (this._progeny.length) { + var t = $shift(this._progeny); + t.on('end', function () { self._end(); }); + t.run(); + return; + } + + function next() { + if (self._teardown.length === 0) { + completeEnd(); + return; + } + var fn = self._teardown.shift(); + var res; + try { + res = fn(); + } catch (e) { + self.fail(e); + } + if (res && typeof res.then === 'function') { + res.then(next, function (_err) { + // TODO: wth? + err = err || _err; + }); + } else { + next(); + } + } + + next(); + + function completeEnd() { + if (!self.ended) { self.emit('end'); } + var pendingAsserts = self._pendingAsserts(); + if (!self._planError && self._plan !== undefined && pendingAsserts) { + self._planError = true; + self.fail('plan != count', { + expected: self._plan, + actual: self.assertCount + }); + } + self.ended = true; + } }; Test.prototype._exit = function _exit() { - if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { - this._planError = true; - this.fail('plan != count', { - expected: this._plan, - actual: this.assertCount, - exiting: true - }); - } else if (!this.ended) { - this.fail('test exited without ending: ' + this.name, { - exiting: true - }); - } + if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { + this._planError = true; + this.fail('plan != count', { + expected: this._plan, + actual: this.assertCount, + exiting: true + }); + } else if (!this.ended) { + this.fail('test exited without ending: ' + this.name, { + exiting: true + }); + } }; Test.prototype._pendingAsserts = function _pendingAsserts() { - if (this._plan === undefined) { - return 1; - } - return this._plan - (this._progeny.length + this.assertCount); + if (this._plan === undefined) { + return 1; + } + return this._plan - (this._progeny.length + this.assertCount); }; Test.prototype._assert = function assert(ok, opts) { - var self = this; - var extra = opts.extra || {}; - - ok = !!ok || !!extra.skip; - - var name = defined(extra.message, opts.message, '(unnamed assert)'); - if (this.calledEnd && opts.operator !== 'fail') { - this.fail('.end() already called: ' + name); - return; - } - - var res = { - id: self.assertCount++, - ok: ok, - skip: defined(extra.skip, opts.skip), - todo: defined(extra.todo, opts.todo, self._todo), - name: name, - operator: defined(extra.operator, opts.operator), - objectPrintDepth: self._objectPrintDepth - }; - if (has(opts, 'actual') || has(extra, 'actual')) { - res.actual = defined(extra.actual, opts.actual); - } - if (has(opts, 'expected') || has(extra, 'expected')) { - res.expected = defined(extra.expected, opts.expected); - } - this._ok = !!(this._ok && ok); - - if (!ok && !res.todo) { - res.error = defined(extra.error, opts.error, new Error(res.name)); - } - - if (!ok) { - var e = new Error('exception'); - var err = $split(e.stack || '', '\n'); - var dir = __dirname + path.sep; - - for (var i = 0; i < err.length; i++) { - /* + var self = this; + var extra = opts.extra || {}; + + ok = !!ok || !!extra.skip; + + var name = defined(extra.message, opts.message, '(unnamed assert)'); + if (this.calledEnd && opts.operator !== 'fail') { + this.fail('.end() already called: ' + name); + return; + } + + var res = { + id: self.assertCount++, + ok: ok, + skip: defined(extra.skip, opts.skip), + todo: defined(extra.todo, opts.todo, self._todo), + name: name, + operator: defined(extra.operator, opts.operator), + objectPrintDepth: self._objectPrintDepth + }; + if (has(opts, 'actual') || has(extra, 'actual')) { + res.actual = defined(extra.actual, opts.actual); + } + if (has(opts, 'expected') || has(extra, 'expected')) { + res.expected = defined(extra.expected, opts.expected); + } + this._ok = !!(this._ok && ok); + + if (!ok && !res.todo) { + res.error = defined(extra.error, opts.error, new Error(res.name)); + } + + if (!ok) { + var e = new Error('exception'); + var err = $split(e.stack || '', '\n'); + var dir = __dirname + path.sep; + + for (var i = 0; i < err.length; i++) { + /* Stack trace lines may resemble one of the following. We need to correctly extract a function name (if any) and path / line number for each line. @@ -355,88 +355,88 @@ Test.prototype._assert = function assert(ok, opts) { /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)?/ */ - var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/; - var lineWithTokens = $replace($replace(err[i], process.cwd(), '/$CWD'), __dirname, '/$TEST'); - var m = re.exec(lineWithTokens); - - if (!m) { - continue; - } - - var callDescription = m[1] || ''; - var filePath = $replace($replace(m[2], '/$CWD', process.cwd()), '/$TEST', __dirname); - - if ($strSlice(filePath, 0, dir.length) === dir) { - continue; - } - - // Function call description may not (just) be a function name. - // Try to extract function name by looking at first "word" only. - res.functionName = $split(callDescription, /\s+/)[0]; - res.file = filePath; - res.line = Number(m[3]); - if (m[4]) { res.column = Number(m[4]); } - - res.at = callDescription + ' (' + filePath + ')'; - break; - } - } - - self.emit('result', res); - - var pendingAsserts = self._pendingAsserts(); - if (!pendingAsserts) { - if (extra.exiting) { - self._end(); - } else { - nextTick(function () { - self._end(); - }); - } - } - - if (!self._planError && pendingAsserts < 0) { - self._planError = true; - self.fail('plan != count', { - expected: self._plan, - actual: self._plan - pendingAsserts - }); - } + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/; + var lineWithTokens = $replace($replace(err[i], process.cwd(), '/$CWD'), __dirname, '/$TEST'); + var m = re.exec(lineWithTokens); + + if (!m) { + continue; + } + + var callDescription = m[1] || ''; + var filePath = $replace($replace(m[2], '/$CWD', process.cwd()), '/$TEST', __dirname); + + if ($strSlice(filePath, 0, dir.length) === dir) { + continue; + } + + // Function call description may not (just) be a function name. + // Try to extract function name by looking at first "word" only. + res.functionName = $split(callDescription, /\s+/)[0]; + res.file = filePath; + res.line = Number(m[3]); + if (m[4]) { res.column = Number(m[4]); } + + res.at = callDescription + ' (' + filePath + ')'; + break; + } + } + + self.emit('result', res); + + var pendingAsserts = self._pendingAsserts(); + if (!pendingAsserts) { + if (extra.exiting) { + self._end(); + } else { + nextTick(function () { + self._end(); + }); + } + } + + if (!self._planError && pendingAsserts < 0) { + self._planError = true; + self.fail('plan != count', { + expected: self._plan, + actual: self._plan - pendingAsserts + }); + } }; Test.prototype.fail = function fail(msg, extra) { - this._assert(false, { - message: msg, - operator: 'fail', - extra: extra - }); + this._assert(false, { + message: msg, + operator: 'fail', + extra: extra + }); }; Test.prototype.pass = function pass(msg, extra) { - this._assert(true, { - message: msg, - operator: 'pass', - extra: extra - }); + this._assert(true, { + message: msg, + operator: 'pass', + extra: extra + }); }; Test.prototype.skip = function skip(msg, extra) { - this._assert(true, { - message: msg, - operator: 'skip', - skip: true, - extra: extra - }); + this._assert(true, { + message: msg, + operator: 'skip', + skip: true, + extra: extra + }); }; var testAssert = function assert(value, msg, extra) { - this._assert(value, { - message: defined(msg, 'should be truthy'), - operator: 'ok', - expected: true, - actual: value, - extra: extra - }); + this._assert(value, { + message: defined(msg, 'should be truthy'), + operator: 'ok', + expected: true, + actual: value, + extra: extra + }); }; Test.prototype.ok = Test.prototype['true'] @@ -444,13 +444,13 @@ Test.prototype.ok = testAssert; function notOK(value, msg, extra) { - this._assert(!value, { - message: defined(msg, 'should be falsy'), - operator: 'notOk', - expected: false, - actual: value, - extra: extra - }); + this._assert(!value, { + message: defined(msg, 'should be falsy'), + operator: 'notOk', + expected: false, + actual: value, + extra: extra + }); } Test.prototype.notOk = Test.prototype['false'] @@ -458,12 +458,12 @@ Test.prototype.notOk = notOK; function error(err, msg, extra) { - this._assert(!err, { - message: defined(msg, String(err)), - operator: 'error', - error: err, - extra: extra - }); + this._assert(!err, { + message: defined(msg, String(err)), + operator: 'error', + error: err, + extra: extra + }); } Test.prototype.error = Test.prototype.ifError @@ -472,16 +472,16 @@ Test.prototype.error = error; function strictEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(is(a, b), { - message: defined(msg, 'should be strictly equal'), - operator: 'equal', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(is(a, b), { + message: defined(msg, 'should be strictly equal'), + operator: 'equal', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.equal = Test.prototype.equals @@ -492,16 +492,16 @@ Test.prototype.equal = strictEqual; function notStrictEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(!is(a, b), { - message: defined(msg, 'should not be strictly equal'), - operator: 'notEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(!is(a, b), { + message: defined(msg, 'should not be strictly equal'), + operator: 'notEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.notEqual @@ -516,16 +516,16 @@ Test.prototype.notEqual = notStrictEqual; function looseEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(a == b, { - message: defined(msg, 'should be loosely equal'), - operator: 'looseEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(a == b, { + message: defined(msg, 'should be loosely equal'), + operator: 'looseEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.looseEqual @@ -533,32 +533,32 @@ Test.prototype.looseEqual = looseEqual; function notLooseEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(a != b, { - message: defined(msg, 'should not be loosely equal'), - operator: 'notLooseEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(a != b, { + message: defined(msg, 'should not be loosely equal'), + operator: 'notLooseEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.notLooseEqual = Test.prototype.notLooseEquals = notLooseEqual; function tapeDeepEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(deepEqual(a, b, { strict: true }), { - message: defined(msg, 'should be deeply equivalent'), - operator: 'deepEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(deepEqual(a, b, { strict: true }), { + message: defined(msg, 'should be deeply equivalent'), + operator: 'deepEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.deepEqual = Test.prototype.deepEquals @@ -567,16 +567,16 @@ Test.prototype.deepEqual = tapeDeepEqual; function notDeepEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(!deepEqual(a, b, { strict: true }), { - message: defined(msg, 'should not be deeply equivalent'), - operator: 'notDeepEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(!deepEqual(a, b, { strict: true }), { + message: defined(msg, 'should not be deeply equivalent'), + operator: 'notDeepEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.notDeepEqual = Test.prototype.notDeepEquals @@ -590,194 +590,194 @@ Test.prototype.notDeepEqual = notDeepEqual; function deepLooseEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(deepEqual(a, b), { - message: defined(msg, 'should be loosely deeply equivalent'), - operator: 'deepLooseEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(deepEqual(a, b), { + message: defined(msg, 'should be loosely deeply equivalent'), + operator: 'deepLooseEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.deepLooseEqual = deepLooseEqual; function notDeepLooseEqual(a, b, msg, extra) { - if (arguments.length < 2) { - throw new TypeError('two arguments must be provided to compare'); - } - this._assert(!deepEqual(a, b), { - message: defined(msg, 'should not be loosely deeply equivalent'), - operator: 'notDeepLooseEqual', - actual: a, - expected: b, - extra: extra - }); + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(!deepEqual(a, b), { + message: defined(msg, 'should not be loosely deeply equivalent'), + operator: 'notDeepLooseEqual', + actual: a, + expected: b, + extra: extra + }); } Test.prototype.notDeepLooseEqual = notDeepLooseEqual; Test.prototype['throws'] = function (fn, expected, msg, extra) { - if (typeof expected === 'string') { - msg = expected; - expected = undefined; - } - - var caught; - - try { - fn(); - } catch (err) { - caught = { error: err }; - if (Object(err) === err && (!isEnumerable(err, 'message') || !has(err, 'message'))) { - var message = err.message; - delete err.message; - err.message = message; - } - } - - var passed = caught; - - if (caught) { - if (typeof expected === 'string' && caught.error && caught.error.message === expected) { - throw new TypeError('The "error/message" argument is ambiguous. The error message ' + inspect(expected) + ' is identical to the message.'); - } - if (typeof expected === 'function') { - if (typeof expected.prototype !== 'undefined' && caught.error instanceof expected) { - passed = true; - } else if (isProto(Error, expected)) { - passed = false; - } else { - passed = expected.call({}, caught.error) === true; - } - } else if (isRegExp(expected)) { - passed = $exec(expected, caught.error) !== null; - expected = inspect(expected); - } else if (expected && typeof expected === 'object') { // Handle validation objects. - var keys = objectKeys(expected); - // Special handle errors to make sure the name and the message are compared as well. - if (expected instanceof Error) { - $push(keys, 'name', 'message'); - } else if (keys.length === 0) { - throw new TypeError('`throws` validation object must not be empty'); - } - passed = every(keys, function (key) { - if (typeof caught.error[key] === 'string' && isRegExp(expected[key]) && $exec(expected[key], caught.error[key]) !== null) { - return true; - } - if (key in caught.error && deepEqual(caught.error[key], expected[key], { strict: true })) { - return true; - } - return false; - }); - } - } - - this._assert(!!passed, { - message: defined(msg, 'should throw'), - operator: 'throws', - actual: caught && caught.error, - expected: expected, - error: !passed && caught && caught.error, - extra: extra - }); + if (typeof expected === 'string') { + msg = expected; + expected = undefined; + } + + var caught; + + try { + fn(); + } catch (err) { + caught = { error: err }; + if (Object(err) === err && (!isEnumerable(err, 'message') || !has(err, 'message'))) { + var message = err.message; + delete err.message; + err.message = message; + } + } + + var passed = caught; + + if (caught) { + if (typeof expected === 'string' && caught.error && caught.error.message === expected) { + throw new TypeError('The "error/message" argument is ambiguous. The error message ' + inspect(expected) + ' is identical to the message.'); + } + if (typeof expected === 'function') { + if (typeof expected.prototype !== 'undefined' && caught.error instanceof expected) { + passed = true; + } else if (isProto(Error, expected)) { + passed = false; + } else { + passed = expected.call({}, caught.error) === true; + } + } else if (isRegExp(expected)) { + passed = $exec(expected, caught.error) !== null; + expected = inspect(expected); + } else if (expected && typeof expected === 'object') { // Handle validation objects. + var keys = objectKeys(expected); + // Special handle errors to make sure the name and the message are compared as well. + if (expected instanceof Error) { + $push(keys, 'name', 'message'); + } else if (keys.length === 0) { + throw new TypeError('`throws` validation object must not be empty'); + } + passed = every(keys, function (key) { + if (typeof caught.error[key] === 'string' && isRegExp(expected[key]) && $exec(expected[key], caught.error[key]) !== null) { + return true; + } + if (key in caught.error && deepEqual(caught.error[key], expected[key], { strict: true })) { + return true; + } + return false; + }); + } + } + + this._assert(!!passed, { + message: defined(msg, 'should throw'), + operator: 'throws', + actual: caught && caught.error, + expected: expected, + error: !passed && caught && caught.error, + extra: extra + }); }; Test.prototype.doesNotThrow = function doesNotThrow(fn, expected, msg, extra) { - if (typeof expected === 'string') { - msg = expected; - expected = undefined; - } - var caught; - try { - fn(); - } catch (err) { - caught = { error: err }; - } - this._assert(!caught, { - message: defined(msg, 'should not throw'), - operator: 'throws', - actual: caught && caught.error, - expected: expected, - error: caught && caught.error, - extra: extra - }); + if (typeof expected === 'string') { + msg = expected; + expected = undefined; + } + var caught; + try { + fn(); + } catch (err) { + caught = { error: err }; + } + this._assert(!caught, { + message: defined(msg, 'should not throw'), + operator: 'throws', + actual: caught && caught.error, + expected: expected, + error: caught && caught.error, + extra: extra + }); }; Test.prototype.match = function match(string, regexp, msg, extra) { - if (!isRegExp(regexp)) { - this._assert(false, { - message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'), - operator: 'match', - actual: objectToString(regexp), - expected: '[object RegExp]', - extra: extra - }); - } else if (typeof string !== 'string') { - this._assert(false, { - message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'), - operator: 'match', - actual: string === null ? null : typeof string, - expected: 'string', - extra: extra - }); - } else { - var matches = $exec(regexp, string) !== null; - var message = defined( - msg, - 'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string) - ); - this._assert(matches, { - message: message, - operator: 'match', - actual: string, - expected: regexp, - extra: extra - }); - } + if (!isRegExp(regexp)) { + this._assert(false, { + message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'), + operator: 'match', + actual: objectToString(regexp), + expected: '[object RegExp]', + extra: extra + }); + } else if (typeof string !== 'string') { + this._assert(false, { + message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'), + operator: 'match', + actual: string === null ? null : typeof string, + expected: 'string', + extra: extra + }); + } else { + var matches = $exec(regexp, string) !== null; + var message = defined( + msg, + 'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string) + ); + this._assert(matches, { + message: message, + operator: 'match', + actual: string, + expected: regexp, + extra: extra + }); + } }; Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra) { - if (!isRegExp(regexp)) { - this._assert(false, { - message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'), - operator: 'doesNotMatch', - actual: objectToString(regexp), - expected: '[object RegExp]', - extra: extra - }); - } else if (typeof string !== 'string') { - this._assert(false, { - message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'), - operator: 'doesNotMatch', - actual: string === null ? null : typeof string, - expected: 'string', - extra: extra - }); - } else { - var matches = $exec(regexp, string) !== null; - var message = defined( - msg, - 'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string) - ); - this._assert(!matches, { - message: message, - operator: 'doesNotMatch', - actual: string, - expected: regexp, - extra: extra - }); - } + if (!isRegExp(regexp)) { + this._assert(false, { + message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'), + operator: 'doesNotMatch', + actual: objectToString(regexp), + expected: '[object RegExp]', + extra: extra + }); + } else if (typeof string !== 'string') { + this._assert(false, { + message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'), + operator: 'doesNotMatch', + actual: string === null ? null : typeof string, + expected: 'string', + extra: extra + }); + } else { + var matches = $exec(regexp, string) !== null; + var message = defined( + msg, + 'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string) + ); + this._assert(!matches, { + message: message, + operator: 'doesNotMatch', + actual: string, + expected: regexp, + extra: extra + }); + } }; // eslint-disable-next-line no-unused-vars Test.skip = function skip(name_, _opts, _cb) { - var args = getTestArgs.apply(null, arguments); - args.opts.skip = true; - return new Test(args.name, args.opts, args.cb); + var args = getTestArgs.apply(null, arguments); + args.opts.skip = true; + return new Test(args.name, args.opts, args.cb); }; // vim: set softtabstop=4 shiftwidth=4: diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js index 9d13d44e..dc16e7a5 100644 --- a/test/add-subtest-async.js +++ b/test/add-subtest-async.js @@ -3,11 +3,11 @@ var test = require('../'); test('parent', function (t) { - t.pass('parent'); - setTimeout(function () { - t.test('child', function (st) { - st.pass('child'); - st.end(); - }); - }, 100); + t.pass('parent'); + setTimeout(function () { + t.test('child', function (st) { + st.pass('child'); + st.end(); + }); + }, 100); }); diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index 9a73ed8a..87c54bcd 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -8,39 +8,39 @@ var stripFullStack = require('./common').stripFullStack; var testWrapper = require('./anonymous-fn/test-wrapper'); tap.test('inside anonymous functions', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - var tc = function (rows) { - var body = stripFullStack(rows.toString('utf8')); + var test = tape.createHarness(); + var tc = function (rows) { + var body = stripFullStack(rows.toString('utf8')); - tt.same(body, [ - 'TAP version 13', - '# wrapped test failure', - 'not ok 1 fail', - ' ---', - ' operator: fail', - ' at: ($TEST/anonymous-fn.js:$LINE:$COL)', - ' stack: |-', - ' Error: fail', - ' [... stack stripped ...]', - ' at $TEST/anonymous-fn.js:$LINE:$COL', - ' at Test. ($TEST/anonymous-fn/test-wrapper.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - }; + tt.same(body, [ + 'TAP version 13', + '# wrapped test failure', + 'not ok 1 fail', + ' ---', + ' operator: fail', + ' at: ($TEST/anonymous-fn.js:$LINE:$COL)', + ' stack: |-', + ' Error: fail', + ' [... stack stripped ...]', + ' at $TEST/anonymous-fn.js:$LINE:$COL', + ' at Test. ($TEST/anonymous-fn/test-wrapper.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('wrapped test failure', testWrapper(function (t) { - t.fail('fail'); - t.end(); - })); + test('wrapped test failure', testWrapper(function (t) { + t.fail('fail'); + t.end(); + })); }); diff --git a/test/anonymous-fn/test-wrapper.js b/test/anonymous-fn/test-wrapper.js index f79ef485..0c42f00e 100644 --- a/test/anonymous-fn/test-wrapper.js +++ b/test/anonymous-fn/test-wrapper.js @@ -2,17 +2,17 @@ // Example of wrapper function that would invoke tape module.exports = function (testCase) { - return function (t) { - setUp(); - testCase(t); - tearDown(); - }; + return function (t) { + setUp(); + testCase(t); + tearDown(); + }; }; function setUp() { - // ... example ... + // ... example ... } function tearDown() { - // ... example ... + // ... example ... } diff --git a/test/array.js b/test/array.js index 39be3f61..11a7fdc3 100644 --- a/test/array.js +++ b/test/array.js @@ -6,58 +6,58 @@ var tap = require('tap'); var concat = require('concat-stream'); tap.test('array test', function (tt) { - tt.plan(1); - - var test = tape.createHarness(); - - test.createStream().pipe(concat(function (rows) { - tt.same(rows.toString('utf8'), [ - 'TAP version 13', - '# array', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'ok 5 should be deeply equivalent', - '', - '1..5', - '# tests 5', - '# pass 5', - '', - '# ok' - ].join('\n') + '\n'); - })); - - test('array', function (t) { - t.plan(5); - - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; - - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); - - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; - - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); - }); + tt.plan(1); + + var test = tape.createHarness(); + + test.createStream().pipe(concat(function (rows) { + tt.same(rows.toString('utf8'), [ + 'TAP version 13', + '# array', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'ok 5 should be deeply equivalent', + '', + '1..5', + '# tests 5', + '# pass 5', + '', + '# ok' + ].join('\n') + '\n'); + })); + + test('array', function (t) { + t.plan(5); + + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; + + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); + + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; + + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); + }); }); diff --git a/test/async-await.js b/test/async-await.js index c3e1ce18..6b014a87 100644 --- a/test/async-await.js +++ b/test/async-await.js @@ -9,298 +9,298 @@ var nodeVersion = process.versions.node; var majorVersion = nodeVersion.split('.')[0]; if (Number(majorVersion) < 8) { - process.exit(0); // eslint-disable-line no-process-exit + process.exit(0); // eslint-disable-line no-process-exit } var node17 = Number(majorVersion) >= 17; var lengthMessage = 'Cannot read property \'length\' of null'; try { - lengthMessage = null.length; + lengthMessage = null.length; } catch (e) { - lengthMessage = e.message; // differs in v8 6.9+ (node 16.9+) + lengthMessage = e.message; // differs in v8 6.9+ (node 16.9+) } tap.test('async1', function (t) { - runProgram('async-await', 'async1.js', function (r) { - t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ - 'TAP version 13', - '# async1', - 'ok 1 before await', - 'ok 2 after await', - '', - '1..2', - '# tests 2', - '# pass 2', - '', - '# ok', - '', - '' - ]); - t.same(r.exitCode, 0); - t.same(r.stderr.toString('utf8'), ''); - t.end(); - }); + runProgram('async-await', 'async1.js', function (r) { + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ + 'TAP version 13', + '# async1', + 'ok 1 before await', + 'ok 2 after await', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok', + '', + '' + ]); + t.same(r.exitCode, 0); + t.same(r.stderr.toString('utf8'), ''); + t.end(); + }); }); tap.test('async2', function (t) { - runProgram('async-await', 'async2.js', function (r) { - var stdout = r.stdout.toString('utf8'); - var lines = stdout.split('\n').filter(function (line) { - return !(/^(\s+)at(\s+)$/).test(line); - }); + runProgram('async-await', 'async2.js', function (r) { + var stdout = r.stdout.toString('utf8'); + var lines = stdout.split('\n').filter(function (line) { + return !(/^(\s+)at(\s+)$/).test(line); + }); - t.deepEqual(stripFullStack(lines.join('\n')), [ - 'TAP version 13', - '# async2', - 'ok 1 before await', - 'not ok 2 after await', - ' ---', - ' operator: ok', - ' expected: true', - ' actual: false', - ' at: Test.myTest ($TEST/async-await/async2.js:$LINE:$COL)', - ' stack: |-', - ' Error: after await', - ' [... stack stripped ...]', - ' at Test.myTest ($TEST/async-await/async2.js:$LINE:$COL)', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ]); - t.same(r.exitCode, 1); - t.same(r.stderr.toString('utf8'), ''); - t.end(); - }); + t.deepEqual(stripFullStack(lines.join('\n')), [ + 'TAP version 13', + '# async2', + 'ok 1 before await', + 'not ok 2 after await', + ' ---', + ' operator: ok', + ' expected: true', + ' actual: false', + ' at: Test.myTest ($TEST/async-await/async2.js:$LINE:$COL)', + ' stack: |-', + ' Error: after await', + ' [... stack stripped ...]', + ' at Test.myTest ($TEST/async-await/async2.js:$LINE:$COL)', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ]); + t.same(r.exitCode, 1); + t.same(r.stderr.toString('utf8'), ''); + t.end(); + }); }); tap.test('async3', function (t) { - runProgram('async-await', 'async3.js', function (r) { - t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ - 'TAP version 13', - '# async3', - 'ok 1 before await', - 'ok 2 after await', - '', - '1..2', - '# tests 2', - '# pass 2', - '', - '# ok', - '', - '' - ]); - t.same(r.exitCode, 0); - t.same(r.stderr.toString('utf8'), ''); - t.end(); - }); + runProgram('async-await', 'async3.js', function (r) { + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ + 'TAP version 13', + '# async3', + 'ok 1 before await', + 'ok 2 after await', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok', + '', + '' + ]); + t.same(r.exitCode, 0); + t.same(r.stderr.toString('utf8'), ''); + t.end(); + }); }); tap.test('async4', function (t) { - runProgram('async-await', 'async4.js', function (r) { - t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ - 'TAP version 13', - '# async4', - 'ok 1 before await', - 'not ok 2 Error: oops', - ' ---', - ' operator: error', - ' at: Test.myTest ($TEST/async-await/async4.js:$LINE:$COL)', - ' stack: |-', - ' Error: oops', - ' at Timeout.myTimeout [as _onTimeout] ($TEST/async-await/async4.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ]); - t.same(r.exitCode, 1); - t.same(r.stderr.toString('utf8'), ''); - t.end(); - }); + runProgram('async-await', 'async4.js', function (r) { + t.deepEqual(stripFullStack(r.stdout.toString('utf8')), [ + 'TAP version 13', + '# async4', + 'ok 1 before await', + 'not ok 2 Error: oops', + ' ---', + ' operator: error', + ' at: Test.myTest ($TEST/async-await/async4.js:$LINE:$COL)', + ' stack: |-', + ' Error: oops', + ' at Timeout.myTimeout [as _onTimeout] ($TEST/async-await/async4.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ]); + t.same(r.exitCode, 1); + t.same(r.stderr.toString('utf8'), ''); + t.end(); + }); }); tap.test('async5', function (t) { - runProgram('async-await', 'async5.js', function (r) { - t.same(stripFullStack(r.stdout.toString('utf8')), [ - 'TAP version 13', - '# async5', - 'ok 1 before server', - 'ok 2 after server', - 'ok 3 before request', - 'ok 4 after request', - 'ok 5 res.statusCode is 200', - 'not ok 6 .end() already called: mockDb.state is new', - ' ---', - ' operator: fail', - ' at: Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)', - ' stack: |-', - ' Error: .end() already called: mockDb.state is new', - ' [... stack stripped ...]', - ' at Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 7 .end() already called: error on close', - ' ---', - ' operator: fail', - ' at: Server. ($TEST/async-await/async5.js:$LINE:$COL)', - ' stack: |-', - ' Error: .end() already called: error on close', - ' [... stack stripped ...]', - ' at Server. ($TEST/async-await/async5.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 8 .end() already called', - ' ---', - ' operator: fail', - ' at: Server. ($TEST/async-await/async5.js:$LINE:$COL)', - ' stack: |-', - ' Error: .end() already called', - ' [... stack stripped ...]', - ' at Server. ($TEST/async-await/async5.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..8', - '# tests 8', - '# pass 5', - '# fail 3', - '', - '' - ]); - t.same(r.exitCode, 1); - t.same(r.stderr.toString('utf8'), ''); - t.end(); - }); + runProgram('async-await', 'async5.js', function (r) { + t.same(stripFullStack(r.stdout.toString('utf8')), [ + 'TAP version 13', + '# async5', + 'ok 1 before server', + 'ok 2 after server', + 'ok 3 before request', + 'ok 4 after request', + 'ok 5 res.statusCode is 200', + 'not ok 6 .end() already called: mockDb.state is new', + ' ---', + ' operator: fail', + ' at: Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)', + ' stack: |-', + ' Error: .end() already called: mockDb.state is new', + ' [... stack stripped ...]', + ' at Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 7 .end() already called: error on close', + ' ---', + ' operator: fail', + ' at: Server. ($TEST/async-await/async5.js:$LINE:$COL)', + ' stack: |-', + ' Error: .end() already called: error on close', + ' [... stack stripped ...]', + ' at Server. ($TEST/async-await/async5.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 .end() already called', + ' ---', + ' operator: fail', + ' at: Server. ($TEST/async-await/async5.js:$LINE:$COL)', + ' stack: |-', + ' Error: .end() already called', + ' [... stack stripped ...]', + ' at Server. ($TEST/async-await/async5.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..8', + '# tests 8', + '# pass 5', + '# fail 3', + '', + '' + ]); + t.same(r.exitCode, 1); + t.same(r.stderr.toString('utf8'), ''); + t.end(); + }); }); tap.test('sync-error', function (t) { - runProgram('async-await', 'sync-error.js', function (r) { - t.same(stripFullStack(r.stdout.toString('utf8')), [ - 'TAP version 13', - '# sync-error', - 'ok 1 before throw', - '' - ]); - t.same(r.exitCode, 1); + runProgram('async-await', 'sync-error.js', function (r) { + t.same(stripFullStack(r.stdout.toString('utf8')), [ + 'TAP version 13', + '# sync-error', + 'ok 1 before throw', + '' + ]); + t.same(r.exitCode, 1); - var stderr = r.stderr.toString('utf8'); - var lines = stderr.split('\n'); - lines = lines.filter(function (line) { - return !(/\(timers.js:/).test(line) + var stderr = r.stderr.toString('utf8'); + var lines = stderr.split('\n'); + lines = lines.filter(function (line) { + return !(/\(timers.js:/).test(line) && !(/\(internal\/timers.js:/).test(line) && !(/Immediate\.next/).test(line); - }); - stderr = lines.join('\n'); + }); + stderr = lines.join('\n'); - t.same(stripFullStack(stderr), [].concat( - '$TEST/async-await/sync-error.js:7', - ' throw new Error(\'oopsie\');', - ' ^', - '', - 'Error: oopsie', - ' at Test.myTest ($TEST/async-await/sync-error.js:$LINE:$COL)', - ' at Test.bound [as _cb] ($TAPE/lib/test.js:$LINE:$COL)', - ' at Test.run ($TAPE/lib/test.js:$LINE:$COL)', - ' at Test.bound [as run] ($TAPE/lib/test.js:$LINE:$COL)', - node17 ? [ - '', - 'Node.js ' + process.version - ] : [], - '' - )); - t.end(); - }); + t.same(stripFullStack(stderr), [].concat( + '$TEST/async-await/sync-error.js:7', + ' throw new Error(\'oopsie\');', + ' ^', + '', + 'Error: oopsie', + ' at Test.myTest ($TEST/async-await/sync-error.js:$LINE:$COL)', + ' at Test.bound [as _cb] ($TAPE/lib/test.js:$LINE:$COL)', + ' at Test.run ($TAPE/lib/test.js:$LINE:$COL)', + ' at Test.bound [as run] ($TAPE/lib/test.js:$LINE:$COL)', + node17 ? [ + '', + 'Node.js ' + process.version + ] : [], + '' + )); + t.end(); + }); }); tap.test('async-error', function (t) { - runProgram('async-await', 'async-error.js', function (r) { - var stdout = r.stdout.toString('utf8'); - var lines = stdout.split('\n'); - lines = lines.filter(function (line) { - return !(/^(\s+)at(\s+)$/).test(line); - }); - stdout = lines.join('\n'); + runProgram('async-await', 'async-error.js', function (r) { + var stdout = r.stdout.toString('utf8'); + var lines = stdout.split('\n'); + lines = lines.filter(function (line) { + return !(/^(\s+)at(\s+)$/).test(line); + }); + stdout = lines.join('\n'); - t.same(stripFullStack(stdout), [ - 'TAP version 13', - '# async-error', - 'ok 1 before throw', - 'not ok 2 Error: oopsie', - ' ---', - ' operator: error', - ' stack: |-', - ' Error: oopsie', - ' at Test.myTest ($TEST/async-await/async-error.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ]); - t.same(r.exitCode, 1); + t.same(stripFullStack(stdout), [ + 'TAP version 13', + '# async-error', + 'ok 1 before throw', + 'not ok 2 Error: oopsie', + ' ---', + ' operator: error', + ' stack: |-', + ' Error: oopsie', + ' at Test.myTest ($TEST/async-await/async-error.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ]); + t.same(r.exitCode, 1); - var stderr = r.stderr.toString('utf8'); - var stderrLines = stderr.split('\n').filter(function (line) { - return !(/\(timers.js:/).test(line) + var stderr = r.stderr.toString('utf8'); + var stderrLines = stderr.split('\n').filter(function (line) { + return !(/\(timers.js:/).test(line) && !(/\(internal\/timers.js:/).test(line) && !(/Immediate\.next/).test(line); - }); + }); - t.same(stderrLines.join('\n'), ''); - t.end(); - }); + t.same(stderrLines.join('\n'), ''); + t.end(); + }); }); tap.test('async-bug', function (t) { - runProgram('async-await', 'async-bug.js', function (r) { - var stdout = r.stdout.toString('utf8'); - var lines = stdout.split('\n'); - lines = lines.filter(function (line) { - return !(/^(\s+)at(\s+)$/).test(line); - }); - stdout = lines.join('\n'); + runProgram('async-await', 'async-bug.js', function (r) { + var stdout = r.stdout.toString('utf8'); + var lines = stdout.split('\n'); + lines = lines.filter(function (line) { + return !(/^(\s+)at(\s+)$/).test(line); + }); + stdout = lines.join('\n'); - t.same(stripFullStack(stdout), [ - 'TAP version 13', - '# async-error', - 'ok 1 before throw', - 'ok 2 should be strictly equal', - 'not ok 3 TypeError: ' + lengthMessage, - ' ---', - ' operator: error', - ' stack: |-', - ' TypeError: ' + lengthMessage, - ' at myCode ($TEST/async-await/async-bug.js:$LINE:$COL)', - ' at Test.myTest ($TEST/async-await/async-bug.js:$LINE:$COL)', - ' ...', - '', - '1..3', - '# tests 3', - '# pass 2', - '# fail 1', - '', - '' - ]); - t.same(r.exitCode, 1); + t.same(stripFullStack(stdout), [ + 'TAP version 13', + '# async-error', + 'ok 1 before throw', + 'ok 2 should be strictly equal', + 'not ok 3 TypeError: ' + lengthMessage, + ' ---', + ' operator: error', + ' stack: |-', + ' TypeError: ' + lengthMessage, + ' at myCode ($TEST/async-await/async-bug.js:$LINE:$COL)', + ' at Test.myTest ($TEST/async-await/async-bug.js:$LINE:$COL)', + ' ...', + '', + '1..3', + '# tests 3', + '# pass 2', + '# fail 1', + '', + '' + ]); + t.same(r.exitCode, 1); - var stderr = r.stderr.toString('utf8'); + var stderr = r.stderr.toString('utf8'); - t.same(stderr, ''); - t.end(); - }); + t.same(stderr, ''); + t.end(); + }); }); diff --git a/test/async-await/async-bug.js b/test/async-await/async-bug.js index b9fde636..263e7eaf 100644 --- a/test/async-await/async-bug.js +++ b/test/async-await/async-bug.js @@ -3,29 +3,29 @@ var test = require('../../'); function myCode(arr) { - let sum = 0; - // oops forgot to handle null - for (let i = 0; i < arr.length; i++) { - sum += arr[i]; - } - return sum; + let sum = 0; + // oops forgot to handle null + for (let i = 0; i < arr.length; i++) { + sum += arr[i]; + } + return sum; } test('async-error', async function myTest(t) { - await sleep(100); - t.ok(true, 'before throw'); + await sleep(100); + t.ok(true, 'before throw'); - const sum = myCode([1, 2, 3]); - t.equal(sum, 6); + const sum = myCode([1, 2, 3]); + t.equal(sum, 6); - const sum2 = myCode(null); - t.equal(sum2, 0); + const sum2 = myCode(null); + t.equal(sum2, 0); - t.end(); + t.end(); }); function sleep(ms) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); } diff --git a/test/async-await/async-error.js b/test/async-await/async-error.js index ae02da57..95f47b07 100644 --- a/test/async-await/async-error.js +++ b/test/async-await/async-error.js @@ -3,8 +3,8 @@ var test = require('../../'); test('async-error', async function myTest(t) { - t.ok(true, 'before throw'); - throw new Error('oopsie'); - /* eslint no-unreachable: 0 */ - t.ok(true, 'after throw'); + t.ok(true, 'before throw'); + throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ + t.ok(true, 'after throw'); }); diff --git a/test/async-await/async1.js b/test/async-await/async1.js index ac40d193..5bf12e13 100644 --- a/test/async-await/async1.js +++ b/test/async-await/async1.js @@ -3,14 +3,14 @@ var test = require('../../'); test('async1', async function myTest(t) { - try { - t.ok(true, 'before await'); - await new Promise((resolve) => { - setTimeout(resolve, 10); - }); - t.ok(true, 'after await'); - t.end(); - } catch (err) { - t.ifError(err); - } + try { + t.ok(true, 'before await'); + await new Promise((resolve) => { + setTimeout(resolve, 10); + }); + t.ok(true, 'after await'); + t.end(); + } catch (err) { + t.ifError(err); + } }); diff --git a/test/async-await/async2.js b/test/async-await/async2.js index 1f366b1a..98bd69b8 100644 --- a/test/async-await/async2.js +++ b/test/async-await/async2.js @@ -3,13 +3,13 @@ var test = require('../../'); test('async2', async function myTest(t) { - try { - t.ok(true, 'before await'); - await new Promise((resolve) => { - setTimeout(resolve, 10); - }); - t.ok(false, 'after await'); - } catch (err) { - t.ifError(err); - } + try { + t.ok(true, 'before await'); + await new Promise((resolve) => { + setTimeout(resolve, 10); + }); + t.ok(false, 'after await'); + } catch (err) { + t.ifError(err); + } }); diff --git a/test/async-await/async3.js b/test/async-await/async3.js index 25dd1bcd..e86d0905 100644 --- a/test/async-await/async3.js +++ b/test/async-await/async3.js @@ -3,9 +3,9 @@ var test = require('../../'); test('async3', async function myTest(t) { - t.ok(true, 'before await'); - await new Promise((resolve) => { - setTimeout(resolve, 10); - }); - t.ok(true, 'after await'); + t.ok(true, 'before await'); + await new Promise((resolve) => { + setTimeout(resolve, 10); + }); + t.ok(true, 'after await'); }); diff --git a/test/async-await/async4.js b/test/async-await/async4.js index 67706a6a..f7f80bde 100644 --- a/test/async-await/async4.js +++ b/test/async-await/async4.js @@ -3,15 +3,15 @@ var test = require('../../'); test('async4', async function myTest(t) { - try { - t.ok(true, 'before await'); - await new Promise((resolve, reject) => { - setTimeout(function myTimeout() { - reject(new Error('oops')); - }, 10); - }); - t.ok(true, 'after await'); - } catch (err) { - t.ifError(err); - } + try { + t.ok(true, 'before await'); + await new Promise((resolve, reject) => { + setTimeout(function myTimeout() { + reject(new Error('oops')); + }, 10); + }); + t.ok(true, 'after await'); + } catch (err) { + t.ifError(err); + } }); diff --git a/test/async-await/async5.js b/test/async-await/async5.js index eca3bc4a..5e40cae4 100644 --- a/test/async-await/async5.js +++ b/test/async-await/async5.js @@ -6,54 +6,54 @@ var http = require('http'); var test = require('../../'); test('async5', async function myTest(t) { - try { - t.ok(true, 'before server'); - - var mockDb = { state: 'old' }; - var server = http.createServer(function (req, res) { - res.end('OK'); - - // Pretend we write to the DB and it takes time. - setTimeout(function () { - mockDb.state = 'new'; - }, 10); - }); - - await util.promisify(function (cb) { - server.listen(0, cb); - })(); - - t.ok(true, 'after server'); - - t.ok(true, 'before request'); - - var res = await util.promisify(function (cb) { - var req = http.request({ - hostname: 'localhost', - port: server.address().port, - path: '/', - method: 'GET' - }, function (resp) { - cb(null, resp); - }); - req.end(); - })(); - - t.ok(true, 'after request'); - - res.resume(); - t.equal(res.statusCode, 200, 'res.statusCode is 200'); - - setTimeout(function () { - t.equal(mockDb.state, 'new', 'mockDb.state is new'); - - server.close(function (err) { - t.ifError(err, 'error on close'); - t.end(); - }); - }, 50); - } catch (err) { - t.ifError(err, 'error in catch'); - t.end(); - } + try { + t.ok(true, 'before server'); + + var mockDb = { state: 'old' }; + var server = http.createServer(function (req, res) { + res.end('OK'); + + // Pretend we write to the DB and it takes time. + setTimeout(function () { + mockDb.state = 'new'; + }, 10); + }); + + await util.promisify(function (cb) { + server.listen(0, cb); + })(); + + t.ok(true, 'after server'); + + t.ok(true, 'before request'); + + var res = await util.promisify(function (cb) { + var req = http.request({ + hostname: 'localhost', + port: server.address().port, + path: '/', + method: 'GET' + }, function (resp) { + cb(null, resp); + }); + req.end(); + })(); + + t.ok(true, 'after request'); + + res.resume(); + t.equal(res.statusCode, 200, 'res.statusCode is 200'); + + setTimeout(function () { + t.equal(mockDb.state, 'new', 'mockDb.state is new'); + + server.close(function (err) { + t.ifError(err, 'error on close'); + t.end(); + }); + }, 50); + } catch (err) { + t.ifError(err, 'error in catch'); + t.end(); + } }); diff --git a/test/async-await/sync-error.js b/test/async-await/sync-error.js index f2d825cc..314bc867 100644 --- a/test/async-await/sync-error.js +++ b/test/async-await/sync-error.js @@ -3,9 +3,9 @@ var test = require('../../'); test('sync-error', function myTest(t) { - t.ok(true, 'before throw'); - throw new Error('oopsie'); - /* eslint no-unreachable: 0 */ - t.ok(true, 'after throw'); - t.end(); + t.ok(true, 'before throw'); + throw new Error('oopsie'); + /* eslint no-unreachable: 0 */ + t.ok(true, 'after throw'); + t.end(); }); diff --git a/test/bound.js b/test/bound.js index cff296b3..e233a5c9 100644 --- a/test/bound.js +++ b/test/bound.js @@ -3,10 +3,10 @@ var test = require('../'); test('bind works', function (t) { - t.plan(2); - var equal = t.equal; - var deepEqual = t.deepEqual; - equal(3, 3); - deepEqual([4], [4]); - t.end(); + t.plan(2); + var equal = t.equal; + var deepEqual = t.deepEqual; + equal(3, 3); + deepEqual([4], [4]); + t.end(); }); diff --git a/test/browser/asserts.js b/test/browser/asserts.js index fb981b7c..0e59e8a0 100644 --- a/test/browser/asserts.js +++ b/test/browser/asserts.js @@ -3,9 +3,9 @@ var test = require('../../'); test(function (t) { - t.plan(4); - t.ok(true); - t.equal(3, 1 + 2); - t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]); - t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]); + t.plan(4); + t.ok(true); + t.equal(3, 1 + 2); + t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]); + t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]); }); diff --git a/test/child_ordering.js b/test/child_ordering.js index 6c75f587..01263048 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -5,52 +5,52 @@ var test = require('../'); var childRan = false; test('parent', function (t) { - t.test('child', function (st) { - childRan = true; - st.pass('child ran'); - st.end(); - }); - t.end(); + t.test('child', function (st) { + childRan = true; + st.pass('child ran'); + st.end(); + }); + t.end(); }); test('uncle', function (t) { - t.ok(childRan, 'Child should run before next top-level test'); - t.end(); + t.ok(childRan, 'Child should run before next top-level test'); + t.end(); }); var grandParentRan = false; var parentRan = false; var grandChildRan = false; test('grandparent', function (t) { - t.ok(!grandParentRan, 'grand parent ran twice'); - grandParentRan = true; - t.test('parent', function (st) { - st.ok(!parentRan, 'parent ran twice'); - parentRan = true; - st.test('grandchild', function (s2t) { - s2t.ok(!grandChildRan, 'grand child ran twice'); - grandChildRan = true; - s2t.pass('grand child ran'); - s2t.end(); - }); - st.pass('parent ran'); - st.end(); - }); - t.test('other parent', function (st) { - st.ok(parentRan, 'first parent runs before second parent'); - st.ok(grandChildRan, 'grandchild runs before second parent'); - st.end(); - }); - t.pass('grandparent ran'); - t.end(); + t.ok(!grandParentRan, 'grand parent ran twice'); + grandParentRan = true; + t.test('parent', function (st) { + st.ok(!parentRan, 'parent ran twice'); + parentRan = true; + st.test('grandchild', function (s2t) { + s2t.ok(!grandChildRan, 'grand child ran twice'); + grandChildRan = true; + s2t.pass('grand child ran'); + s2t.end(); + }); + st.pass('parent ran'); + st.end(); + }); + t.test('other parent', function (st) { + st.ok(parentRan, 'first parent runs before second parent'); + st.ok(grandChildRan, 'grandchild runs before second parent'); + st.end(); + }); + t.pass('grandparent ran'); + t.end(); }); test('second grandparent', function (t) { - t.ok(grandParentRan, 'grandparent ran'); - t.ok(parentRan, 'parent ran'); - t.ok(grandChildRan, 'grandchild ran'); - t.pass('other grandparent ran'); - t.end(); + t.ok(grandParentRan, 'grandparent ran'); + t.ok(parentRan, 'parent ran'); + t.ok(grandChildRan, 'grandchild ran'); + t.pass('other grandparent ran'); + t.end(); }); // vim: set softtabstop=4 shiftwidth=4: diff --git a/test/circular-things.js b/test/circular-things.js index 37786b51..af2b9850 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -7,40 +7,40 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('circular test', function (assert) { - var test = tape.createHarness({ exit: false }); - assert.plan(1); + var test = tape.createHarness({ exit: false }); + assert.plan(1); - test.createStream().pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# circular', - 'not ok 1 should be strictly equal', - ' ---', - ' operator: equal', - ' expected: |-', - ' {}', - ' actual: |-', - ' { circular: [Circular] }', - ' at: Test. ($TEST/circular-things.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be strictly equal', - ' [... stack stripped ...]', - ' at Test. ($TEST/circular-things.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - })); + test.createStream().pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# circular', + 'not ok 1 should be strictly equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' {}', + ' actual: |-', + ' { circular: [Circular] }', + ' at: Test. ($TEST/circular-things.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be strictly equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/circular-things.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + })); - test('circular', function (t) { - t.plan(1); - var circular = {}; - circular.circular = circular; - t.equal(circular, {}); - }); + test('circular', function (t) { + t.plan(1); + var circular = {}; + circular.circular = circular; + t.equal(circular, {}); + }); }); diff --git a/test/comment.js b/test/comment.js index 68843563..ed00580f 100644 --- a/test/comment.js +++ b/test/comment.js @@ -7,185 +7,185 @@ var tape = require('../'); // Exploratory test to ascertain proper output when no t.comment() call // is made. tap.test('no comment', function (assert) { - assert.plan(1); - - var verify = function (output) { - assert.deepEqual(output.toString('utf8').split('\n'), [ - 'TAP version 13', - '# no comment', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' - ]); - }; - - var test = tape.createHarness(); - test.createStream().pipe(concat(verify)); - test('no comment', function (t) { - t.end(); - }); + assert.plan(1); + + var verify = function (output) { + assert.deepEqual(output.toString('utf8').split('\n'), [ + 'TAP version 13', + '# no comment', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ]); + }; + + var test = tape.createHarness(); + test.createStream().pipe(concat(verify)); + test('no comment', function (t) { + t.end(); + }); }); // Exploratory test, can we call t.comment() passing nothing? tap.test('missing argument', function (assert) { - assert.plan(1); - var test = tape.createHarness(); - test.createStream(); - test('missing argument', function (t) { - try { - t.comment(); - t.end(); - } catch (err) { - assert.equal(err.constructor, TypeError); - } finally { - assert.end(); - } - }); + assert.plan(1); + var test = tape.createHarness(); + test.createStream(); + test('missing argument', function (t) { + try { + t.comment(); + t.end(); + } catch (err) { + assert.equal(err.constructor, TypeError); + } finally { + assert.end(); + } + }); }); // Exploratory test, can we call t.comment() passing nothing? tap.test('null argument', function (assert) { - assert.plan(1); - var test = tape.createHarness(); - test.createStream(); - test('null argument', function (t) { - try { - t.comment(null); - t.end(); - } catch (err) { - assert.equal(err.constructor, TypeError); - } finally { - assert.end(); - } - }); + assert.plan(1); + var test = tape.createHarness(); + test.createStream(); + test('null argument', function (t) { + try { + t.comment(null); + t.end(); + } catch (err) { + assert.equal(err.constructor, TypeError); + } finally { + assert.end(); + } + }); }); // Exploratory test, how is whitespace treated? tap.test('whitespace', function (assert) { - assert.plan(1); - - var verify = function (output) { - assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# whitespace', - '# ', - '# a', - '# a', - '# a', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' - ].join('\n')); - }; - - var test = tape.createHarness(); - test.createStream().pipe(concat(verify)); - test('whitespace', function (t) { - t.comment(' '); - t.comment(' a'); - t.comment('a '); - t.comment(' a '); - t.end(); - }); + assert.plan(1); + + var verify = function (output) { + assert.equal(output.toString('utf8'), [ + 'TAP version 13', + '# whitespace', + '# ', + '# a', + '# a', + '# a', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ].join('\n')); + }; + + var test = tape.createHarness(); + test.createStream().pipe(concat(verify)); + test('whitespace', function (t) { + t.comment(' '); + t.comment(' a'); + t.comment('a '); + t.comment(' a '); + t.end(); + }); }); // Exploratory test, how about passing types other than strings? tap.test('non-string types', function (assert) { - assert.plan(1); - - var verify = function (output) { - assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# non-string types', - '# true', - '# false', - '# 42', - '# 6.66', - '# [object Object]', - '# [object Object]', - '# [object Object]', - '# function ConstructorFunction() {}', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' - ].join('\n')); - }; - - var test = tape.createHarness(); - test.createStream().pipe(concat(verify)); - test('non-string types', function (t) { - t.comment(true); - t.comment(false); - t.comment(42); - t.comment(6.66); - t.comment({}); - t.comment({ answer: 42 }); - function ConstructorFunction() {} - t.comment(new ConstructorFunction()); - t.comment(ConstructorFunction); - t.end(); - }); + assert.plan(1); + + var verify = function (output) { + assert.equal(output.toString('utf8'), [ + 'TAP version 13', + '# non-string types', + '# true', + '# false', + '# 42', + '# 6.66', + '# [object Object]', + '# [object Object]', + '# [object Object]', + '# function ConstructorFunction() {}', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ].join('\n')); + }; + + var test = tape.createHarness(); + test.createStream().pipe(concat(verify)); + test('non-string types', function (t) { + t.comment(true); + t.comment(false); + t.comment(42); + t.comment(6.66); + t.comment({}); + t.comment({ answer: 42 }); + function ConstructorFunction() {} + t.comment(new ConstructorFunction()); + t.comment(ConstructorFunction); + t.end(); + }); }); tap.test('multiline string', function (assert) { - assert.plan(1); - - var verify = function (output) { - assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# multiline strings', - '# a', - '# b', - '# c', - '# d', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' - ].join('\n')); - }; - - var test = tape.createHarness(); - test.createStream().pipe(concat(verify)); - test('multiline strings', function (t) { - t.comment([ - 'a', - 'b' - ].join('\n')); - t.comment([ - 'c', - 'd' - ].join('\r\n')); - t.end(); - }); + assert.plan(1); + + var verify = function (output) { + assert.equal(output.toString('utf8'), [ + 'TAP version 13', + '# multiline strings', + '# a', + '# b', + '# c', + '# d', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ].join('\n')); + }; + + var test = tape.createHarness(); + test.createStream().pipe(concat(verify)); + test('multiline strings', function (t) { + t.comment([ + 'a', + 'b' + ].join('\n')); + t.comment([ + 'c', + 'd' + ].join('\r\n')); + t.end(); + }); }); tap.test('comment with createStream/objectMode', function (assert) { - assert.plan(1); - - var test = tape.createHarness(); - test.createStream({ objectMode: true }).on('data', function (row) { - if (typeof row === 'string') { - assert.equal(row, 'comment message'); - } - }); - test('t.comment', function (t) { - t.comment('comment message'); - t.end(); - }); + assert.plan(1); + + var test = tape.createHarness(); + test.createStream({ objectMode: true }).on('data', function (row) { + if (typeof row === 'string') { + assert.equal(row, 'comment message'); + } + }); + test('t.comment', function (t) { + t.comment('comment message'); + t.end(); + }); }); diff --git a/test/common.js b/test/common.js index e7882355..5856cf3d 100644 --- a/test/common.js +++ b/test/common.js @@ -6,18 +6,18 @@ var concat = require('concat-stream'); var yaml = require('js-yaml'); module.exports.getDiag = function (body) { - var yamlStart = body.indexOf(' ---'); - var yamlEnd = body.indexOf(' ...\n'); - var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { - return line.slice(2); - }).join('\n'); + var yamlStart = body.indexOf(' ---'); + var yamlEnd = body.indexOf(' ...\n'); + var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { + return line.slice(2); + }).join('\n'); - // The stack trace and at variable will vary depending on where the code - // is run, so just strip it out. - var withStack = yaml.safeLoad(diag); - delete withStack.stack; - delete withStack.at; - return withStack; + // The stack trace and at variable will vary depending on where the code + // is run, so just strip it out. + var withStack = yaml.safeLoad(diag); + delete withStack.stack; + delete withStack.at; + return withStack; }; // There are three challenges associated with checking the stack traces included @@ -37,68 +37,68 @@ module.exports.getDiag = function (body) { // and replace them with placeholders. var stripChangingData = function (line) { - var withoutTestDir = line.replace(__dirname, '$TEST'); - var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); - var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/'); - var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL'); - var withoutNestedLineNumbers = withoutLineNumbers.replace(/, :\$LINE:\$COL\)$/, ')'); - return withoutNestedLineNumbers; + var withoutTestDir = line.replace(__dirname, '$TEST'); + var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); + var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/'); + var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL'); + var withoutNestedLineNumbers = withoutLineNumbers.replace(/, :\$LINE:\$COL\)$/, ')'); + return withoutNestedLineNumbers; }; module.exports.stripFullStack = function (output) { - var stripped = ' [... stack stripped ...]'; - var withDuplicates = output.split(/\r?\n/g).map(stripChangingData).map(function (line) { - var m = line.match(/[ ]{8}at .*\((.*)\)/); + var stripped = ' [... stack stripped ...]'; + var withDuplicates = output.split(/\r?\n/g).map(stripChangingData).map(function (line) { + var m = line.match(/[ ]{8}at .*\((.*)\)/); - if (m && m[1].slice(0, 5) !== '$TEST') { - return stripped; - } - return line; - }); + if (m && m[1].slice(0, 5) !== '$TEST') { + return stripped; + } + return line; + }); - var withoutInternals = withDuplicates.filter(function (line) { - return !line.match(/ \(node:[^)]+\)$/); - }); + var withoutInternals = withDuplicates.filter(function (line) { + return !line.match(/ \(node:[^)]+\)$/); + }); - var deduped = withoutInternals.filter(function (line, ix) { - var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; - return !hasPrior; - }); + var deduped = withoutInternals.filter(function (line, ix) { + var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; + return !hasPrior; + }); - return deduped.join('\n').replace( - // Handle stack trace variation in Node v0.8 - /at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g, - 'at$1 Test.' - ).replace( - // Handle stack trace variation in Node v0.8 - /at(:?) (Test\.)?tap\.test\.test\.skip/g, - 'at$1 $2' - ).replace( - // Handle stack trace variation in Node v0.8 - /(\[\.\.\. stack stripped \.\.\.\]\r?\n *at) \(([^)]+)\)/g, - '$1 $2' - ).split(/\r?\n/g); + return deduped.join('\n').replace( + // Handle stack trace variation in Node v0.8 + /at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g, + 'at$1 Test.' + ).replace( + // Handle stack trace variation in Node v0.8 + /at(:?) (Test\.)?tap\.test\.test\.skip/g, + 'at$1 $2' + ).replace( + // Handle stack trace variation in Node v0.8 + /(\[\.\.\. stack stripped \.\.\.\]\r?\n *at) \(([^)]+)\)/g, + '$1 $2' + ).split(/\r?\n/g); }; module.exports.runProgram = function (folderName, fileName, cb) { - var result = { - stdout: null, - stderr: null, - exitCode: 0 - }; - var ps = spawn(process.execPath, [ - path.join(__dirname, folderName, fileName) - ]); + var result = { + stdout: null, + stderr: null, + exitCode: 0 + }; + var ps = spawn(process.execPath, [ + path.join(__dirname, folderName, fileName) + ]); - ps.stdout.pipe(concat(function (stdoutRows) { - result.stdout = stdoutRows; - })); - ps.stderr.pipe(concat(function (stderrRows) { - result.stderr = stderrRows; - })); + ps.stdout.pipe(concat(function (stdoutRows) { + result.stdout = stdoutRows; + })); + ps.stderr.pipe(concat(function (stderrRows) { + result.stderr = stderrRows; + })); - ps.on('exit', function (code) { - result.exitCode = code; - cb(result); - }); + ps.on('exit', function (code) { + result.exitCode = code; + cb(result); + }); }; diff --git a/test/create_multiple_streams.js b/test/create_multiple_streams.js index 9307e881..965e984a 100644 --- a/test/create_multiple_streams.js +++ b/test/create_multiple_streams.js @@ -3,30 +3,30 @@ var tape = require('../'); tape.test('createMultipleStreams', function (tt) { - tt.plan(2); - - var th = tape.createHarness(); - th.createStream(); - th.createStream(); - - var testOneComplete = false; - - th('test one', function (tht) { - tht.plan(1); - setTimeout(function () { - tht.pass(); - testOneComplete = true; - }, 100); - }); - - th('test two', function (tht) { - tht.ok(testOneComplete, 'test 1 completed before test 2'); - tht.end(); - }); - - th.onFinish(function () { - tt.equal(th._results.count, 2, 'harness test ran'); - tt.equal(th._results.fail, 0, "harness test didn't fail"); - }); + tt.plan(2); + + var th = tape.createHarness(); + th.createStream(); + th.createStream(); + + var testOneComplete = false; + + th('test one', function (tht) { + tht.plan(1); + setTimeout(function () { + tht.pass(); + testOneComplete = true; + }, 100); + }); + + th('test two', function (tht) { + tht.ok(testOneComplete, 'test 1 completed before test 2'); + tht.end(); + }); + + th.onFinish(function () { + tt.equal(th._results.count, 2, 'harness test ran'); + tt.equal(th._results.fail, 0, "harness test didn't fail"); + }); }); diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index dfdff536..88ed34c7 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -10,187 +10,187 @@ var getDiag = common.getDiag; var stripFullStack = common.stripFullStack; tap.test('deep equal failure', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# deep equal', - 'not ok 1 should be strictly equal', - ' ---', - ' operator: equal', - ' expected: |-', - ' { b: 2 }', - ' actual: |-', - ' { a: 1 }', - ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be strictly equal', - ' [... stack stripped ...]', - ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ b: 2 }', - actual: '{ a: 1 }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should be strictly equal', - diag: { - operator: 'equal', - expected: '{ b: 2 }', - actual: '{ a: 1 }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('deep equal', function (t) { - t.plan(1); - t.equal({ a: 1 }, { b: 2 }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be strictly equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { b: 2 }', + ' actual: |-', + ' { a: 1 }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be strictly equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'equal', + expected: '{ b: 2 }', + actual: '{ a: 1 }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should be strictly equal', + diag: { + operator: 'equal', + expected: '{ b: 2 }', + actual: '{ a: 1 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('deep equal', function (t) { + t.plan(1); + t.equal({ a: 1 }, { b: 2 }); + }); }); tap.test('deep equal failure, depth 6, with option', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# deep equal', - 'not ok 1 should be strictly equal', - ' ---', - ' operator: equal', - ' expected: |-', - ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - ' actual: |-', - ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be strictly equal', - ' [... stack stripped ...]', - ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should be strictly equal', - diag: { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('deep equal', { objectPrintDepth: 6 }, function (t) { - t.plan(1); - t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be strictly equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be strictly equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should be strictly equal', + diag: { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('deep equal', { objectPrintDepth: 6 }, function (t) { + t.plan(1); + t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); + }); }); tap.test('deep equal failure, depth 6, without option', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# deep equal', - 'not ok 1 should be strictly equal', - ' ---', - ' operator: equal', - ' expected: |-', - ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', - ' actual: |-', - ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', - ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be strictly equal', - ' [... stack stripped ...]', - ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should be strictly equal', - diag: { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('deep equal', function (t) { - t.plan(1); - t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# deep equal', + 'not ok 1 should be strictly equal', + ' ---', + ' operator: equal', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be strictly equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should be strictly equal', + diag: { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('deep equal', function (t) { + t.plan(1); + t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); + }); }); diff --git a/test/deep.js b/test/deep.js index 8e41a2fa..944b519d 100644 --- a/test/deep.js +++ b/test/deep.js @@ -3,35 +3,35 @@ var test = require('../'); test('deep strict equal', function (t) { - t.notDeepEqual( - [{ a: '3' }], - [{ a: 3 }] - ); - t.end(); + t.notDeepEqual( + [{ a: '3' }], + [{ a: 3 }] + ); + t.end(); }); test('deep loose equal', function (t) { - t.deepLooseEqual( - [{ a: '3' }], - [{ a: 3 }] - ); - t.end(); + t.deepLooseEqual( + [{ a: '3' }], + [{ a: 3 }] + ); + t.end(); }); test('requires 2 arguments', function (t) { - var err = /^TypeError: two arguments must be provided/; - t.throws(function () { t.deepEqual(); }, err, 'deepEqual: no args'); - t.throws(function () { t.deepEqual(undefined); }, err, 'deepEqual: one arg'); - t.throws(function () { t.deepLooseEqual(); }, err, 'deepLooseEqual: no args'); - t.throws(function () { t.deepLooseEqual(undefined); }, err, 'deepLooseEqual: one arg'); - t.throws(function () { t.notDeepEqual(); }, err, 'notDeepEqual: no args'); - t.throws(function () { t.notDeepEqual(undefined); }, err, 'notDeepEqual: one arg'); - t.throws(function () { t.notDeepLooseEqual(); }, err, 'notDeepLooseEqual: no args'); - t.throws(function () { t.notDeepLooseEqual(undefined); }, err, 'notDeepLooseEqual: one arg'); - t.throws(function () { t.equal(); }, err, 'equal: no args'); - t.throws(function () { t.equal(undefined); }, err, 'equal: one arg'); - t.throws(function () { t.notEqual(); }, err, 'notEqual: no args'); - t.throws(function () { t.notEqual(undefined); }, err, 'notEqual: one arg'); + var err = /^TypeError: two arguments must be provided/; + t.throws(function () { t.deepEqual(); }, err, 'deepEqual: no args'); + t.throws(function () { t.deepEqual(undefined); }, err, 'deepEqual: one arg'); + t.throws(function () { t.deepLooseEqual(); }, err, 'deepLooseEqual: no args'); + t.throws(function () { t.deepLooseEqual(undefined); }, err, 'deepLooseEqual: one arg'); + t.throws(function () { t.notDeepEqual(); }, err, 'notDeepEqual: no args'); + t.throws(function () { t.notDeepEqual(undefined); }, err, 'notDeepEqual: one arg'); + t.throws(function () { t.notDeepLooseEqual(); }, err, 'notDeepLooseEqual: no args'); + t.throws(function () { t.notDeepLooseEqual(undefined); }, err, 'notDeepLooseEqual: one arg'); + t.throws(function () { t.equal(); }, err, 'equal: no args'); + t.throws(function () { t.equal(undefined); }, err, 'equal: one arg'); + t.throws(function () { t.notEqual(); }, err, 'notEqual: no args'); + t.throws(function () { t.notEqual(undefined); }, err, 'notEqual: one arg'); - t.end(); + t.end(); }); diff --git a/test/default-messages.js b/test/default-messages.js index 70d113bb..1f302c96 100644 --- a/test/default-messages.js +++ b/test/default-messages.js @@ -8,44 +8,44 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('default messages', function (t) { - t.plan(1); + t.plan(1); - var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); + var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); - ps.stdout.pipe(concat(function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# default messages', - 'ok 1 should be truthy', - 'ok 2 should be falsy', - 'ok 3 should be strictly equal', - 'ok 4 should not be strictly equal', - 'ok 5 should be loosely equal', - 'ok 6 should not be loosely equal', - 'ok 7 should be strictly equal', - 'ok 8 should not be strictly equal', - 'ok 9 should be deeply equivalent', - 'not ok 10 should not be deeply equivalent', - ' ---', - ' operator: notDeepEqual', - ' expected: true', - ' actual: true', - ' at: Test. ($TEST/messages/defaults.js:$LINE:$COL)', - ' stack: |-', - ' Error: should not be deeply equivalent', - ' [... stack stripped ...]', - ' at Test. ($TEST/messages/defaults.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 11 should be loosely deeply equivalent', - 'ok 12 should not be loosely deeply equivalent', - '', - '1..12', - '# tests 12', - '# pass 11', - '# fail 1', - '', - '' - ]); - })); + ps.stdout.pipe(concat(function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# default messages', + 'ok 1 should be truthy', + 'ok 2 should be falsy', + 'ok 3 should be strictly equal', + 'ok 4 should not be strictly equal', + 'ok 5 should be loosely equal', + 'ok 6 should not be loosely equal', + 'ok 7 should be strictly equal', + 'ok 8 should not be strictly equal', + 'ok 9 should be deeply equivalent', + 'not ok 10 should not be deeply equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: true', + ' actual: true', + ' at: Test. ($TEST/messages/defaults.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be deeply equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/messages/defaults.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 11 should be loosely deeply equivalent', + 'ok 12 should not be loosely deeply equivalent', + '', + '1..12', + '# tests 12', + '# pass 11', + '# fail 1', + '', + '' + ]); + })); }); diff --git a/test/double_end.js b/test/double_end.js index a3445ab6..de91b83f 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -8,56 +8,56 @@ var spawn = require('child_process').spawn; var stripFullStack = require('./common').stripFullStack; test(function (tt) { - tt.plan(2); - var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]); - ps.on('exit', function (code) { - tt.equal(code, 1); - }); - ps.stdout.pipe(concat(function (body) { - // The implementation of node's timer library has changed over time. We - // need to reverse engineer the error we expect to see. + tt.plan(2); + var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]); + ps.on('exit', function (code) { + tt.equal(code, 1); + }); + ps.stdout.pipe(concat(function (body) { + // The implementation of node's timer library has changed over time. We + // need to reverse engineer the error we expect to see. - // This code is unfortunately by necessity highly coupled to node - // versions, and may require tweaking with future versions of the timers - // library. - function doEnd() { throw new Error(); } - var to = setTimeout(doEnd, 5000); - clearTimeout(to); - to._onTimeout = doEnd; + // This code is unfortunately by necessity highly coupled to node + // versions, and may require tweaking with future versions of the timers + // library. + function doEnd() { throw new Error(); } + var to = setTimeout(doEnd, 5000); + clearTimeout(to); + to._onTimeout = doEnd; - var stackExpected; - var atExpected; - try { - to._onTimeout(); - } catch (e) { - stackExpected = stripFullStack(e.stack)[1]; - stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); - stackExpected = stackExpected.trim(); - atExpected = stackExpected.replace(/^at\s+/, 'at: '); - } + var stackExpected; + var atExpected; + try { + to._onTimeout(); + } catch (e) { + stackExpected = stripFullStack(e.stack)[1]; + stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); + stackExpected = stackExpected.trim(); + atExpected = stackExpected.replace(/^at\s+/, 'at: '); + } - var stripped = stripFullStack(body.toString('utf8')); - tt.same(stripped, [ - 'TAP version 13', - '# double end', - 'ok 1 should be strictly equal', - 'not ok 2 .end() already called', - ' ---', - ' operator: fail', - ' ' + atExpected, - ' stack: |-', - ' Error: .end() already called', - ' [... stack stripped ...]', - ' ' + stackExpected, - ' [... stack stripped ...]', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ]); - })); + var stripped = stripFullStack(body.toString('utf8')); + tt.same(stripped, [ + 'TAP version 13', + '# double end', + 'ok 1 should be strictly equal', + 'not ok 2 .end() already called', + ' ---', + ' operator: fail', + ' ' + atExpected, + ' stack: |-', + ' Error: .end() already called', + ' [... stack stripped ...]', + ' ' + stackExpected, + ' [... stack stripped ...]', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ]); + })); }); diff --git a/test/double_end/double.js b/test/double_end/double.js index 2c0ae405..1a4d470d 100644 --- a/test/double_end/double.js +++ b/test/double_end/double.js @@ -3,11 +3,11 @@ var test = require('../../'); test('double end', function (t) { - function doEnd() { - t.end(); - } + function doEnd() { + t.end(); + } - t.equal(1 + 1, 2); - t.end(); - setTimeout(doEnd, 5); + t.equal(1 + 1, 2); + t.end(); + setTimeout(doEnd, 5); }); diff --git a/test/edge-cases.js b/test/edge-cases.js index bf4f2e37..8b230bc5 100644 --- a/test/edge-cases.js +++ b/test/edge-cases.js @@ -7,283 +7,283 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('edge cases', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# zeroes', - 'not ok 1 0 equal to -0', - ' ---', - ' operator: equal', - ' expected: |-', - ' -0', - ' actual: |-', - ' 0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: 0 equal to -0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 2 -0 equal to 0', - ' ---', - ' operator: equal', - ' expected: |-', - ' 0', - ' actual: |-', - ' -0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: -0 equal to 0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 3 0 notEqual to -0', - 'ok 4 -0 notEqual to 0', - 'ok 5 0 looseEqual to -0', - 'ok 6 -0 looseEqual to 0', - 'not ok 7 0 notLooseEqual to -0', - ' ---', - ' operator: notLooseEqual', - ' expected: |-', - ' -0', - ' actual: |-', - ' 0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: 0 notLooseEqual to -0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 8 -0 notLooseEqual to 0', - ' ---', - ' operator: notLooseEqual', - ' expected: |-', - ' 0', - ' actual: |-', - ' -0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: -0 notLooseEqual to 0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 9 0 strictEqual to -0', - ' ---', - ' operator: equal', - ' expected: |-', - ' -0', - ' actual: |-', - ' 0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: 0 strictEqual to -0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 10 -0 strictEqual to 0', - ' ---', - ' operator: equal', - ' expected: |-', - ' 0', - ' actual: |-', - ' -0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: -0 strictEqual to 0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 11 0 notStrictEqual to -0', - 'ok 12 -0 notStrictEqual to 0', - 'ok 13 0 deepLooseEqual to -0', - 'ok 14 -0 deepLooseEqual to 0', - 'not ok 15 0 notDeepLooseEqual to -0', - ' ---', - ' operator: notDeepLooseEqual', - ' expected: |-', - ' -0', - ' actual: |-', - ' 0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: 0 notDeepLooseEqual to -0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 16 -0 notDeepLooseEqual to 0', - ' ---', - ' operator: notDeepLooseEqual', - ' expected: |-', - ' 0', - ' actual: |-', - ' -0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: -0 notDeepLooseEqual to 0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 17 0 deepEqual to -0', - ' ---', - ' operator: deepEqual', - ' expected: |-', - ' -0', - ' actual: |-', - ' 0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: 0 deepEqual to -0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 18 -0 deepEqual to 0', - ' ---', - ' operator: deepEqual', - ' expected: |-', - ' 0', - ' actual: |-', - ' -0', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: -0 deepEqual to 0', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 19 0 notDeepEqual to -0', - 'ok 20 -0 notDeepEqual to 0', - '# NaNs', - 'ok 21 NaN equal to NaN', - 'not ok 22 NaN notEqual to NaN', - ' ---', - ' operator: notEqual', - ' expected: NaN', - ' actual: NaN', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: NaN notEqual to NaN', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 23 NaN looseEqual to NaN', - ' ---', - ' operator: looseEqual', - ' expected: NaN', - ' actual: NaN', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: NaN looseEqual to NaN', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 24 NaN notLooseEqual to NaN', - 'ok 25 NaN strictEqual to NaN', - 'not ok 26 NaN notStrictEqual to NaN', - ' ---', - ' operator: notEqual', - ' expected: NaN', - ' actual: NaN', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: NaN notStrictEqual to NaN', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 27 NaN deepLooseEqual to NaN', - ' ---', - ' operator: deepLooseEqual', - ' expected: NaN', - ' actual: NaN', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: NaN deepLooseEqual to NaN', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 28 NaN notDeepLooseEqual to NaN', - 'ok 29 NaN deepEqual to NaN', - 'not ok 30 NaN notDeepEqual to NaN', - ' ---', - ' operator: notDeepEqual', - ' expected: NaN', - ' actual: NaN', - ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' stack: |-', - ' Error: NaN notDeepEqual to NaN', - ' [... stack stripped ...]', - ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..30', - '# tests 30', - '# pass 15', - '# fail 15', - '' - ]); - })); + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# zeroes', + 'not ok 1 0 equal to -0', + ' ---', + ' operator: equal', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 equal to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 -0 equal to 0', + ' ---', + ' operator: equal', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 equal to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 3 0 notEqual to -0', + 'ok 4 -0 notEqual to 0', + 'ok 5 0 looseEqual to -0', + 'ok 6 -0 looseEqual to 0', + 'not ok 7 0 notLooseEqual to -0', + ' ---', + ' operator: notLooseEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notLooseEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 -0 notLooseEqual to 0', + ' ---', + ' operator: notLooseEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notLooseEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 9 0 strictEqual to -0', + ' ---', + ' operator: equal', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 strictEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 10 -0 strictEqual to 0', + ' ---', + ' operator: equal', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 strictEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 11 0 notStrictEqual to -0', + 'ok 12 -0 notStrictEqual to 0', + 'ok 13 0 deepLooseEqual to -0', + 'ok 14 -0 deepLooseEqual to 0', + 'not ok 15 0 notDeepLooseEqual to -0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 notDeepLooseEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 16 -0 notDeepLooseEqual to 0', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 notDeepLooseEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 17 0 deepEqual to -0', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' -0', + ' actual: |-', + ' 0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: 0 deepEqual to -0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 18 -0 deepEqual to 0', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' 0', + ' actual: |-', + ' -0', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: -0 deepEqual to 0', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 19 0 notDeepEqual to -0', + 'ok 20 -0 notDeepEqual to 0', + '# NaNs', + 'ok 21 NaN equal to NaN', + 'not ok 22 NaN notEqual to NaN', + ' ---', + ' operator: notEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN notEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 23 NaN looseEqual to NaN', + ' ---', + ' operator: looseEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN looseEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 24 NaN notLooseEqual to NaN', + 'ok 25 NaN strictEqual to NaN', + 'not ok 26 NaN notStrictEqual to NaN', + ' ---', + ' operator: notEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN notStrictEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 27 NaN deepLooseEqual to NaN', + ' ---', + ' operator: deepLooseEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN deepLooseEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 28 NaN notDeepLooseEqual to NaN', + 'ok 29 NaN deepEqual to NaN', + 'not ok 30 NaN notDeepEqual to NaN', + ' ---', + ' operator: notDeepEqual', + ' expected: NaN', + ' actual: NaN', + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' stack: |-', + ' Error: NaN notDeepEqual to NaN', + ' [... stack stripped ...]', + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..30', + '# tests 30', + '# pass 15', + '# fail 15', + '' + ]); + })); - test('zeroes', function (t) { - t.equal(0, -0, '0 equal to -0'); - t.equal(-0, 0, '-0 equal to 0'); - t.notEqual(0, -0, '0 notEqual to -0'); - t.notEqual(-0, 0, '-0 notEqual to 0'); + test('zeroes', function (t) { + t.equal(0, -0, '0 equal to -0'); + t.equal(-0, 0, '-0 equal to 0'); + t.notEqual(0, -0, '0 notEqual to -0'); + t.notEqual(-0, 0, '-0 notEqual to 0'); - t.looseEqual(0, -0, '0 looseEqual to -0'); - t.looseEqual(-0, 0, '-0 looseEqual to 0'); - t.notLooseEqual(0, -0, '0 notLooseEqual to -0'); - t.notLooseEqual(-0, 0, '-0 notLooseEqual to 0'); + t.looseEqual(0, -0, '0 looseEqual to -0'); + t.looseEqual(-0, 0, '-0 looseEqual to 0'); + t.notLooseEqual(0, -0, '0 notLooseEqual to -0'); + t.notLooseEqual(-0, 0, '-0 notLooseEqual to 0'); - t.strictEqual(0, -0, '0 strictEqual to -0'); - t.strictEqual(-0, 0, '-0 strictEqual to 0'); - t.notStrictEqual(0, -0, '0 notStrictEqual to -0'); - t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0'); + t.strictEqual(0, -0, '0 strictEqual to -0'); + t.strictEqual(-0, 0, '-0 strictEqual to 0'); + t.notStrictEqual(0, -0, '0 notStrictEqual to -0'); + t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0'); - t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0'); - t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0'); - t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0'); - t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0'); + t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0'); + t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0'); + t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0'); + t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0'); - t.deepEqual(0, -0, '0 deepEqual to -0'); - t.deepEqual(-0, 0, '-0 deepEqual to 0'); - t.notDeepEqual(0, -0, '0 notDeepEqual to -0'); - t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0'); + t.deepEqual(0, -0, '0 deepEqual to -0'); + t.deepEqual(-0, 0, '-0 deepEqual to 0'); + t.notDeepEqual(0, -0, '0 notDeepEqual to -0'); + t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0'); - t.end(); - }); + t.end(); + }); - test('NaNs', function (t) { - t.equal(NaN, NaN, 'NaN equal to NaN'); - t.notEqual(NaN, NaN, 'NaN notEqual to NaN'); + test('NaNs', function (t) { + t.equal(NaN, NaN, 'NaN equal to NaN'); + t.notEqual(NaN, NaN, 'NaN notEqual to NaN'); - t.looseEqual(NaN, NaN, 'NaN looseEqual to NaN'); - t.notLooseEqual(NaN, NaN, 'NaN notLooseEqual to NaN'); + t.looseEqual(NaN, NaN, 'NaN looseEqual to NaN'); + t.notLooseEqual(NaN, NaN, 'NaN notLooseEqual to NaN'); - t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN'); - t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN'); + t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN'); + t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN'); - t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN'); - t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN'); + t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN'); + t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN'); - t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN'); - t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN'); + t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN'); + t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN'); - t.end(); - }); + t.end(); + }); }); diff --git a/test/end-as-callback.js b/test/end-as-callback.js index d3cb1fc9..4bad681b 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -6,57 +6,57 @@ var tape = require('../'); var concat = require('concat-stream'); tap.test('tape assert.end as callback', function (tt) { - var test = tape.createHarness({ exit: false }); + var test = tape.createHarness({ exit: false }); - test.createStream().pipe(concat(function (rows) { - tt.equal(rows.toString('utf8'), [ - 'TAP version 13', - '# do a task and write', - 'ok 1 null', - 'ok 2 should be strictly equal', - '# do a task and write fail', - 'ok 3 null', - 'ok 4 should be strictly equal', - 'not ok 5 Error: fail', - getStackTrace(rows), // tap error stack - '', - '1..5', - '# tests 5', - '# pass 4', - '# fail 1' - ].join('\n') + '\n'); - tt.end(); - })); + test.createStream().pipe(concat(function (rows) { + tt.equal(rows.toString('utf8'), [ + 'TAP version 13', + '# do a task and write', + 'ok 1 null', + 'ok 2 should be strictly equal', + '# do a task and write fail', + 'ok 3 null', + 'ok 4 should be strictly equal', + 'not ok 5 Error: fail', + getStackTrace(rows), // tap error stack + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1' + ].join('\n') + '\n'); + tt.end(); + })); - test('do a task and write', function (assert) { - fakeAsyncTask('foo', function (err, value) { - assert.ifError(err); - assert.equal(value, 'taskfoo'); + test('do a task and write', function (assert) { + fakeAsyncTask('foo', function (err, value) { + assert.ifError(err); + assert.equal(value, 'taskfoo'); - fakeAsyncWrite('bar', assert.end); - }); - }); + fakeAsyncWrite('bar', assert.end); + }); + }); - test('do a task and write fail', function (assert) { - fakeAsyncTask('bar', function (err, value) { - assert.ifError(err); - assert.equal(value, 'taskbar'); + test('do a task and write fail', function (assert) { + fakeAsyncTask('bar', function (err, value) { + assert.ifError(err); + assert.equal(value, 'taskbar'); - fakeAsyncWriteFail('baz', assert.end); - }); - }); + fakeAsyncWriteFail('baz', assert.end); + }); + }); }); function fakeAsyncTask(name, cb) { - cb(null, 'task' + name); + cb(null, 'task' + name); } function fakeAsyncWrite(name, cb) { - cb(null); + cb(null); } function fakeAsyncWriteFail(name, cb) { - cb(new Error('fail')); + cb(new Error('fail')); } /** @@ -68,20 +68,20 @@ function fakeAsyncWriteFail(name, cb) { * @returns String stacktrace - just the error stack part */ function getStackTrace(rows) { - var stacktrace = ' ---\n'; - var extract = false; - forEach(rows.toString('utf8').split('\n'), function (row) { - if (!extract) { - if (row.indexOf('---') > -1) { // start of stack trace - extract = true; - } - } else if (row.indexOf('...') > -1) { // end of stack trace - extract = false; - stacktrace += ' ...'; - } else { - stacktrace += row + '\n'; - } - }); - // console.log(stacktrace); - return stacktrace; + var stacktrace = ' ---\n'; + var extract = false; + forEach(rows.toString('utf8').split('\n'), function (row) { + if (!extract) { + if (row.indexOf('---') > -1) { // start of stack trace + extract = true; + } + } else if (row.indexOf('...') > -1) { // end of stack trace + extract = false; + stacktrace += ' ...'; + } else { + stacktrace += row + '\n'; + } + }); + // console.log(stacktrace); + return stacktrace; } diff --git a/test/error.js b/test/error.js index 6b9025b3..41ee1f6f 100644 --- a/test/error.js +++ b/test/error.js @@ -7,33 +7,33 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('failures', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# error', - 'not ok 1 Error: this is a message', - ' ---', - ' operator: error', - ' at: Test. ($TEST/error.js:$LINE:$COL)', - ' stack: |-', - ' Error: this is a message', - ' at Test. ($TEST/error.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - })); + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# error', + 'not ok 1 Error: this is a message', + ' ---', + ' operator: error', + ' at: Test. ($TEST/error.js:$LINE:$COL)', + ' stack: |-', + ' Error: this is a message', + ' at Test. ($TEST/error.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + })); - test('error', function (t) { - t.plan(1); - t.error(new Error('this is a message')); - }); + test('error', function (t) { + t.plan(1); + t.error(new Error('this is a message')); + }); }); diff --git a/test/exit.js b/test/exit.js index 45c9df97..8ed986ad 100644 --- a/test/exit.js +++ b/test/exit.js @@ -8,244 +8,244 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('exit ok', function (t) { - t.plan(2); - - var tc = function (rows) { - t.same(rows.toString('utf8'), [ - 'TAP version 13', - '# array', - '# hi', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'ok 5 should be deeply 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); - }); + t.plan(2); + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ + 'TAP version 13', + '# array', + '# hi', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'ok 5 should be deeply 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 = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# array', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'not ok 5 should be deeply equivalent', - ' ---', - ' operator: deepEqual', - ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', - ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: ($TEST/exit/fail.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be deeply equivalent', - ' [... stack stripped ...]', - ' at $TEST/exit/fail.js:$LINE:$COL', - ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL))', - ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL))', - ' at Test. ($TEST/exit/fail.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..5', - '# tests 5', - '# pass 4', - '# fail 1', - '', - '' - ]); - }; - - 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); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# array', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'not ok 5 should be deeply equivalent', + ' ---', + ' operator: deepEqual', + ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', + ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' at: ($TEST/exit/fail.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be deeply equivalent', + ' [... stack stripped ...]', + ' at $TEST/exit/fail.js:$LINE:$COL', + ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL))', + ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL))', + ' at Test. ($TEST/exit/fail.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1', + '', + '' + ]); + }; + + 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 = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# array', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'ok 5 should be deeply equivalent', - 'not ok 6 plan != count', - ' ---', - ' operator: fail', - ' expected: 6', - ' actual: 5', - ' at: process. ($TAPE/index.js:$LINE:$COL)', - ' stack: |-', - ' Error: plan != count', - ' [... stack stripped ...]', - ' ...', - '', - '1..6', - '# tests 6', - '# pass 5', - '# fail 1', - '', - '' - ]); - }; - - 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); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# array', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'ok 5 should be deeply equivalent', + 'not ok 6 plan != count', + ' ---', + ' operator: fail', + ' expected: 6', + ' actual: 5', + ' at: process. ($TAPE/index.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' ...', + '', + '1..6', + '# tests 6', + '# pass 5', + '# fail 1', + '', + '' + ]); + }; + + 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 = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# first', - 'ok 1 should be truthy', - '# second', - 'ok 2 should be truthy', - 'not ok 3 plan != count', - ' ---', - ' operator: fail', - ' expected: 2', - ' actual: 1', - ' at: process. ($TAPE/index.js:$LINE:$COL)', - ' stack: |-', - ' Error: plan != count', - ' [... stack stripped ...]', - ' ...', - '', - '1..3', - '# tests 3', - '# pass 2', - '# fail 1', - '', - '' - ]); - }; - - 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); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# first', + 'ok 1 should be truthy', + '# second', + 'ok 2 should be truthy', + 'not ok 3 plan != count', + ' ---', + ' operator: fail', + ' expected: 2', + ' actual: 1', + ' at: process. ($TAPE/index.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' ...', + '', + '1..3', + '# tests 3', + '# pass 2', + '# fail 1', + '', + '' + ]); + }; + + 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); + }); }); tap.test('todo passing', function (t) { - t.plan(2); - - var tc = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# TODO todo pass', - 'ok 1 should be truthy # TODO', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '', - '' - ]); - }; - - var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - t.equal(code, 0); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# TODO todo pass', + 'ok 1 should be truthy # TODO', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '', + '' + ]); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + t.equal(code, 0); + }); }); tap.test('todo failing', function (t) { - t.plan(2); - - var tc = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# TODO todo fail', - 'not ok 1 should be truthy # TODO', - ' ---', - ' operator: ok', - ' expected: true', - ' actual: false', - ' at: Test. ($TEST/exit/todo_fail.js:$LINE:$COL)', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '', - '' - ]); - }; - - var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - t.equal(code, 0); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# TODO todo fail', + 'not ok 1 should be truthy # TODO', + ' ---', + ' operator: ok', + ' expected: true', + ' actual: false', + ' at: Test. ($TEST/exit/todo_fail.js:$LINE:$COL)', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '', + '' + ]); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + t.equal(code, 0); + }); }); tap.test('forgot to call t.end()', function (t) { - t.plan(2); - - var tc = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# first', - 'ok 1 should be truthy', - '# oops forgot end', - 'ok 2 should be truthy', - 'not ok 3 test exited without ending: oops forgot end', - ' ---', - ' operator: fail', - ' at: process. ($TAPE/index.js:$LINE:$COL)', - ' stack: |-', - ' Error: test exited without ending: oops forgot end', - ' [... stack stripped ...]', - ' ...', - '', - '1..3', - '# tests 3', - '# pass 2', - '# fail 1', - '', - '' - ]); - }; - - var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - t.notEqual(code, 0); - }); + t.plan(2); + + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# first', + 'ok 1 should be truthy', + '# oops forgot end', + 'ok 2 should be truthy', + 'not ok 3 test exited without ending: oops forgot end', + ' ---', + ' operator: fail', + ' at: process. ($TAPE/index.js:$LINE:$COL)', + ' stack: |-', + ' Error: test exited without ending: oops forgot end', + ' [... stack stripped ...]', + ' ...', + '', + '1..3', + '# tests 3', + '# pass 2', + '# fail 1', + '', + '' + ]); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + t.notEqual(code, 0); + }); }); diff --git a/test/exit/fail.js b/test/exit/fail.js index 930f51df..6c97ce1a 100644 --- a/test/exit/fail.js +++ b/test/exit/fail.js @@ -4,34 +4,34 @@ var test = require('../../'); var falafel = require('falafel'); test('array', function (t) { - t.plan(5); + t.plan(5); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); + } + ); }); diff --git a/test/exit/missing_end.js b/test/exit/missing_end.js index 7616fec1..0009b724 100644 --- a/test/exit/missing_end.js +++ b/test/exit/missing_end.js @@ -3,10 +3,10 @@ var test = require('../../'); test('first', function (t) { - t.ok(true); - t.end(); + t.ok(true); + t.end(); }); test('oops forgot end', function (t) { - t.ok(true); + t.ok(true); }); diff --git a/test/exit/ok.js b/test/exit/ok.js index 7649d940..05a6bd18 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -4,35 +4,35 @@ var falafel = require('falafel'); var test = require('../../'); test('array', function (t) { - t.comment('hi'); - t.plan(5); + t.comment('hi'); + t.plan(5); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); }); diff --git a/test/exit/second.js b/test/exit/second.js index 79e632e2..e7ca2cf5 100644 --- a/test/exit/second.js +++ b/test/exit/second.js @@ -3,11 +3,11 @@ var test = require('../../'); test('first', function (t) { - t.plan(1); - t.ok(true); + t.plan(1); + t.ok(true); }); test('second', function (t) { - t.plan(2); - t.ok(true); + t.plan(2); + t.ok(true); }); diff --git a/test/exit/todo.js b/test/exit/todo.js index bf0de1a8..b6863c59 100644 --- a/test/exit/todo.js +++ b/test/exit/todo.js @@ -3,6 +3,6 @@ var test = require('../../'); test('todo pass', { todo: true }, function (t) { - t.plan(1); - t.ok(true); + t.plan(1); + t.ok(true); }); diff --git a/test/exit/todo_fail.js b/test/exit/todo_fail.js index 06ec32f1..6e8dea93 100644 --- a/test/exit/todo_fail.js +++ b/test/exit/todo_fail.js @@ -3,6 +3,6 @@ var test = require('../../'); test('todo fail', { todo: true }, function (t) { - t.plan(1); - t.ok(false); + t.plan(1); + t.ok(false); }); diff --git a/test/exit/too_few.js b/test/exit/too_few.js index 33bc0855..cf88c1cc 100644 --- a/test/exit/too_few.js +++ b/test/exit/too_few.js @@ -4,34 +4,34 @@ var falafel = require('falafel'); var test = require('../../'); test('array', function (t) { - t.plan(6); + t.plan(6); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); }); diff --git a/test/exposed-harness.js b/test/exposed-harness.js index d153eda7..cb8b6019 100644 --- a/test/exposed-harness.js +++ b/test/exposed-harness.js @@ -5,10 +5,10 @@ var tap = require('tap'); tap.test('main harness object is exposed', function (assert) { - assert.equal(typeof tape.getHarness, 'function', 'tape.getHarness is a function'); + assert.equal(typeof tape.getHarness, 'function', 'tape.getHarness is a function'); - assert.equal(tape.getHarness()._results.pass, 0); + assert.equal(tape.getHarness()._results.pass, 0); - assert.end(); + assert.end(); }); diff --git a/test/fail.js b/test/fail.js index a2715dcf..af37eaea 100644 --- a/test/fail.js +++ b/test/fail.js @@ -8,73 +8,73 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness({ exit: false }); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# array', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'not ok 5 should be deeply equivalent', - ' ---', - ' operator: deepEqual', - ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', - ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: ($TEST/fail.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be deeply equivalent', - ' [... stack stripped ...]', - ' at $TEST/fail.js:$LINE:$COL', - ' at eval (eval at ($TEST/fail.js:$LINE:$COL))', - ' at eval (eval at ($TEST/fail.js:$LINE:$COL))', - ' at Test. ($TEST/fail.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..5', - '# tests 5', - '# pass 4', - '# fail 1', - '' - ]); - }; + var test = tape.createHarness({ exit: false }); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# array', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'not ok 5 should be deeply equivalent', + ' ---', + ' operator: deepEqual', + ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', + ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' at: ($TEST/fail.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be deeply equivalent', + ' [... stack stripped ...]', + ' at $TEST/fail.js:$LINE:$COL', + ' at eval (eval at ($TEST/fail.js:$LINE:$COL))', + ' at eval (eval at ($TEST/fail.js:$LINE:$COL))', + ' at Test. ($TEST/fail.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('array', function (t) { - t.plan(5); + test('array', function (t) { + t.plan(5); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); - } - ); - }); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4444]], [5, 6]]); + } + ); + }); }); diff --git a/test/has spaces.js b/test/has spaces.js index 990c9d88..8aa149b7 100644 --- a/test/has spaces.js +++ b/test/has spaces.js @@ -7,36 +7,36 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness({ exit: false }); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# fail', - 'not ok 1 this should fail', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/has spaces.js:$LINE:$COL)', - ' stack: |-', - ' Error: this should fail', - ' [... stack stripped ...]', - ' at Test. ($TEST/has spaces.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - }; + var test = tape.createHarness({ exit: false }); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# fail', + 'not ok 1 this should fail', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/has spaces.js:$LINE:$COL)', + ' stack: |-', + ' Error: this should fail', + ' [... stack stripped ...]', + ' at Test. ($TEST/has spaces.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('fail', function (t) { - t.fail('this should fail'); - t.end(); - }); + test('fail', function (t) { + t.fail('this should fail'); + t.end(); + }); }); diff --git a/test/ignore/fake_node_modules/stub1.js b/test/ignore/fake_node_modules/stub1.js index 6ef0b71c..d8d58e15 100644 --- a/test/ignore/fake_node_modules/stub1.js +++ b/test/ignore/fake_node_modules/stub1.js @@ -3,6 +3,6 @@ var tape = require('../../../'); tape.test(function (t) { - t.plan(1); - t.fail('Should not print'); + t.plan(1); + t.fail('Should not print'); }); diff --git a/test/ignore/fake_node_modules/stub2.js b/test/ignore/fake_node_modules/stub2.js index 27bebd87..213ee99e 100644 --- a/test/ignore/fake_node_modules/stub2.js +++ b/test/ignore/fake_node_modules/stub2.js @@ -3,6 +3,6 @@ var tape = require('../../../'); tape.test(function (t) { - t.fail('Should not print'); - t.end(); + t.fail('Should not print'); + t.end(); }); diff --git a/test/ignore/test.js b/test/ignore/test.js index f2d6f572..52777336 100644 --- a/test/ignore/test.js +++ b/test/ignore/test.js @@ -3,6 +3,6 @@ var tape = require('../../'); tape.test(function (t) { - t.plan(1); - t.ok('Okay'); + t.plan(1); + t.ok('Okay'); }); diff --git a/test/ignore/test/stub1.js b/test/ignore/test/stub1.js index e91244ee..0ea00c46 100644 --- a/test/ignore/test/stub1.js +++ b/test/ignore/test/stub1.js @@ -3,6 +3,6 @@ var tape = require('../../../'); tape.test(function (t) { - t.plan(1); - t.pass('test/stub1'); + t.plan(1); + t.pass('test/stub1'); }); diff --git a/test/ignore/test/stub2.js b/test/ignore/test/stub2.js index f4661b88..7f061890 100644 --- a/test/ignore/test/stub2.js +++ b/test/ignore/test/stub2.js @@ -3,6 +3,6 @@ var tape = require('../../../'); tape.test(function (t) { - t.pass('test/stub2'); - t.end(); + t.pass('test/stub2'); + t.end(); }); diff --git a/test/ignore/test/sub/sub.stub1.js b/test/ignore/test/sub/sub.stub1.js index 0f39cfee..96a23cde 100644 --- a/test/ignore/test/sub/sub.stub1.js +++ b/test/ignore/test/sub/sub.stub1.js @@ -3,6 +3,6 @@ var tape = require('../../../../'); tape.test(function (t) { - t.plan(1); - t.pass('test/sub/stub1'); + t.plan(1); + t.pass('test/sub/stub1'); }); diff --git a/test/ignore/test/sub/sub.stub2.js b/test/ignore/test/sub/sub.stub2.js index bec910d7..daa2c84e 100644 --- a/test/ignore/test/sub/sub.stub2.js +++ b/test/ignore/test/sub/sub.stub2.js @@ -3,6 +3,6 @@ var tape = require('../../../../'); tape.test(function (t) { - t.pass('test/sub/stub2'); - t.end(); + t.pass('test/sub/stub2'); + t.end(); }); diff --git a/test/ignore/test2.js b/test/ignore/test2.js index a2ceecc0..1364e64d 100644 --- a/test/ignore/test2.js +++ b/test/ignore/test2.js @@ -3,6 +3,6 @@ var tape = require('../../'); tape.test(function (t) { - t.pass('Should print'); - t.end(); + t.pass('Should print'); + t.end(); }); diff --git a/test/ignore_from_gitignore.js b/test/ignore_from_gitignore.js index 8260c2ec..3e46cdc5 100644 --- a/test/ignore_from_gitignore.js +++ b/test/ignore_from_gitignore.js @@ -10,113 +10,113 @@ var stripFullStack = require('./common').stripFullStack; var tapeBin = path.join(process.cwd(), 'bin/tape'); tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, function (tt) { - tt.plan(2); + tt.plan(2); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# (anonymous)', - 'ok 1 should be truthy', - '# (anonymous)', - 'ok 2 test/stub1', - '# (anonymous)', - 'ok 3 test/stub2', - '# (anonymous)', - 'ok 4 test/sub/stub1', - '# (anonymous)', - 'ok 5 test/sub/stub2', - '# (anonymous)', - 'ok 6 Should print', - '', - '1..6', - '# tests 6', - '# pass 6', - '', - '# ok', - '', - '' - ]); - }; + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# (anonymous)', + 'ok 1 should be truthy', + '# (anonymous)', + 'ok 2 test/stub1', + '# (anonymous)', + 'ok 3 test/stub2', + '# (anonymous)', + 'ok 4 test/sub/stub1', + '# (anonymous)', + 'ok 5 test/sub/stub2', + '# (anonymous)', + 'ok 6 Should print', + '', + '1..6', + '# tests 6', + '# pass 6', + '', + '# ok', + '', + '' + ]); + }; - var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') }); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - tt.equal(code, 0); // code 0 - }); + var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') }); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + tt.equal(code, 0); // code 0 + }); }); tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) { - tt.plan(2); + tt.plan(2); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# (anonymous)', - 'not ok 1 Should not print', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)', - ' stack: |-', - ' Error: Should not print', - ' [... stack stripped ...]', - ' at Test. ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# (anonymous)', - 'not ok 2 Should not print', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)', - ' stack: |-', - ' Error: Should not print', - ' [... stack stripped ...]', - ' at Test. ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# (anonymous)', - 'ok 3 should be truthy', - '# (anonymous)', - 'ok 4 test/stub1', - '# (anonymous)', - 'ok 5 test/stub2', - '# (anonymous)', - 'ok 6 test/sub/stub1', - '# (anonymous)', - 'ok 7 test/sub/stub2', - '# (anonymous)', - 'ok 8 Should print', - '', - '1..8', - '# tests 8', - '# pass 6', - '# fail 2', - '', - '' - ]); - }; + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# (anonymous)', + 'not ok 1 Should not print', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)', + ' stack: |-', + ' Error: Should not print', + ' [... stack stripped ...]', + ' at Test. ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# (anonymous)', + 'not ok 2 Should not print', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)', + ' stack: |-', + ' Error: Should not print', + ' [... stack stripped ...]', + ' at Test. ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# (anonymous)', + 'ok 3 should be truthy', + '# (anonymous)', + 'ok 4 test/stub1', + '# (anonymous)', + 'ok 5 test/stub2', + '# (anonymous)', + 'ok 6 test/sub/stub1', + '# (anonymous)', + 'ok 7 test/sub/stub2', + '# (anonymous)', + 'ok 8 Should print', + '', + '1..8', + '# tests 8', + '# pass 6', + '# fail 2', + '', + '' + ]); + }; - var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') }); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - tt.equal(code, 1); - }); + var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') }); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + tt.equal(code, 1); + }); }); tap.test('Should fail when ignore file does not exist', { skip: process.platform === 'win32' }, function (tt) { - tt.plan(3); + tt.plan(3); - var testStdout = function (rows) { - tt.same(rows.toString('utf8'), ''); - }; + var testStdout = function (rows) { + tt.same(rows.toString('utf8'), ''); + }; - var testStderr = function (rows) { - tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n'))); - }; + var testStderr = function (rows) { + tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n'))); + }; - var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') }); - ps.stdout.pipe(concat(testStdout)); - ps.stderr.pipe(concat(testStderr)); - ps.on('exit', function (code) { - tt.equal(code, 2); - }); + var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') }); + ps.stdout.pipe(concat(testStdout)); + ps.stderr.pipe(concat(testStderr)); + ps.on('exit', function (code) { + tt.equal(code, 2); + }); }); diff --git a/test/import.js b/test/import.js index f4072326..8688c149 100644 --- a/test/import.js +++ b/test/import.js @@ -7,189 +7,189 @@ var hasDynamicImport = require('has-dynamic-import'); var assign = require('object.assign'); tap.test('importing mjs files', function (t) { - hasDynamicImport().then(function (hasSupport) { - if (hasSupport) { - var tc = function (rows) { - t.same(rows.toString('utf8'), [ - 'TAP version 13', - '# mjs-a', - 'ok 1 test ran', - '# mjs-b', - 'ok 2 test ran after mjs-a', - '# mjs-c', - 'ok 3 test ran after mjs-b', - '# mjs-d', - 'ok 4 test ran after mjs-c', - '# mjs-e', - 'ok 5 test ran after mjs-d', - '# mjs-f', - 'ok 6 test ran after mjs-e', - '# mjs-g', - 'ok 7 test ran after mjs-f', - '# mjs-h', - 'ok 8 test ran after mjs-g', - '', - '1..8', - '# tests 8', - '# pass 8', - '', - '# ok' - ].join('\n') + '\n\n'); - }; + hasDynamicImport().then(function (hasSupport) { + if (hasSupport) { + var tc = function (rows) { + t.same(rows.toString('utf8'), [ + 'TAP version 13', + '# mjs-a', + 'ok 1 test ran', + '# mjs-b', + 'ok 2 test ran after mjs-a', + '# mjs-c', + 'ok 3 test ran after mjs-b', + '# mjs-d', + 'ok 4 test ran after mjs-c', + '# mjs-e', + 'ok 5 test ran after mjs-d', + '# mjs-f', + 'ok 6 test ran after mjs-e', + '# mjs-g', + 'ok 7 test ran after mjs-f', + '# mjs-h', + 'ok 8 test ran after mjs-g', + '', + '1..8', + '# tests 8', + '# pass 8', + '', + '# ok' + ].join('\n') + '\n\n'); + }; - var ps = tape('import/mjs-*.mjs'); - ps.stdout.pipe(concat(tc)); - ps.stderr.pipe(process.stderr); - ps.on('exit', function (code) { - t.equal(code, 0); - t.end(); - }); - } else { - t.pass('does not support dynamic import'); - t.end(); - } - }); + var ps = tape('import/mjs-*.mjs'); + ps.stdout.pipe(concat(tc)); + ps.stderr.pipe(process.stderr); + ps.on('exit', function (code) { + t.equal(code, 0); + t.end(); + }); + } else { + t.pass('does not support dynamic import'); + t.end(); + } + }); }); tap.test('importing type: "module" files', function (t) { - hasDynamicImport().then(function (hasSupport) { - if (hasSupport) { - var tc = function (rows) { - t.same(rows.toString('utf8'), [ - 'TAP version 13', - '# package-type-a', - 'ok 1 test ran', - '# package-type-b', - 'ok 2 test ran after package-type-a', - '# package-type-c', - 'ok 3 test ran after package-type-b', - '', - '1..3', - '# tests 3', - '# pass 3', - '', - '# ok' - ].join('\n') + '\n\n'); - }; + hasDynamicImport().then(function (hasSupport) { + if (hasSupport) { + var tc = function (rows) { + t.same(rows.toString('utf8'), [ + 'TAP version 13', + '# package-type-a', + 'ok 1 test ran', + '# package-type-b', + 'ok 2 test ran after package-type-a', + '# package-type-c', + 'ok 3 test ran after package-type-b', + '', + '1..3', + '# tests 3', + '# pass 3', + '', + '# ok' + ].join('\n') + '\n\n'); + }; - var ps = tape('import/package_type/*.js'); - ps.stdout.pipe(concat(tc)); - ps.stderr.pipe(process.stderr); - ps.on('exit', function (code) { - t.equal(code, 0); - t.end(); - }); - } else { - t.pass('does not support dynamic import'); - t.end(); - } - }); + var ps = tape('import/package_type/*.js'); + ps.stdout.pipe(concat(tc)); + ps.stderr.pipe(process.stderr); + ps.on('exit', function (code) { + t.equal(code, 0); + t.end(); + }); + } else { + t.pass('does not support dynamic import'); + t.end(); + } + }); }); tap.test('errors importing test files', function (t) { - hasDynamicImport().then(function (hasSupport) { - var createTest = function (options) { - var message = options.error + ' in `' + options.mode + '` mode`'; - var ps = tape(options.files, { env: { NODE_OPTIONS: '--unhandled-rejections=' + options.mode } }); - ps.stderr.pipe(concat(options.unhandledRejection(message))); - ps.on('exit', function (code/* , sig */) { - t.equal(code, options.exitCode, message + ' has exit code ' + options.exitCode); - }); - }; + hasDynamicImport().then(function (hasSupport) { + var createTest = function (options) { + var message = options.error + ' in `' + options.mode + '` mode`'; + var ps = tape(options.files, { env: { NODE_OPTIONS: '--unhandled-rejections=' + options.mode } }); + ps.stderr.pipe(concat(options.unhandledRejection(message))); + ps.on('exit', function (code/* , sig */) { + t.equal(code, options.exitCode, message + ' has exit code ' + options.exitCode); + }); + }; - var warning = function (message) { - return function (rows) { - t.match(rows.toString('utf8'), 'UnhandledPromiseRejectionWarning', 'should have unhandled rejection warning: ' + message); - }; - }; + var warning = function (message) { + return function (rows) { + t.match(rows.toString('utf8'), 'UnhandledPromiseRejectionWarning', 'should have unhandled rejection warning: ' + message); + }; + }; - var noWarning = function (message) { - return function (rows) { - t.notMatch(rows.toString('utf8'), 'UnhandledPromiseRejectionWarning', 'should not have unhandled rejection warning: ' + message); - }; - }; + var noWarning = function (message) { + return function (rows) { + t.notMatch(rows.toString('utf8'), 'UnhandledPromiseRejectionWarning', 'should not have unhandled rejection warning: ' + message); + }; + }; - if (hasSupport) { - var tests = [{ - files: 'import/syntax-error.mjs import/mjs-a.mjs import/mjs-b.mjs', - error: 'syntax errors in first imported esm file', - mode: 'warn', - exitCode: 0, - unhandledRejection: warning - }, { - files: 'import/throws.mjs import/mjs-a.mjs import/mjs-b.mjs', - error: 'thrown errors in first imported esm file', - mode: 'warn', - exitCode: 0, - unhandledRejection: warning - }, { - files: 'import/mjs-a.mjs import/syntax-error.mjs', - error: 'syntax error in esm file', - mode: 'warn', - exitCode: 1, - unhandledRejection: warning - }, { - files: 'import/syntax-error.mjs', - error: 'syntax error in esm file', - mode: 'strict', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/throws.mjs', - error: 'thrown error in esm file', - mode: 'strict', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/syntax-error.cjs', - error: 'syntax error in cjs file', - mode: 'warn', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/throws.cjs', - error: 'thrown error in cjs file', - mode: 'warn', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/syntax-error.cjs', - error: 'syntax error in cjs file', - mode: 'strict', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/throws.cjs', - error: 'thrown error in cjs file', - mode: 'strict', - exitCode: 1, - unhandledRejection: noWarning - }, { - files: 'import/mjs-a.mjs import/syntax-error.cjs', - error: 'syntax error in cjs file in loading promise', - mode: 'warn', - exitCode: 1, - unhandledRejection: warning - }, { - files: 'import/mjs-a.mjs import/syntax-error.cjs', - error: 'syntax error in cjs file in loading promise', - mode: 'strict', - exitCode: 1, - unhandledRejection: noWarning - }]; + if (hasSupport) { + var tests = [{ + files: 'import/syntax-error.mjs import/mjs-a.mjs import/mjs-b.mjs', + error: 'syntax errors in first imported esm file', + mode: 'warn', + exitCode: 0, + unhandledRejection: warning + }, { + files: 'import/throws.mjs import/mjs-a.mjs import/mjs-b.mjs', + error: 'thrown errors in first imported esm file', + mode: 'warn', + exitCode: 0, + unhandledRejection: warning + }, { + files: 'import/mjs-a.mjs import/syntax-error.mjs', + error: 'syntax error in esm file', + mode: 'warn', + exitCode: 1, + unhandledRejection: warning + }, { + files: 'import/syntax-error.mjs', + error: 'syntax error in esm file', + mode: 'strict', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/throws.mjs', + error: 'thrown error in esm file', + mode: 'strict', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/syntax-error.cjs', + error: 'syntax error in cjs file', + mode: 'warn', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/throws.cjs', + error: 'thrown error in cjs file', + mode: 'warn', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/syntax-error.cjs', + error: 'syntax error in cjs file', + mode: 'strict', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/throws.cjs', + error: 'thrown error in cjs file', + mode: 'strict', + exitCode: 1, + unhandledRejection: noWarning + }, { + files: 'import/mjs-a.mjs import/syntax-error.cjs', + error: 'syntax error in cjs file in loading promise', + mode: 'warn', + exitCode: 1, + unhandledRejection: warning + }, { + files: 'import/mjs-a.mjs import/syntax-error.cjs', + error: 'syntax error in cjs file in loading promise', + mode: 'strict', + exitCode: 1, + unhandledRejection: noWarning + }]; - t.plan(tests.length * 2); + t.plan(tests.length * 2); - tests.map(createTest); - } else { - t.pass('does not support dynamic import'); - t.end(); - } - }); + tests.map(createTest); + } else { + t.pass('does not support dynamic import'); + t.end(); + } + }); }); function tape(args, options) { - var bin = __dirname + '/../bin/tape'; + var bin = __dirname + '/../bin/tape'; - return spawn('node', [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options)); + return spawn('node', [bin].concat(args.split(' ')), assign({ cwd: __dirname }, options)); } diff --git a/test/import/mjs-a.mjs b/test/import/mjs-a.mjs index 39244e0b..f0319055 100644 --- a/test/import/mjs-a.mjs +++ b/test/import/mjs-a.mjs @@ -1,8 +1,8 @@ import tape from '../../index.js'; tape.test('mjs-a', function (t) { - t.pass('test ran'); - t.end(); - global.mjs_a = true; + t.pass('test ran'); + t.end(); + global.mjs_a = true; }); diff --git a/test/import/mjs-b.mjs b/test/import/mjs-b.mjs index 69317cd6..88b207b8 100644 --- a/test/import/mjs-b.mjs +++ b/test/import/mjs-b.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-b', function (t) { - t.ok(global.mjs_a, 'test ran after mjs-a'); - t.end(); - global.mjs_b = true; + t.ok(global.mjs_a, 'test ran after mjs-a'); + t.end(); + global.mjs_b = true; }); diff --git a/test/import/mjs-c.mjs b/test/import/mjs-c.mjs index aeaffcd7..da57d4e6 100644 --- a/test/import/mjs-c.mjs +++ b/test/import/mjs-c.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-c', function (t) { - t.ok(global.mjs_b, 'test ran after mjs-b'); - t.end(); - global.mjs_c = true; + t.ok(global.mjs_b, 'test ran after mjs-b'); + t.end(); + global.mjs_c = true; }); diff --git a/test/import/mjs-d.mjs b/test/import/mjs-d.mjs index d6b13422..7cf54cb8 100644 --- a/test/import/mjs-d.mjs +++ b/test/import/mjs-d.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-d', function (t) { - t.ok(global.mjs_c, 'test ran after mjs-c'); - t.end(); - global.mjs_d = true; + t.ok(global.mjs_c, 'test ran after mjs-c'); + t.end(); + global.mjs_d = true; }); diff --git a/test/import/mjs-e.mjs b/test/import/mjs-e.mjs index f089e3d2..29a7c63e 100644 --- a/test/import/mjs-e.mjs +++ b/test/import/mjs-e.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-e', function (t) { - t.ok(global.mjs_d, 'test ran after mjs-d'); - t.end(); - global.mjs_e = true; + t.ok(global.mjs_d, 'test ran after mjs-d'); + t.end(); + global.mjs_e = true; }); diff --git a/test/import/mjs-f.mjs b/test/import/mjs-f.mjs index d1e68539..0e428bee 100644 --- a/test/import/mjs-f.mjs +++ b/test/import/mjs-f.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-f', function (t) { - t.ok(global.mjs_e, 'test ran after mjs-e'); - t.end(); - global.mjs_f = true; + t.ok(global.mjs_e, 'test ran after mjs-e'); + t.end(); + global.mjs_f = true; }); diff --git a/test/import/mjs-g.mjs b/test/import/mjs-g.mjs index fb7728bf..1a7a0c16 100644 --- a/test/import/mjs-g.mjs +++ b/test/import/mjs-g.mjs @@ -1,7 +1,7 @@ import tape from '../../index.js'; tape.test('mjs-g', function (t) { - t.ok(global.mjs_f, 'test ran after mjs-f'); - t.end(); - global.mjs_g = true; + t.ok(global.mjs_f, 'test ran after mjs-f'); + t.end(); + global.mjs_g = true; }); diff --git a/test/import/mjs-h.mjs b/test/import/mjs-h.mjs index e4af5d81..67046721 100644 --- a/test/import/mjs-h.mjs +++ b/test/import/mjs-h.mjs @@ -1,6 +1,6 @@ import tape from '../../index.js'; tape.test('mjs-h', function (t) { - t.ok(global.mjs_g, 'test ran after mjs-g'); - t.end(); + t.ok(global.mjs_g, 'test ran after mjs-g'); + t.end(); }); diff --git a/test/import/package_type/package-a.js b/test/import/package_type/package-a.js index af4b097a..0471914c 100644 --- a/test/import/package_type/package-a.js +++ b/test/import/package_type/package-a.js @@ -1,8 +1,8 @@ import tape from '../../../index.js'; tape.test('package-type-a', function (t) { - t.pass('test ran'); - t.end(); - global.package_type_a = true; + t.pass('test ran'); + t.end(); + global.package_type_a = true; }); diff --git a/test/import/package_type/package-b.js b/test/import/package_type/package-b.js index 74b8d052..10b6dfcf 100644 --- a/test/import/package_type/package-b.js +++ b/test/import/package_type/package-b.js @@ -1,7 +1,7 @@ import tape from '../../../index.js'; tape.test('package-type-b', function (t) { - t.ok(global.package_type_a, 'test ran after package-type-a'); - t.end(); - global.package_type_b = true; + t.ok(global.package_type_a, 'test ran after package-type-a'); + t.end(); + global.package_type_b = true; }); diff --git a/test/import/package_type/package-c.js b/test/import/package_type/package-c.js index 8fa8fac3..bb8807b3 100644 --- a/test/import/package_type/package-c.js +++ b/test/import/package_type/package-c.js @@ -1,6 +1,6 @@ import tape from '../../../index.js'; tape.test('package-type-c', function (t) { - t.ok(global.package_type_b, 'test ran after package-type-b'); - t.end(); + t.ok(global.package_type_b, 'test ran after package-type-b'); + t.end(); }); diff --git a/test/many.js b/test/many.js index 6e5368a3..99b8ff06 100644 --- a/test/many.js +++ b/test/many.js @@ -3,8 +3,8 @@ var test = require('../'); test('many tests', function (t) { - t.plan(100); - for (var i = 0; i < 100; i++) { - setTimeout(function () { t.pass(); }, Math.random() * 50); - } + t.plan(100); + for (var i = 0; i < 100; i++) { + setTimeout(function () { t.pass(); }, Math.random() * 50); + } }); diff --git a/test/match.js b/test/match.js index c7c6a097..5fd1879d 100644 --- a/test/match.js +++ b/test/match.js @@ -7,252 +7,252 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('match', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness({ exit: false }); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# match', - 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', - ' ---', - ' operator: match', - ' expected: \'[object RegExp]\'', - ' actual: \'[object String]\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 2 regex arg must not be a string', - ' ---', - ' operator: match', - ' expected: \'[object RegExp]\'', - ' actual: \'[object String]\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: regex arg must not be a string', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })', - ' ---', - ' operator: match', - ' expected: \'string\'', - ' actual: \'object\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 4 string arg must not be an object', - ' ---', - ' operator: match', - ' expected: \'string\'', - ' actual: \'object\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: string arg must not be an object', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'', - ' ---', - ' operator: match', - ' expected: /abc/', - ' actual: \'string\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The input did not match the regular expression /abc/. Input: \'string\'', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 6 "string" does not match /abc/', - ' ---', - ' operator: match', - ' expected: /abc/', - ' actual: \'string\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: "string" does not match /abc/', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'', - 'ok 8 "I will pass" matches /pass$/', - '', - '1..8', - '# tests 8', - '# pass 2', - '# fail 6', - '' - ]); - }; + var test = tape.createHarness({ exit: false }); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# match', + 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', + ' ---', + ' operator: match', + ' expected: \'[object RegExp]\'', + ' actual: \'[object String]\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 regex arg must not be a string', + ' ---', + ' operator: match', + ' expected: \'[object RegExp]\'', + ' actual: \'[object String]\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: regex arg must not be a string', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })', + ' ---', + ' operator: match', + ' expected: \'string\'', + ' actual: \'object\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 4 string arg must not be an object', + ' ---', + ' operator: match', + ' expected: \'string\'', + ' actual: \'object\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: string arg must not be an object', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'', + ' ---', + ' operator: match', + ' expected: /abc/', + ' actual: \'string\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The input did not match the regular expression /abc/. Input: \'string\'', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 6 "string" does not match /abc/', + ' ---', + ' operator: match', + ' expected: /abc/', + ' actual: \'string\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: "string" does not match /abc/', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'', + 'ok 8 "I will pass" matches /pass$/', + '', + '1..8', + '# tests 8', + '# pass 2', + '# fail 6', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('match', function (t) { - t.plan(8); + test('match', function (t) { + t.plan(8); - t.match(/abc/, 'string'); - t.match(/abc/, 'string', 'regex arg must not be a string'); + t.match(/abc/, 'string'); + t.match(/abc/, 'string', 'regex arg must not be a string'); - t.match({ abc: 123 }, /abc/); - t.match({ abc: 123 }, /abc/, 'string arg must not be an object'); + t.match({ abc: 123 }, /abc/); + t.match({ abc: 123 }, /abc/, 'string arg must not be an object'); - t.match('string', /abc/); - t.match('string', /abc/, '"string" does not match /abc/'); + t.match('string', /abc/); + t.match('string', /abc/, '"string" does not match /abc/'); - t.match('I will pass', /pass$/); - t.match('I will pass', /pass$/, '"I will pass" matches /pass$/'); + t.match('I will pass', /pass$/); + t.match('I will pass', /pass$/, '"I will pass" matches /pass$/'); - t.end(); - }); + t.end(); + }); }); tap.test('doesNotMatch', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness({ exit: false }); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# doesNotMatch', - 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', - ' ---', - ' operator: doesNotMatch', - ' expected: \'[object RegExp]\'', - ' actual: \'[object String]\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 2 regex arg must not be a string', - ' ---', - ' operator: doesNotMatch', - ' expected: \'[object RegExp]\'', - ' actual: \'[object String]\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: regex arg must not be a string', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })', - ' ---', - ' operator: doesNotMatch', - ' expected: \'string\'', - ' actual: \'object\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 4 string arg must not be an object', - ' ---', - ' operator: doesNotMatch', - ' expected: \'string\'', - ' actual: \'object\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: string arg must not be an object', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'', - ' ---', - ' operator: doesNotMatch', - ' expected: /string/', - ' actual: \'string\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The input was expected to not match the regular expression /string/. Input: \'string\'', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 6 "string" should not match /string/', - ' ---', - ' operator: doesNotMatch', - ' expected: /string/', - ' actual: \'string\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: "string" should not match /string/', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'', - ' ---', - ' operator: doesNotMatch', - ' expected: /pass$/', - ' actual: \'I will pass\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 8 "I will pass" should not match /pass$/', - ' ---', - ' operator: doesNotMatch', - ' expected: /pass$/', - ' actual: \'I will pass\'', - ' at: Test. ($TEST/match.js:$LINE:$COL)', - ' stack: |-', - ' Error: "I will pass" should not match /pass$/', - ' [... stack stripped ...]', - ' at Test. ($TEST/match.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'', - 'ok 10 "I will fail" does not match /pass$/', - '', - '1..10', - '# tests 10', - '# pass 2', - '# fail 8', - '' - ]); - }; + var test = tape.createHarness({ exit: false }); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# doesNotMatch', + 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', + ' ---', + ' operator: doesNotMatch', + ' expected: \'[object RegExp]\'', + ' actual: \'[object String]\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 regex arg must not be a string', + ' ---', + ' operator: doesNotMatch', + ' expected: \'[object RegExp]\'', + ' actual: \'[object String]\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: regex arg must not be a string', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })', + ' ---', + ' operator: doesNotMatch', + ' expected: \'string\'', + ' actual: \'object\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 4 string arg must not be an object', + ' ---', + ' operator: doesNotMatch', + ' expected: \'string\'', + ' actual: \'object\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: string arg must not be an object', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'', + ' ---', + ' operator: doesNotMatch', + ' expected: /string/', + ' actual: \'string\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The input was expected to not match the regular expression /string/. Input: \'string\'', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 6 "string" should not match /string/', + ' ---', + ' operator: doesNotMatch', + ' expected: /string/', + ' actual: \'string\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: "string" should not match /string/', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'', + ' ---', + ' operator: doesNotMatch', + ' expected: /pass$/', + ' actual: \'I will pass\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 "I will pass" should not match /pass$/', + ' ---', + ' operator: doesNotMatch', + ' expected: /pass$/', + ' actual: \'I will pass\'', + ' at: Test. ($TEST/match.js:$LINE:$COL)', + ' stack: |-', + ' Error: "I will pass" should not match /pass$/', + ' [... stack stripped ...]', + ' at Test. ($TEST/match.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'', + 'ok 10 "I will fail" does not match /pass$/', + '', + '1..10', + '# tests 10', + '# pass 2', + '# fail 8', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('doesNotMatch', function (t) { - t.plan(10); + test('doesNotMatch', function (t) { + t.plan(10); - t.doesNotMatch(/abc/, 'string'); - t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string'); + t.doesNotMatch(/abc/, 'string'); + t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string'); - t.doesNotMatch({ abc: 123 }, /abc/); - t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object'); + t.doesNotMatch({ abc: 123 }, /abc/); + t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object'); - t.doesNotMatch('string', /string/); - t.doesNotMatch('string', /string/, '"string" should not match /string/'); + t.doesNotMatch('string', /string/); + t.doesNotMatch('string', /string/, '"string" should not match /string/'); - t.doesNotMatch('I will pass', /pass$/); - t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/'); + t.doesNotMatch('I will pass', /pass$/); + t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/'); - t.doesNotMatch('I will fail', /pass$/); - t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/'); + t.doesNotMatch('I will fail', /pass$/); + t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/'); - t.end(); - }); + t.end(); + }); }); diff --git a/test/max_listeners.js b/test/max_listeners.js index 286a2b15..34335d0c 100644 --- a/test/max_listeners.js +++ b/test/max_listeners.js @@ -8,5 +8,5 @@ var ps = spawn(process.execPath, [path.join(__dirname, 'max_listeners', 'source. ps.stdout.pipe(process.stdout, { end: false }); ps.stderr.on('data', function (buf) { - console.log('not ok ' + buf); + console.log('not ok ' + buf); }); diff --git a/test/max_listeners/source.js b/test/max_listeners/source.js index 137f8a1c..5443182d 100644 --- a/test/max_listeners/source.js +++ b/test/max_listeners/source.js @@ -3,8 +3,8 @@ var test = require('../../'); for (var i = 0; i < 11; i++) { - test(function (t) { - t.ok(true, 'true is truthy'); - t.end(); - }); + test(function (t) { + t.ok(true, 'true is truthy'); + t.end(); + }); } diff --git a/test/messages/defaults.js b/test/messages/defaults.js index e9672147..6e01fe25 100644 --- a/test/messages/defaults.js +++ b/test/messages/defaults.js @@ -3,23 +3,23 @@ var test = require('../../'); test('default messages', function (t) { - t.plan(12); + t.plan(12); - t.ok(true); - t.notOk(false); + t.ok(true); + t.notOk(false); - t.equal(true, true); - t.notEqual(true, false); + t.equal(true, true); + t.notEqual(true, false); - t.looseEqual(true, true); - t.notLooseEqual(true, false); + t.looseEqual(true, true); + t.notLooseEqual(true, false); - t.strictEqual(true, true); - t.notStrictEqual(true, false); + t.strictEqual(true, true); + t.notStrictEqual(true, false); - t.deepEqual(true, true); - t.notDeepEqual(true, true); + t.deepEqual(true, true); + t.notDeepEqual(true, true); - t.deepLooseEqual(true, true); - t.notDeepLooseEqual(true, false); + t.deepLooseEqual(true, true); + t.notDeepLooseEqual(true, false); }); diff --git a/test/nested-async-plan-noend.js b/test/nested-async-plan-noend.js index a086d8ed..a0339d38 100644 --- a/test/nested-async-plan-noend.js +++ b/test/nested-async-plan-noend.js @@ -3,36 +3,36 @@ var test = require('../'); test('Harness async test support', function (t) { - t.plan(3); + t.plan(3); - t.ok(true, 'sync child A'); + t.ok(true, 'sync child A'); - t.test('sync child B', function (tt) { - tt.plan(2); + t.test('sync child B', function (tt) { + tt.plan(2); - setTimeout(function () { - tt.test('async grandchild A', function (ttt) { - ttt.plan(1); - ttt.ok(true); - }); - }, 50); + setTimeout(function () { + tt.test('async grandchild A', function (ttt) { + ttt.plan(1); + ttt.ok(true); + }); + }, 50); - setTimeout(function () { - tt.test('async grandchild B', function (ttt) { - ttt.plan(1); - ttt.ok(true); - }); - }, 100); - }); + setTimeout(function () { + tt.test('async grandchild B', function (ttt) { + ttt.plan(1); + ttt.ok(true); + }); + }, 100); + }); - setTimeout(function () { - t.test('async child', function (tt) { - tt.plan(2); - tt.ok(true, 'sync grandchild in async child A'); - tt.test('sync grandchild in async child B', function (ttt) { - ttt.plan(1); - ttt.ok(true); - }); - }); - }, 200); + setTimeout(function () { + t.test('async child', function (tt) { + tt.plan(2); + tt.ok(true, 'sync grandchild in async child A'); + tt.test('sync grandchild in async child B', function (ttt) { + ttt.plan(1); + ttt.ok(true); + }); + }); + }, 200); }); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 66b805d9..7512536c 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -5,42 +5,42 @@ var tap = require('tap'); var concat = require('concat-stream'); tap.test('nested sync test without plan or end', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - var tc = function (rows) { - tt.same(rows.toString('utf8').split('\n'), [ - 'TAP version 13', - '# nested without plan or end', - '# first', - 'ok 1 should be truthy', - '# second', - 'ok 2 should be truthy', - '', - '1..2', - '# tests 2', - '# pass 2', - '', - '# ok', - '' - ]); - }; + var test = tape.createHarness(); + var tc = function (rows) { + tt.same(rows.toString('utf8').split('\n'), [ + 'TAP version 13', + '# nested without plan or end', + '# first', + 'ok 1 should be truthy', + '# second', + 'ok 2 should be truthy', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('nested without plan or end', function (t) { - t.test('first', function (q) { - setTimeout(function first() { - q.ok(true); - q.end(); - }, 10); - }); - t.test('second', function (q) { - setTimeout(function second() { - q.ok(true); - q.end(); - }, 10); - }); - }); + test('nested without plan or end', function (t) { + t.test('first', function (q) { + setTimeout(function first() { + q.ok(true); + q.end(); + }, 10); + }); + t.test('second', function (q) { + setTimeout(function second() { + q.ok(true); + q.end(); + }, 10); + }); + }); }); diff --git a/test/nested.js b/test/nested.js index 6348a250..0a536a2f 100644 --- a/test/nested.js +++ b/test/nested.js @@ -6,81 +6,81 @@ var tap = require('tap'); var concat = require('concat-stream'); tap.test('array test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - var tc = function (rows) { - tt.same(rows.toString('utf8').split('\n'), [ - 'TAP version 13', - '# nested array test', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'ok 5 should be deeply equivalent', - '# inside test', - 'ok 6 should be truthy', - 'ok 7 should be truthy', - '# another', - 'ok 8 should be truthy', - '', - '1..8', - '# tests 8', - '# pass 8', - '', - '# ok', - '' - ]); - }; + var test = tape.createHarness(); + var tc = function (rows) { + tt.same(rows.toString('utf8').split('\n'), [ + 'TAP version 13', + '# nested array test', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'ok 5 should be deeply equivalent', + '# inside test', + 'ok 6 should be truthy', + 'ok 7 should be truthy', + '# another', + 'ok 8 should be truthy', + '', + '1..8', + '# tests 8', + '# pass 8', + '', + '# ok', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('nested array test', function (t) { - t.plan(6); + test('nested array test', function (t) { + t.plan(6); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - t.test('inside test', function (q) { - q.plan(2); - q.ok(true); + t.test('inside test', function (q) { + q.plan(2); + q.ok(true); - setTimeout(function () { - q.ok(true); - }, 100); - }); + setTimeout(function () { + q.ok(true); + }, 100); + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); - }); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); + }); - test('another', function (t) { - t.plan(1); - setTimeout(function () { - t.ok(true); - }, 50); - }); + test('another', function (t) { + t.plan(1); + setTimeout(function () { + t.ok(true); + }, 50); + }); }); diff --git a/test/nested2.js b/test/nested2.js index f167df61..011467ec 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -3,18 +3,18 @@ var test = require('../'); test(function (t) { - var i = 0; - t.test('setup', function (st) { - process.nextTick(function () { - st.equal(i, 0, 'called once'); - i++; - st.end(); - }); - }); + var i = 0; + t.test('setup', function (st) { + process.nextTick(function () { + st.equal(i, 0, 'called once'); + i++; + st.end(); + }); + }); - t.test('teardown', function (st) { - st.end(); - }); + t.test('teardown', function (st) { + st.end(); + }); - t.end(); + t.end(); }); diff --git a/test/no_callback.js b/test/no_callback.js index 47a478dc..ced2fabb 100644 --- a/test/no_callback.js +++ b/test/no_callback.js @@ -7,43 +7,43 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('no callback', function (tt) { - tt.plan(1); - - var test = tape.createHarness(); - var tc = function (rows) { - var body = stripFullStack(rows.toString('utf8')); - - tt.same(body, [ - 'TAP version 13', - '# group', - '# No callback.', - 'not ok 1 # TODO No callback.', - ' ---', - ' operator: fail', - ' stack: |-', - ' Error: # TODO No callback.', - ' [... stack stripped ...]', - ' ...', - '# SKIP No callback, skipped.', - '# TODO No callback, todo.', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - }; - - test.createStream().pipe(concat(tc)); - - test('group', function (t) { - t.plan(3); - - t.test('No callback.'); - - t.test('No callback, skipped.', { skip: true }); - - t.test('No callback, todo.', { todo: true }); - }); + tt.plan(1); + + var test = tape.createHarness(); + var tc = function (rows) { + var body = stripFullStack(rows.toString('utf8')); + + tt.same(body, [ + 'TAP version 13', + '# group', + '# No callback.', + 'not ok 1 # TODO No callback.', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: # TODO No callback.', + ' [... stack stripped ...]', + ' ...', + '# SKIP No callback, skipped.', + '# TODO No callback, todo.', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + }; + + test.createStream().pipe(concat(tc)); + + test('group', function (t) { + t.plan(3); + + t.test('No callback.'); + + t.test('No callback, skipped.', { skip: true }); + + t.test('No callback, todo.', { todo: true }); + }); }); diff --git a/test/no_only.js b/test/no_only.js index d0f126ba..4e755c98 100644 --- a/test/no_only.js +++ b/test/no_only.js @@ -12,99 +12,99 @@ var expectedExitCodeFailure = (/^0\.10\.\d+$/).test(process.versions.node); var expectedStackTraceBug = (/^3\.[012]\.\d+$/).test(process.versions.node); // https://github.com/nodejs/node/issues/2581 tap.test( - 'Should throw error when --no-only is passed via cli and there is a .only test', - { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, - function (tt) { - tt.plan(3); + 'Should throw error when --no-only is passed via cli and there is a .only test', + { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, + function (tt) { + tt.plan(3); - exec(tapeBin + ' --no-only "**/*.js"', { - cwd: path.join(__dirname, 'no_only') - }, function (err, stdout, stderr) { - tt.same(stdout.toString('utf8'), ''); - tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); - tt.equal(err.code, 1); - }); - } + exec(tapeBin + ' --no-only "**/*.js"', { + cwd: path.join(__dirname, 'no_only') + }, function (err, stdout, stderr) { + tt.same(stdout.toString('utf8'), ''); + tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); + tt.equal(err.code, 1); + }); + } ); tap.test( - 'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test', - { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, - function (tt) { - tt.plan(3); + 'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test', + { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, + function (tt) { + tt.plan(3); - exec(tapeBin + ' "**/*.js"', { - cwd: path.join(__dirname, 'no_only'), - env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' } - }, function (err, stdout, stderr) { - tt.same(stdout.toString('utf8'), ''); - tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); - tt.equal(err.code, 1); - }); - } + exec(tapeBin + ' "**/*.js"', { + cwd: path.join(__dirname, 'no_only'), + env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' } + }, function (err, stdout, stderr) { + tt.same(stdout.toString('utf8'), ''); + tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); + tt.equal(err.code, 1); + }); + } ); tap.test( - 'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli', - { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, - function (tt) { - tt.plan(3); + 'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli', + { todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false }, + function (tt) { + tt.plan(3); - exec(tapeBin + ' --no-only "**/*.js"', { - cwd: path.join(__dirname, 'no_only'), - env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' } - }, function (err, stdout, stderr) { - tt.same(stdout.toString('utf8'), ''); - tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); - tt.equal(err.code, 1); - }); - } + exec(tapeBin + ' --no-only "**/*.js"', { + cwd: path.join(__dirname, 'no_only'), + env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' } + }, function (err, stdout, stderr) { + tt.same(stdout.toString('utf8'), ''); + tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/); + tt.equal(err.code, 1); + }); + } ); tap.test('Should run successfully if there is no only test', function (tt) { - tt.plan(3); + tt.plan(3); - exec(tapeBin + ' --no-only "**/test-a.js"', { - cwd: path.join(__dirname, 'no_only') - }, function (err, stdout, stderr) { - tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/); - tt.same(stripFullStack(stdout.toString('utf8')), [ - 'TAP version 13', - '# should pass', - 'ok 1 should be truthy', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '', - '' - ]); - tt.equal(err, null); // code 0 - }); + exec(tapeBin + ' --no-only "**/test-a.js"', { + cwd: path.join(__dirname, 'no_only') + }, function (err, stdout, stderr) { + tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/); + tt.same(stripFullStack(stdout.toString('utf8')), [ + 'TAP version 13', + '# should pass', + 'ok 1 should be truthy', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '', + '' + ]); + tt.equal(err, null); // code 0 + }); }); tap.test('Should run successfully if there is an only test and no --no-only flag', function (tt) { - tt.plan(3); + tt.plan(3); - exec(tapeBin + ' "**/test-b.js"', { - cwd: path.join(__dirname, 'no_only') - }, function (err, stdout, stderr) { - tt.same(stripFullStack(stdout.toString('utf8')), [ - 'TAP version 13', - '# should pass again', - 'ok 1 should be truthy', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '', - '' - ]); - tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/); - tt.equal(err, null); // code 0 - }); + exec(tapeBin + ' "**/test-b.js"', { + cwd: path.join(__dirname, 'no_only') + }, function (err, stdout, stderr) { + tt.same(stripFullStack(stdout.toString('utf8')), [ + 'TAP version 13', + '# should pass again', + 'ok 1 should be truthy', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '', + '' + ]); + tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/); + tt.equal(err, null); // code 0 + }); }); diff --git a/test/no_only/test-a.js b/test/no_only/test-a.js index 41107d38..db181572 100644 --- a/test/no_only/test-a.js +++ b/test/no_only/test-a.js @@ -3,6 +3,6 @@ var tape = require('../../'); tape.test('should pass', function (t) { - t.plan(1); - t.ok(1); + t.plan(1); + t.ok(1); }); diff --git a/test/no_only/test-b.js b/test/no_only/test-b.js index c6f6eb6e..d2aa5801 100644 --- a/test/no_only/test-b.js +++ b/test/no_only/test-b.js @@ -3,12 +3,12 @@ var tape = require('../../'); tape.test('should pass', function (t) { - t.plan(1); - t.ok(1); + t.plan(1); + t.ok(1); }); tape.test.only('should pass again', function (t) { - t.plan(1); - t.ok(1); + t.plan(1); + t.ok(1); }); diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js index d02ab0ef..1d22e21f 100644 --- a/test/not-deep-equal-failure.js +++ b/test/not-deep-equal-failure.js @@ -10,187 +10,187 @@ var getDiag = common.getDiag; var stripFullStack = common.stripFullStack; tap.test('deep equal failure', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# not deep equal', - 'not ok 1 should not be deeply equivalent', - ' ---', - ' operator: notDeepEqual', - ' expected: |-', - ' { b: 2 }', - ' actual: |-', - ' { b: 2 }', - ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should not be deeply equivalent', - ' [... stack stripped ...]', - ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'notDeepEqual', - expected: '{ b: 2 }', - actual: '{ b: 2 }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should not be deeply equivalent', - diag: { - operator: 'notDeepEqual', - expected: '{ b: 2 }', - actual: '{ b: 2 }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('not deep equal', function (t) { - t.plan(1); - t.notDeepEqual({ b: 2 }, { b: 2 }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be deeply equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { b: 2 }', + ' actual: |-', + ' { b: 2 }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be deeply equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'notDeepEqual', + expected: '{ b: 2 }', + actual: '{ b: 2 }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be deeply equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ b: 2 }', + actual: '{ b: 2 }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('not deep equal', function (t) { + t.plan(1); + t.notDeepEqual({ b: 2 }, { b: 2 }); + }); }); tap.test('not deep equal failure, depth 6, with option', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# not deep equal', - 'not ok 1 should not be deeply equivalent', - ' ---', - ' operator: notDeepEqual', - ' expected: |-', - ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - ' actual: |-', - ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should not be deeply equivalent', - ' [... stack stripped ...]', - ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'notDeepEqual', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should not be deeply equivalent', - diag: { - operator: 'notDeepEqual', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('not deep equal', { objectPrintDepth: 6 }, function (t) { - t.plan(1); - t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be deeply equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be deeply equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be deeply equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('not deep equal', { objectPrintDepth: 6 }, function (t) { + t.plan(1); + t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); + }); }); tap.test('not deep equal failure, depth 6, without option', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); - - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# not deep equal', - 'not ok 1 should not be deeply equivalent', - ' ---', - ' operator: notDeepEqual', - ' expected: |-', - ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', - ' actual: |-', - ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', - ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should not be deeply equivalent', - ' [... stack stripped ...]', - ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - - assert.deepEqual(getDiag(body), { - operator: 'notDeepEqual', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' - }); - })); - - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should not be deeply equivalent', - diag: { - operator: 'notDeepEqual', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); - - test('not deep equal', function (t) { - t.plan(1); - t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); - }); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not deep equal', + 'not ok 1 should not be deeply equivalent', + ' ---', + ' operator: notDeepEqual', + ' expected: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' actual: |-', + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }', + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be deeply equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + + assert.deepEqual(getDiag(body), { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + }); + })); + + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be deeply equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); + + test('not deep equal', function (t) { + t.plan(1); + t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); + }); }); diff --git a/test/not-equal-failure.js b/test/not-equal-failure.js index 87a66453..aa0a89d4 100644 --- a/test/not-equal-failure.js +++ b/test/not-equal-failure.js @@ -10,61 +10,61 @@ var getDiag = common.getDiag; var stripFullStack = common.stripFullStack; tap.test('not equal failure', function (assert) { - var test = tape.createHarness({ exit: false }); - var stream = test.createStream(); - var parser = tapParser(); - assert.plan(3); + var test = tape.createHarness({ exit: false }); + var stream = test.createStream(); + var parser = tapParser(); + assert.plan(3); - stream.pipe(parser); - stream.pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# not equal', - 'not ok 1 should not be strictly equal', - ' ---', - ' operator: notEqual', - ' expected: 2', - ' actual: 2', - ' at: Test. ($TEST/not-equal-failure.js:$LINE:$COL)', - ' stack: |-', - ' Error: should not be strictly equal', - ' [... stack stripped ...]', - ' at Test. ($TEST/not-equal-failure.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# not equal', + 'not ok 1 should not be strictly equal', + ' ---', + ' operator: notEqual', + ' expected: 2', + ' actual: 2', + ' at: Test. ($TEST/not-equal-failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: should not be strictly equal', + ' [... stack stripped ...]', + ' at Test. ($TEST/not-equal-failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); - assert.deepEqual(getDiag(body), { - operator: 'notEqual', - expected: '2', - actual: '2' - }); - })); + assert.deepEqual(getDiag(body), { + operator: 'notEqual', + expected: '2', + actual: '2' + }); + })); - parser.once('assert', function (data) { - assert.deepEqual(data, { - ok: false, - id: 1, - name: 'should not be strictly equal', - diag: { - operator: 'notEqual', - expected: '2', - actual: '2', - // we don't care about these next two - stack: data.diag.stack, - at: data.diag.at - } - }); - }); + parser.once('assert', function (data) { + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be strictly equal', + diag: { + operator: 'notEqual', + expected: '2', + actual: '2', + // we don't care about these next two + stack: data.diag.stack, + at: data.diag.at + } + }); + }); - test('not equal', function (t) { - t.plan(1); - t.notEqual(2, 2); - }); + test('not equal', function (t) { + t.plan(1); + t.notEqual(2, 2); + }); }); diff --git a/test/numerics.js b/test/numerics.js index 746a5098..f2b559ad 100644 --- a/test/numerics.js +++ b/test/numerics.js @@ -7,178 +7,178 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('numerics', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# numeric strings', - 'not ok 1 number equal to string', - ' ---', - ' operator: equal', - ' expected: \'3\'', - ' actual: 3', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: number equal to string', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 2 string equal to number', - ' ---', - ' operator: equal', - ' expected: 3', - ' actual: \'3\'', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: string equal to number', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 3 number notEqual to string', - 'ok 4 string notEqual to number', - 'ok 5 number looseEqual to string', - 'ok 6 string looseEqual to number', - 'not ok 7 number notLooseEqual to string', - ' ---', - ' operator: notLooseEqual', - ' expected: \'3\'', - ' actual: 3', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: number notLooseEqual to string', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 8 string notLooseEqual to number', - ' ---', - ' operator: notLooseEqual', - ' expected: 3', - ' actual: \'3\'', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: string notLooseEqual to number', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 9 number strictEqual to string', - ' ---', - ' operator: equal', - ' expected: \'3\'', - ' actual: 3', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: number strictEqual to string', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 10 string strictEqual to number', - ' ---', - ' operator: equal', - ' expected: 3', - ' actual: \'3\'', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: string strictEqual to number', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 11 number notStrictEqual to string', - 'ok 12 string notStrictEqual to number', - 'ok 13 number deepLooseEqual to string', - 'ok 14 string deepLooseEqual to number', - 'not ok 15 number notDeepLooseEqual to string', - ' ---', - ' operator: notDeepLooseEqual', - ' expected: \'3\'', - ' actual: 3', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: number notDeepLooseEqual to string', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 16 string notDeepLooseEqual to number', - ' ---', - ' operator: notDeepLooseEqual', - ' expected: 3', - ' actual: \'3\'', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: string notDeepLooseEqual to number', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 17 number deepEqual to string', - ' ---', - ' operator: deepEqual', - ' expected: \'3\'', - ' actual: 3', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: number deepEqual to string', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'not ok 18 string deepEqual to number', - ' ---', - ' operator: deepEqual', - ' expected: 3', - ' actual: \'3\'', - ' at: Test. ($TEST/numerics.js:$LINE:$COL)', - ' stack: |-', - ' Error: string deepEqual to number', - ' [... stack stripped ...]', - ' at Test. ($TEST/numerics.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 19 number notDeepEqual to string', - 'ok 20 string notDeepEqual to number', - '', - '1..20', - '# tests 20', - '# pass 10', - '# fail 10', - '' - ]); - })); + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# numeric strings', + 'not ok 1 number equal to string', + ' ---', + ' operator: equal', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number equal to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 2 string equal to number', + ' ---', + ' operator: equal', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string equal to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 3 number notEqual to string', + 'ok 4 string notEqual to number', + 'ok 5 number looseEqual to string', + 'ok 6 string looseEqual to number', + 'not ok 7 number notLooseEqual to string', + ' ---', + ' operator: notLooseEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number notLooseEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 string notLooseEqual to number', + ' ---', + ' operator: notLooseEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string notLooseEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 9 number strictEqual to string', + ' ---', + ' operator: equal', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number strictEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 10 string strictEqual to number', + ' ---', + ' operator: equal', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string strictEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 11 number notStrictEqual to string', + 'ok 12 string notStrictEqual to number', + 'ok 13 number deepLooseEqual to string', + 'ok 14 string deepLooseEqual to number', + 'not ok 15 number notDeepLooseEqual to string', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number notDeepLooseEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 16 string notDeepLooseEqual to number', + ' ---', + ' operator: notDeepLooseEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string notDeepLooseEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 17 number deepEqual to string', + ' ---', + ' operator: deepEqual', + ' expected: \'3\'', + ' actual: 3', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: number deepEqual to string', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'not ok 18 string deepEqual to number', + ' ---', + ' operator: deepEqual', + ' expected: 3', + ' actual: \'3\'', + ' at: Test. ($TEST/numerics.js:$LINE:$COL)', + ' stack: |-', + ' Error: string deepEqual to number', + ' [... stack stripped ...]', + ' at Test. ($TEST/numerics.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 19 number notDeepEqual to string', + 'ok 20 string notDeepEqual to number', + '', + '1..20', + '# tests 20', + '# pass 10', + '# fail 10', + '' + ]); + })); - test('numeric strings', function (t) { - t.equal(3, '3', 'number equal to string'); - t.equal('3', 3, 'string equal to number'); - t.notEqual(3, '3', 'number notEqual to string'); - t.notEqual('3', 3, 'string notEqual to number'); + test('numeric strings', function (t) { + t.equal(3, '3', 'number equal to string'); + t.equal('3', 3, 'string equal to number'); + t.notEqual(3, '3', 'number notEqual to string'); + t.notEqual('3', 3, 'string notEqual to number'); - t.looseEqual(3, '3', 'number looseEqual to string'); - t.looseEqual('3', 3, 'string looseEqual to number'); - t.notLooseEqual(3, '3', 'number notLooseEqual to string'); - t.notLooseEqual('3', 3, 'string notLooseEqual to number'); + t.looseEqual(3, '3', 'number looseEqual to string'); + t.looseEqual('3', 3, 'string looseEqual to number'); + t.notLooseEqual(3, '3', 'number notLooseEqual to string'); + t.notLooseEqual('3', 3, 'string notLooseEqual to number'); - t.strictEqual(3, '3', 'number strictEqual to string'); - t.strictEqual('3', 3, 'string strictEqual to number'); - t.notStrictEqual(3, '3', 'number notStrictEqual to string'); - t.notStrictEqual('3', 3, 'string notStrictEqual to number'); + t.strictEqual(3, '3', 'number strictEqual to string'); + t.strictEqual('3', 3, 'string strictEqual to number'); + t.notStrictEqual(3, '3', 'number notStrictEqual to string'); + t.notStrictEqual('3', 3, 'string notStrictEqual to number'); - t.deepLooseEqual(3, '3', 'number deepLooseEqual to string'); - t.deepLooseEqual('3', 3, 'string deepLooseEqual to number'); - t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string'); - t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number'); + t.deepLooseEqual(3, '3', 'number deepLooseEqual to string'); + t.deepLooseEqual('3', 3, 'string deepLooseEqual to number'); + t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string'); + t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number'); - t.deepEqual(3, '3', 'number deepEqual to string'); - t.deepEqual('3', 3, 'string deepEqual to number'); - t.notDeepEqual(3, '3', 'number notDeepEqual to string'); - t.notDeepEqual('3', 3, 'string notDeepEqual to number'); + t.deepEqual(3, '3', 'number deepEqual to string'); + t.deepEqual('3', 3, 'string deepEqual to number'); + t.notDeepEqual(3, '3', 'number notDeepEqual to string'); + t.notDeepEqual('3', 3, 'string notDeepEqual to number'); - t.end(); - }); + t.end(); + }); }); diff --git a/test/objectMode.js b/test/objectMode.js index fd71d8cc..eb7eddf1 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -6,66 +6,66 @@ var forEach = require('for-each'); var through = require('through'); tap.test('object results', function (assert) { - var printer = through({ objectMode: true }); - var objects = []; + var printer = through({ objectMode: true }); + var objects = []; - printer.write = function (obj) { - objects.push(obj); - }; + printer.write = function (obj) { + objects.push(obj); + }; - printer.end = function (obj) { - if (obj) { objects.push(obj); } + printer.end = function (obj) { + if (obj) { objects.push(obj); } - var todos = 0; - var skips = 0; - var testIds = []; - var endIds = []; - var asserts = 0; + var todos = 0; + var skips = 0; + var testIds = []; + var endIds = []; + var asserts = 0; - assert.equal(objects.length, 13); + assert.equal(objects.length, 13); - forEach(objects, function (object) { - if (object.type === 'assert') { - asserts++; - } else if (object.type === 'test') { - testIds.push(object.id); + forEach(objects, function (object) { + if (object.type === 'assert') { + asserts++; + } else if (object.type === 'test') { + testIds.push(object.id); - if (object.skip) { - skips++; - } else if (object.todo) { - todos++; - } - } else if (object.type === 'end') { - endIds.push(object.text); - // test object should exist - assert.notEqual(testIds.indexOf(object.test), -1); - } - }); + if (object.skip) { + skips++; + } else if (object.todo) { + todos++; + } + } else if (object.type === 'end') { + endIds.push(object.text); + // test object should exist + assert.notEqual(testIds.indexOf(object.test), -1); + } + }); - assert.equal(asserts, 5); - assert.equal(skips, 1); - assert.equal(todos, 2); - assert.equal(testIds.length, endIds.length); - assert.end(); - }; + assert.equal(asserts, 5); + assert.equal(skips, 1); + assert.equal(todos, 2); + assert.equal(testIds.length, endIds.length); + assert.end(); + }; - tape.createStream({ objectMode: true }).pipe(printer); + tape.createStream({ objectMode: true }).pipe(printer); - tape('parent', function (t1) { - t1.equal(true, true); - t1.test('child1', { skip: true }, function (t2) { - t2.equal(true, true); - t2.equal(true, false); - t2.end(); - }); - t1.test('child2', { todo: true }, function (t3) { - t3.equal(true, false); - t3.equal(true, true); - t3.end(); - }); - t1.test('child3', { todo: true }); - t1.equal(true, true); - t1.equal(true, true); - t1.end(); - }); + tape('parent', function (t1) { + t1.equal(true, true); + t1.test('child1', { skip: true }, function (t2) { + t2.equal(true, true); + t2.equal(true, false); + t2.end(); + }); + t1.test('child2', { todo: true }, function (t3) { + t3.equal(true, false); + t3.equal(true, true); + t3.end(); + }); + t1.test('child3', { todo: true }); + t1.equal(true, true); + t1.equal(true, true); + t1.end(); + }); }); diff --git a/test/objectModeWithComment.js b/test/objectModeWithComment.js index 9a34f270..b00f0779 100644 --- a/test/objectModeWithComment.js +++ b/test/objectModeWithComment.js @@ -5,37 +5,37 @@ var tape = require('../'); var through = require('through'); tap.test('test.comment() in objectMode', function (assert) { - var printer = through({ objectMode: true }); - var objects = []; - printer.on('error', function (e) { - assert.fail(e); - }); + var printer = through({ objectMode: true }); + var objects = []; + printer.on('error', function (e) { + assert.fail(e); + }); - printer.write = function (obj) { - objects.push(obj); - }; - printer.end = function (obj) { - if (obj) { objects.push(obj); } + printer.write = function (obj) { + objects.push(obj); + }; + printer.end = function (obj) { + if (obj) { objects.push(obj); } - assert.equal(objects.length, 3); - assert.deepEqual(objects, [ - { - type: 'test', - name: 'test.comment', - id: 0, - skip: false, - todo: false - }, - 'message', - { type: 'end', test: 0 } - ]); - assert.end(); - }; + assert.equal(objects.length, 3); + assert.deepEqual(objects, [ + { + type: 'test', + name: 'test.comment', + id: 0, + skip: false, + todo: false + }, + 'message', + { type: 'end', test: 0 } + ]); + assert.end(); + }; - tape.createStream({ objectMode: true }).pipe(printer); + tape.createStream({ objectMode: true }).pipe(printer); - tape('test.comment', function (test) { - test.comment('message'); - test.end(); - }); + tape('test.comment', function (test) { + test.comment('message'); + test.end(); + }); }); diff --git a/test/onFailure.js b/test/onFailure.js index 5eb05142..884963c5 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -6,22 +6,22 @@ var tape = require('../').createHarness(); // Because this test passing depends on a failure, we must direct the failing output of the inner test var noop = function () {}; var mockSink = { - on: noop, - removeListener: noop, - emit: noop, - end: noop + on: noop, + removeListener: noop, + emit: noop, + end: noop }; tape.createStream().pipe(mockSink); tap.test('on failure', { timeout: 1000 }, function (tt) { - tt.plan(1); + tt.plan(1); - tape('dummy test', function (t) { - t.fail(); - t.end(); - }); + tape('dummy test', function (t) { + t.fail(); + t.end(); + }); - tape.onFailure(function () { - tt.pass('tape ended'); - }); + tape.onFailure(function () { + tt.pass('tape ended'); + }); }); diff --git a/test/onFinish.js b/test/onFinish.js index db3b7609..b54e265a 100644 --- a/test/onFinish.js +++ b/test/onFinish.js @@ -4,11 +4,11 @@ var tap = require('tap'); var tape = require('../'); tap.test('on finish', { timeout: 1000 }, function (tt) { - tt.plan(1); - tape.onFinish(function () { - tt.pass('tape ended'); - }); - tape('dummy test', function (t) { - t.end(); - }); + tt.plan(1); + tape.onFinish(function () { + tt.pass('tape ended'); + }); + tape('dummy test', function (t) { + t.end(); + }); }); diff --git a/test/only-twice.js b/test/only-twice.js index 7c7ab183..f6db94d3 100644 --- a/test/only-twice.js +++ b/test/only-twice.js @@ -4,19 +4,19 @@ var tape = require('../'); var tap = require('tap'); tap.test('only twice error', function (assert) { - var test = tape.createHarness({ exit: false }); + var test = tape.createHarness({ exit: false }); - test.only('first only', function (t) { - t.end(); - }); + test.only('first only', function (t) { + t.end(); + }); - assert.throws(function () { - test.only('second only', function (t) { - t.end(); - }); - }, { - name: 'Error', - message: 'there can only be one only test' - }); - assert.end(); + assert.throws(function () { + test.only('second only', function (t) { + t.end(); + }); + }, { + name: 'Error', + message: 'there can only be one only test' + }); + assert.end(); }); diff --git a/test/only.js b/test/only.js index 4011d86a..3302fb20 100644 --- a/test/only.js +++ b/test/only.js @@ -5,44 +5,44 @@ var tape = require('../'); var concat = require('concat-stream'); tap.test('tape only test', function (tt) { - var test = tape.createHarness({ exit: false }); - var ran = []; - - var tc = function (rows) { - tt.deepEqual(rows.toString('utf8').split('\n'), [ - 'TAP version 13', - '# run success', - 'ok 1 assert name', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '' - ]); - tt.deepEqual(ran, [3]); - - tt.end(); - }; - - test.createStream().pipe(concat(tc)); - - test('never run fail', function (t) { - ran.push(1); - t.equal(true, false); - t.end(); - }); - - test('never run success', function (t) { - ran.push(2); - t.equal(true, true); - t.end(); - }); - - test.only('run success', function (t) { - ran.push(3); - t.ok(true, 'assert name'); - t.end(); - }); + var test = tape.createHarness({ exit: false }); + var ran = []; + + var tc = function (rows) { + tt.deepEqual(rows.toString('utf8').split('\n'), [ + 'TAP version 13', + '# run success', + 'ok 1 assert name', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '' + ]); + tt.deepEqual(ran, [3]); + + tt.end(); + }; + + test.createStream().pipe(concat(tc)); + + test('never run fail', function (t) { + ran.push(1); + t.equal(true, false); + t.end(); + }); + + test('never run success', function (t) { + ran.push(2); + t.equal(true, true); + t.end(); + }); + + test.only('run success', function (t) { + ran.push(3); + t.ok(true, 'assert name'); + t.end(); + }); }); diff --git a/test/only2.js b/test/only2.js index bf629978..494e6004 100644 --- a/test/only2.js +++ b/test/only2.js @@ -3,9 +3,9 @@ var test = require('../'); test('only2 test 1', function (t) { - t.end(); + t.end(); }); test.only('only2 test 2', function (t) { - t.end(); + t.end(); }); diff --git a/test/only3.js b/test/only3.js index 6c73ef83..01cfb041 100644 --- a/test/only3.js +++ b/test/only3.js @@ -3,15 +3,15 @@ var test = require('../'); test('only3 test 1', function (t) { - t.fail('not 1'); - t.end(); + t.fail('not 1'); + t.end(); }); test.only('only3 test 2', function (t) { - t.end(); + t.end(); }); test('only3 test 3', function (t) { - t.fail('not 3'); - t.end(); + t.fail('not 3'); + t.end(); }); diff --git a/test/only4.js b/test/only4.js index b4362124..fa96b02e 100644 --- a/test/only4.js +++ b/test/only4.js @@ -3,10 +3,10 @@ var test = require('../'); test('only4 duplicate test name', function (t) { - t.fail('not 1'); - t.end(); + t.fail('not 1'); + t.end(); }); test.only('only4 duplicate test name', function (t) { - t.end(); + t.end(); }); diff --git a/test/only5.js b/test/only5.js index abbfbe20..272b1ae2 100644 --- a/test/only5.js +++ b/test/only5.js @@ -3,10 +3,10 @@ var test = require('../'); test.only('only5 duplicate test name', function (t) { - t.end(); + t.end(); }); test('only5 duplicate test name', function (t) { - t.fail('not 2'); - t.end(); + t.fail('not 2'); + t.end(); }); diff --git a/test/order.js b/test/order.js index 5c0ea715..e1f67292 100644 --- a/test/order.js +++ b/test/order.js @@ -4,16 +4,16 @@ var test = require('../'); var current = 0; test(function (t) { - t.equal(current++, 0); - t.end(); + t.equal(current++, 0); + t.end(); }); test(function (t) { - t.plan(1); - setTimeout(function () { - t.equal(current++, 1); - }, 100); + t.plan(1); + setTimeout(function () { + t.equal(current++, 1); + }, 100); }); test(function (t) { - t.equal(current++, 2); - t.end(); + t.equal(current++, 2); + t.end(); }); diff --git a/test/plan_optional.js b/test/plan_optional.js index 6731f269..abd8b367 100644 --- a/test/plan_optional.js +++ b/test/plan_optional.js @@ -3,15 +3,15 @@ var test = require('../'); test('plan should be optional', function (t) { - t.pass('no plan here'); - t.end(); + t.pass('no plan here'); + t.end(); }); test('no plan async', function (t) { - setTimeout(function () { - t.pass('ok'); - t.end(); - }, 100); + setTimeout(function () { + t.pass('ok'); + t.end(); + }, 100); }); // vim: set softtabstop=4 shiftwidth=4: diff --git a/test/promise_fail.js b/test/promise_fail.js index 97039391..aa56343c 100644 --- a/test/promise_fail.js +++ b/test/promise_fail.js @@ -8,100 +8,100 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('callback returning rejected promise should cause that test (and only that test) to fail', function (tt) { - tt.plan(1); - - var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'fail.js')]); - - ps.stdout.pipe(concat(function (rows) { - var rowsString = rows.toString('utf8'); - - if ((/^skip\n$/).test(rowsString)) { - tt.pass('the test file indicated it should be skipped'); - return; - } - - var strippedString = stripFullStack(rowsString).filter(function (line) { - return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); - }).join('\n'); - - // hack for consistency across all versions of node - // some versions produce a longer stack trace for some reason - // since this doesn't affect the validity of the test, the extra line is removed if present - // the regex just removes the lines "at " and "[... stack stripped ...]" if they occur together - strippedString = strippedString - .replace(/.+at (?:Test\.)?\n.+\[\.\.\. stack stripped \.\.\.\]\n/g, '') - .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n'); - - tt.same(strippedString, [ - 'TAP version 13', - '# promise', - 'not ok 1 Error: rejection message', - ' ---', - ' operator: error', - ' stack: |-', - ' Error: rejection message', - ' at $TEST/promises/fail.js:$LINE:$COL', - ' [... stack stripped ...]', - ' ...', - '# after', - 'ok 2 should be truthy', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ].join('\n')); - })); + tt.plan(1); + + var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'fail.js')]); + + ps.stdout.pipe(concat(function (rows) { + var rowsString = rows.toString('utf8'); + + if ((/^skip\n$/).test(rowsString)) { + tt.pass('the test file indicated it should be skipped'); + return; + } + + var strippedString = stripFullStack(rowsString).filter(function (line) { + return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); + }).join('\n'); + + // hack for consistency across all versions of node + // some versions produce a longer stack trace for some reason + // since this doesn't affect the validity of the test, the extra line is removed if present + // the regex just removes the lines "at " and "[... stack stripped ...]" if they occur together + strippedString = strippedString + .replace(/.+at (?:Test\.)?\n.+\[\.\.\. stack stripped \.\.\.\]\n/g, '') + .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n'); + + tt.same(strippedString, [ + 'TAP version 13', + '# promise', + 'not ok 1 Error: rejection message', + ' ---', + ' operator: error', + ' stack: |-', + ' Error: rejection message', + ' at $TEST/promises/fail.js:$LINE:$COL', + ' [... stack stripped ...]', + ' ...', + '# after', + 'ok 2 should be truthy', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ].join('\n')); + })); }); tap.test('subtest callback returning rejected promise should cause that subtest (and only that subtest) to fail', function (tt) { - tt.plan(1); - - var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'subTests.js')]); - - ps.stdout.pipe(concat(function (rows) { - var rowsString = rows.toString('utf8'); - - if ((/^skip\n$/).test(rowsString)) { - tt.pass('the test file indicated it should be skipped'); - return; - } - - var strippedString = stripFullStack(rowsString).filter(function (line) { - return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); - }).join('\n'); - - // hack for consistency across all versions of node - // some versions produce a longer stack trace for some reason - // since this doesn't affect the validity of the test, the extra line is removed if present - // the regex just removes the lines "at " and "[... stack stripped ...]" if they occur together - strippedString = strippedString - .replace(/.+at (?:Test\.)?\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '') - .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n'); - - tt.same(stripFullStack(strippedString), [ - 'TAP version 13', - '# promise', - '# sub test that should fail', - 'not ok 1 Error: rejection message', - ' ---', - ' operator: error', - ' stack: |-', - ' Error: rejection message', - ' at $TEST/promises/subTests.js:$LINE:$COL', - ' [... stack stripped ...]', - ' ...', - '# sub test that should pass', - 'ok 2 should be truthy', - '', - '1..2', - '# tests 2', - '# pass 1', - '# fail 1', - '', - '' - ]); - })); + tt.plan(1); + + var ps = spawn(process.execPath, [path.join(__dirname, 'promises', 'subTests.js')]); + + ps.stdout.pipe(concat(function (rows) { + var rowsString = rows.toString('utf8'); + + if ((/^skip\n$/).test(rowsString)) { + tt.pass('the test file indicated it should be skipped'); + return; + } + + var strippedString = stripFullStack(rowsString).filter(function (line) { + return !(/^(\s+)at(\s+)(?:Test\.)?(?:$|\s)/).test(line); + }).join('\n'); + + // hack for consistency across all versions of node + // some versions produce a longer stack trace for some reason + // since this doesn't affect the validity of the test, the extra line is removed if present + // the regex just removes the lines "at " and "[... stack stripped ...]" if they occur together + strippedString = strippedString + .replace(/.+at (?:Test\.)?\n.+\[\.\.\. stack stripped \.\.\.\]\n/, '') + .replace(/(?:(.+)\[\.\.\. stack stripped \.\.\.\]\n)+/g, '$1[... stack stripped ...]\n'); + + tt.same(stripFullStack(strippedString), [ + 'TAP version 13', + '# promise', + '# sub test that should fail', + 'not ok 1 Error: rejection message', + ' ---', + ' operator: error', + ' stack: |-', + ' Error: rejection message', + ' at $TEST/promises/subTests.js:$LINE:$COL', + ' [... stack stripped ...]', + ' ...', + '# sub test that should pass', + 'ok 2 should be truthy', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + '', + '' + ]); + })); }); diff --git a/test/promises/fail.js b/test/promises/fail.js index 5047c0b9..d3ed599f 100644 --- a/test/promises/fail.js +++ b/test/promises/fail.js @@ -3,17 +3,17 @@ var test = require('../../'); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { - test('promise', function () { - return new Promise(function (resolve, reject) { - reject(new Error('rejection message')); - }); - }); + test('promise', function () { + return new Promise(function (resolve, reject) { + reject(new Error('rejection message')); + }); + }); - test('after', function (t) { - t.plan(1); - t.ok(true); - }); + test('after', function (t) { + t.plan(1); + t.ok(true); + }); } else { - // if promises aren't supported pass the node-tap test - console.log('skip'); + // if promises aren't supported pass the node-tap test + console.log('skip'); } diff --git a/test/promises/subTests.js b/test/promises/subTests.js index bb8d0d9b..4f8a5873 100644 --- a/test/promises/subTests.js +++ b/test/promises/subTests.js @@ -3,18 +3,18 @@ var test = require('../../'); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { - test('promise', function (t) { - t.test('sub test that should fail', function () { - return new Promise(function (resolve, reject) { - reject(new Error('rejection message')); - }); - }); - t.test('sub test that should pass', function (st) { - st.plan(1); - st.ok(true); - }); - }); + test('promise', function (t) { + t.test('sub test that should fail', function () { + return new Promise(function (resolve, reject) { + reject(new Error('rejection message')); + }); + }); + t.test('sub test that should pass', function (st) { + st.plan(1); + st.ok(true); + }); + }); } else { - // if promises aren't supported pass the node-tap test - console.log('skip'); + // if promises aren't supported pass the node-tap test + console.log('skip'); } diff --git a/test/require.js b/test/require.js index 6cfed91a..bb0dca74 100644 --- a/test/require.js +++ b/test/require.js @@ -6,68 +6,68 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('requiring a single module', function (t) { - t.plan(2); + t.plan(2); - var tc = function (rows) { - t.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# module-a', - 'ok 1 loaded module a', - '# test-a', - 'ok 2 module-a loaded in same context', - 'ok 3 test ran after module-a was loaded', - '', - '1..3', - '# tests 3', - '# pass 3', - '', - '# ok', - '', - '' - ]); - }; + var tc = function (rows) { + t.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# module-a', + 'ok 1 loaded module a', + '# test-a', + 'ok 2 module-a loaded in same context', + 'ok 3 test ran after module-a was loaded', + '', + '1..3', + '# tests 3', + '# pass 3', + '', + '# ok', + '', + '' + ]); + }; - var ps = tape('-r ./require/a require/test-a.js'); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - t.equal(code, 0); - }); + var ps = tape('-r ./require/a require/test-a.js'); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + t.equal(code, 0); + }); }); tap.test('requiring multiple modules', function (t) { - t.plan(2); + t.plan(2); - var tc = function (rows) { - t.same(rows.toString('utf8'), [ - 'TAP version 13', - '# module-a', - 'ok 1 loaded module a', - '# module-b', - 'ok 2 loaded module b', - '# test-a', - 'ok 3 module-a loaded in same context', - 'ok 4 test ran after module-a was loaded', - '# test-b', - 'ok 5 module-b loaded in same context', - 'ok 6 test ran after module-b was loaded', - '', - '1..6', - '# tests 6', - '# pass 6', - '', - '# ok' - ].join('\n') + '\n\n'); - }; + var tc = function (rows) { + t.same(rows.toString('utf8'), [ + 'TAP version 13', + '# module-a', + 'ok 1 loaded module a', + '# module-b', + 'ok 2 loaded module b', + '# test-a', + 'ok 3 module-a loaded in same context', + 'ok 4 test ran after module-a was loaded', + '# test-b', + 'ok 5 module-b loaded in same context', + 'ok 6 test ran after module-b was loaded', + '', + '1..6', + '# tests 6', + '# pass 6', + '', + '# ok' + ].join('\n') + '\n\n'); + }; - var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js'); - ps.stdout.pipe(concat(tc)); - ps.on('exit', function (code) { - t.equal(code, 0); - }); + var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js'); + ps.stdout.pipe(concat(tc)); + ps.on('exit', function (code) { + t.equal(code, 0); + }); }); function tape(args) { - var bin = __dirname + '/../bin/tape'; + var bin = __dirname + '/../bin/tape'; - return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }); + return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }); } diff --git a/test/require/a.js b/test/require/a.js index f4d87453..f1c23c74 100644 --- a/test/require/a.js +++ b/test/require/a.js @@ -3,8 +3,8 @@ var tape = require('../..'); tape.test('module-a', function (t) { - t.plan(1); - t.pass('loaded module a'); + t.plan(1); + t.pass('loaded module a'); }); global.module_a = true; diff --git a/test/require/b.js b/test/require/b.js index f7fe3b1c..6a2d1b52 100644 --- a/test/require/b.js +++ b/test/require/b.js @@ -3,8 +3,8 @@ var tape = require('../..'); tape.test('module-b', function (t) { - t.plan(1); - t.pass('loaded module b'); + t.plan(1); + t.pass('loaded module b'); }); global.module_b = true; diff --git a/test/require/test-a.js b/test/require/test-a.js index bcf15ca9..04834510 100644 --- a/test/require/test-a.js +++ b/test/require/test-a.js @@ -3,7 +3,7 @@ var tape = require('../..'); tape.test('test-a', function (t) { - t.ok(global.module_a, 'module-a loaded in same context'); - t.pass('test ran after module-a was loaded'); - t.end(); + t.ok(global.module_a, 'module-a loaded in same context'); + t.pass('test ran after module-a was loaded'); + t.end(); }); diff --git a/test/require/test-b.js b/test/require/test-b.js index 6cd57bfd..552565f7 100644 --- a/test/require/test-b.js +++ b/test/require/test-b.js @@ -3,7 +3,7 @@ var tape = require('../..'); tape.test('test-b', function (t) { - t.ok(global.module_b, 'module-b loaded in same context'); - t.pass('test ran after module-b was loaded'); - t.end(); + t.ok(global.module_b, 'module-b loaded in same context'); + t.pass('test ran after module-b was loaded'); + t.end(); }); diff --git a/test/skip.js b/test/skip.js index d0843599..2260027a 100644 --- a/test/skip.js +++ b/test/skip.js @@ -6,45 +6,45 @@ var concat = require('concat-stream'); var tap = require('tap'); tap.test('test SKIP comment', function (assert) { - assert.plan(1); - - var verify = function (output) { - assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# SKIP skipped', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' - ].join('\n')); - }; - - var tapeTest = test.createHarness(); - tapeTest.createStream().pipe(concat(verify)); - tapeTest('skipped', { skip: true }, function (t) { - t.end(); - }); + assert.plan(1); + + var verify = function (output) { + assert.equal(output.toString('utf8'), [ + 'TAP version 13', + '# SKIP skipped', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ].join('\n')); + }; + + var tapeTest = test.createHarness(); + tapeTest.createStream().pipe(concat(verify)); + tapeTest('skipped', { skip: true }, function (t) { + t.end(); + }); }); test('skip this', { skip: true }, function (t) { - t.fail('this should not even run'); - t.end(); + t.fail('this should not even run'); + t.end(); }); test.skip('skip this too', function (t) { - t.fail('this should not even run'); - t.end(); + t.fail('this should not even run'); + t.end(); }); test('skip subtest', function (t) { - t.test('skip this', { skip: true }, function (st) { - st.fail('this should not even run'); - st.end(); - }); - t.end(); + t.test('skip this', { skip: true }, function (st) { + st.fail('this should not even run'); + st.end(); + }); + t.end(); }); // vim: set softtabstop=4 shiftwidth=4: diff --git a/test/skip_explanation.js b/test/skip_explanation.js index 8cdb383e..ed9e5575 100644 --- a/test/skip_explanation.js +++ b/test/skip_explanation.js @@ -6,80 +6,80 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('test skip explanations', function (assert) { - assert.plan(1); + assert.plan(1); - var verify = function (output) { - assert.deepEqual(stripFullStack(output.toString('utf8')), [ - 'TAP version 13', - '# SKIP (this skips)', - '# some tests might skip', - 'ok 1 this runs', - 'ok 2 failing assert is skipped # SKIP', - 'ok 3 this runs', - '# incomplete test', - 'ok 4 run sh', - 'ok 5 run openssl # SKIP', - '# incomplete test with explanation', - 'ok 6 run sh (conditional skip) # SKIP', - 'ok 7 run openssl # SKIP can\'t run on windows platforms', - 'ok 8 this runs', - '# too much explanation', - 'ok 9 run openssl # SKIP Installer cannot work on windows and fails to add to PATH Err: (2401) denied', - '', - '1..9', - '# tests 9', - '# pass 9', - '', - '# ok', - '' - ]); - }; + var verify = function (output) { + assert.deepEqual(stripFullStack(output.toString('utf8')), [ + 'TAP version 13', + '# SKIP (this skips)', + '# some tests might skip', + 'ok 1 this runs', + 'ok 2 failing assert is skipped # SKIP', + 'ok 3 this runs', + '# incomplete test', + 'ok 4 run sh', + 'ok 5 run openssl # SKIP', + '# incomplete test with explanation', + 'ok 6 run sh (conditional skip) # SKIP', + 'ok 7 run openssl # SKIP can\'t run on windows platforms', + 'ok 8 this runs', + '# too much explanation', + 'ok 9 run openssl # SKIP Installer cannot work on windows and fails to add to PATH Err: (2401) denied', + '', + '1..9', + '# tests 9', + '# pass 9', + '', + '# ok', + '' + ]); + }; - var tapeTest = test.createHarness(); - tapeTest.createStream().pipe(concat(verify)); + var tapeTest = test.createHarness(); + tapeTest.createStream().pipe(concat(verify)); - tapeTest('(this skips)', { skip: true }, function (t) { - t.fail('doesn\'t run'); - t.fail('this doesn\'t run too', { skip: false }); - t.end(); - }); + tapeTest('(this skips)', { skip: true }, function (t) { + t.fail('doesn\'t run'); + t.fail('this doesn\'t run too', { skip: false }); + t.end(); + }); - tapeTest('some tests might skip', function (t) { - t.pass('this runs'); - t.fail('failing assert is skipped', { skip: true }); - t.pass('this runs'); - t.end(); - }); + tapeTest('some tests might skip', function (t) { + t.pass('this runs'); + t.fail('failing assert is skipped', { skip: true }); + t.pass('this runs'); + t.end(); + }); - tapeTest('incomplete test', function (t) { - // var platform = process.platform; something like this needed - var platform = 'win32'; + tapeTest('incomplete test', function (t) { + // var platform = process.platform; something like this needed + var platform = 'win32'; - t.pass('run sh', { skip: platform !== 'win32' }); - t.pass('run openssl', { skip: platform === 'win32' }); - t.end(); - }); + t.pass('run sh', { skip: platform !== 'win32' }); + t.pass('run openssl', { skip: platform === 'win32' }); + t.end(); + }); - tapeTest('incomplete test with explanation', function (t) { - // var platform = process.platform; something like this needed - var platform = 'win32'; + tapeTest('incomplete test with explanation', function (t) { + // var platform = process.platform; something like this needed + var platform = 'win32'; - t.fail('run sh (conditional skip)', { skip: platform === 'win32' }); - t.fail('run openssl', { skip: platform === 'win32' && 'can\'t run on windows platforms' }); - t.pass('this runs'); - t.end(); - }); + t.fail('run sh (conditional skip)', { skip: platform === 'win32' }); + t.fail('run openssl', { skip: platform === 'win32' && 'can\'t run on windows platforms' }); + t.pass('this runs'); + t.end(); + }); - tapeTest('too much explanation', function (t) { - // var platform = process.platform; something like this needed - var platform = 'win32'; + tapeTest('too much explanation', function (t) { + // var platform = process.platform; something like this needed + var platform = 'win32'; - t.fail( - 'run openssl', - { skip: platform === 'win32' && 'Installer cannot work on windows\nand fails to add to PATH\n\n Err: (2401) denied' } - ); - t.end(); - }); + t.fail( + 'run openssl', + { skip: platform === 'win32' && 'Installer cannot work on windows\nand fails to add to PATH\n\n Err: (2401) denied' } + ); + t.end(); + }); }); // vim: set softtabstop=4 shiftwidth=4: diff --git a/test/stackTrace.js b/test/stackTrace.js index dd5e36cd..89829e05 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -7,295 +7,295 @@ var tapParser = require('tap-parser'); var yaml = require('js-yaml'); tap.test('preserves stack trace with newlines', function (tt) { - tt.plan(3); - - var test = tape.createHarness(); - var stream = test.createStream(); - var parser = stream.pipe(tapParser()); - var stackTrace = 'foo\n bar'; - - parser.once('assert', function (data) { - tt.deepEqual(data, { - ok: false, - id: 1, - name: 'Error: Preserve stack', - diag: { - stack: stackTrace, - operator: 'error', - at: data.diag.at // we don't care about this one - } - }); - }); - - stream.pipe(concat(function (body) { - var strippedBody = stripAt(body.toString('utf8')); - 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, - operator: 'error' - }); - })); - - test('multiline stack trace', function (t) { - t.plan(1); - var err = new Error('Preserve stack'); - err.stack = stackTrace; - t.error(err); - }); + tt.plan(3); + + var test = tape.createHarness(); + var stream = test.createStream(); + var parser = stream.pipe(tapParser()); + var stackTrace = 'foo\n bar'; + + parser.once('assert', function (data) { + tt.deepEqual(data, { + ok: false, + id: 1, + name: 'Error: Preserve stack', + diag: { + stack: stackTrace, + operator: 'error', + at: data.diag.at // we don't care about this one + } + }); + }); + + stream.pipe(concat(function (body) { + var strippedBody = stripAt(body.toString('utf8')); + 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, + operator: 'error' + }); + })); + + test('multiline stack trace', function (t) { + t.plan(1); + var err = new Error('Preserve stack'); + err.stack = stackTrace; + t.error(err); + }); }); tap.test('parses function info from original stack', function (tt) { - tt.plan(4); - - var test = tape.createHarness(); - test.createStream(); - - test._results._watch = function (t) { - t.on('result', function (res) { - tt.equal('Test.testFunctionNameParsing', res.functionName); - tt.match(res.file, /stackTrace.js/i); - tt.ok(Number(res.line) > 0); - tt.ok(Number(res.column) > 0); - }); - }; - - test('t.equal stack trace', function testFunctionNameParsing(t) { - t.equal(true, false, 'true should be false'); - t.end(); - }); + tt.plan(4); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('Test.testFunctionNameParsing', res.functionName); + tt.match(res.file, /stackTrace.js/i); + tt.ok(Number(res.line) > 0); + tt.ok(Number(res.column) > 0); + }); + }; + + test('t.equal stack trace', function testFunctionNameParsing(t) { + t.equal(true, false, 'true should be false'); + t.end(); + }); }); tap.test('parses function info from original stack for anonymous function', function (tt) { - tt.plan(4); - - var test = tape.createHarness(); - test.createStream(); - - test._results._watch = function (t) { - t.on('result', function (res) { - tt.equal('Test.', res.functionName); - tt.match(res.file, /stackTrace.js/i); - tt.ok(Number(res.line) > 0); - tt.ok(Number(res.column) > 0); - }); - }; - - test('t.equal stack trace', function (t) { - t.equal(true, false, 'true should be false'); - t.end(); - }); + tt.plan(4); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('Test.', res.functionName); + tt.match(res.file, /stackTrace.js/i); + tt.ok(Number(res.line) > 0); + tt.ok(Number(res.column) > 0); + }); + }; + + test('t.equal stack trace', function (t) { + t.equal(true, false, 'true should be false'); + t.end(); + }); }); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { - tap.test('parses function info from original stack for Promise scenario', function (tt) { - tt.plan(4); - - var test = tape.createHarness(); - test.createStream(); - - test._results._watch = function (t) { - t.on('result', function (res) { - tt.equal('onfulfilled', res.functionName); - tt.match(res.file, /stackTrace.js/i); - tt.ok(Number(res.line) > 0); - tt.ok(Number(res.column) > 0); - }); - }; - - test('t.equal stack trace', function testFunctionNameParsing(t) { - new Promise(function (resolve) { - resolve(); - }).then(function onfulfilled() { - t.equal(true, false, 'true should be false'); - t.end(); - }); - }); - }); - - tap.test('parses function info from original stack for Promise scenario with anonymous function', function (tt) { - tt.plan(4); - - var test = tape.createHarness(); - test.createStream(); - - test._results._watch = function (t) { - t.on('result', function (res) { - tt.equal('', res.functionName); - tt.match(res.file, /stackTrace.js/i); - tt.ok(Number(res.line) > 0); - tt.ok(Number(res.column) > 0); - }); - }; - - test('t.equal stack trace', function testFunctionNameParsing(t) { - new Promise(function (resolve) { - resolve(); - }).then(function () { - t.equal(true, false, 'true should be false'); - t.end(); - }); - }); - }); + tap.test('parses function info from original stack for Promise scenario', function (tt) { + tt.plan(4); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('onfulfilled', res.functionName); + tt.match(res.file, /stackTrace.js/i); + tt.ok(Number(res.line) > 0); + tt.ok(Number(res.column) > 0); + }); + }; + + test('t.equal stack trace', function testFunctionNameParsing(t) { + new Promise(function (resolve) { + resolve(); + }).then(function onfulfilled() { + t.equal(true, false, 'true should be false'); + t.end(); + }); + }); + }); + + tap.test('parses function info from original stack for Promise scenario with anonymous function', function (tt) { + tt.plan(4); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('', res.functionName); + tt.match(res.file, /stackTrace.js/i); + tt.ok(Number(res.line) > 0); + tt.ok(Number(res.column) > 0); + }); + }; + + test('t.equal stack trace', function testFunctionNameParsing(t) { + new Promise(function (resolve) { + resolve(); + }).then(function () { + t.equal(true, false, 'true should be false'); + t.end(); + }); + }); + }); } tap.test('preserves stack trace for failed assertions', function (tt) { - tt.plan(6); - - var test = tape.createHarness(); - var stream = test.createStream(); - var parser = stream.pipe(tapParser()); - - var stack = ''; - parser.once('assert', function (data) { - tt.equal(typeof data.diag.at, 'string'); - tt.equal(typeof data.diag.stack, 'string'); - var at = data.diag.at || ''; - stack = data.diag.stack || ''; - tt.ok((/^Error: true should be false(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); - tt.deepEqual(data, { - ok: false, - id: 1, - name: 'true should be false', - diag: { - at: at, - stack: stack, - operator: 'equal', - expected: false, - actual: true - } - }); - }); - - stream.pipe(concat(function (body) { - var strippedBody = stripAt(body.toString('utf8')); - 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, - operator: 'equal', - expected: false, - actual: true - }); - })); - - test('t.equal stack trace', function (t) { - t.plan(1); - t.equal(true, false, 'true should be false'); - }); + tt.plan(6); + + var test = tape.createHarness(); + var stream = test.createStream(); + var parser = stream.pipe(tapParser()); + + var stack = ''; + parser.once('assert', function (data) { + tt.equal(typeof data.diag.at, 'string'); + tt.equal(typeof data.diag.stack, 'string'); + var at = data.diag.at || ''; + stack = data.diag.stack || ''; + tt.ok((/^Error: true should be false(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); + tt.deepEqual(data, { + ok: false, + id: 1, + name: 'true should be false', + diag: { + at: at, + stack: stack, + operator: 'equal', + expected: false, + actual: true + } + }); + }); + + stream.pipe(concat(function (body) { + var strippedBody = stripAt(body.toString('utf8')); + 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, + operator: 'equal', + expected: false, + actual: true + }); + })); + + test('t.equal stack trace', function (t) { + t.plan(1); + t.equal(true, false, 'true should be false'); + }); }); tap.test('preserves stack trace for failed assertions where actual===falsy', function (tt) { - tt.plan(6); - - var test = tape.createHarness(); - var stream = test.createStream(); - var parser = stream.pipe(tapParser()); - - var stack = ''; - parser.once('assert', function (data) { - tt.equal(typeof data.diag.at, 'string'); - tt.equal(typeof data.diag.stack, 'string'); - var at = data.diag.at || ''; - stack = data.diag.stack || ''; - tt.ok((/^Error: false should be true(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); - tt.deepEqual(data, { - ok: false, - id: 1, - name: 'false should be true', - diag: { - at: at, - stack: stack, - operator: 'equal', - expected: true, - actual: false - } - }); - }); - - stream.pipe(concat(function (body) { - var strippedBody = stripAt(body.toString('utf8')); - 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, - operator: 'equal', - expected: true, - actual: false - }); - })); - - test('t.equal stack trace', function (t) { - t.plan(1); - t.equal(false, true, 'false should be true'); - }); + tt.plan(6); + + var test = tape.createHarness(); + var stream = test.createStream(); + var parser = stream.pipe(tapParser()); + + var stack = ''; + parser.once('assert', function (data) { + tt.equal(typeof data.diag.at, 'string'); + tt.equal(typeof data.diag.stack, 'string'); + var at = data.diag.at || ''; + stack = data.diag.stack || ''; + tt.ok((/^Error: false should be true(\n {4}at .+)+/).exec(stack), 'stack should be a stack'); + tt.deepEqual(data, { + ok: false, + id: 1, + name: 'false should be true', + diag: { + at: at, + stack: stack, + operator: 'equal', + expected: true, + actual: false + } + }); + }); + + stream.pipe(concat(function (body) { + var strippedBody = stripAt(body.toString('utf8')); + 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, + operator: 'equal', + expected: true, + actual: false + }); + })); + + test('t.equal stack trace', function (t) { + t.plan(1); + t.equal(false, true, 'false should be true'); + }); }); function getDiag(body) { - var yamlStart = body.indexOf(' ---'); - var yamlEnd = body.indexOf(' ...\n'); - var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { - return line.slice(2); - }).join('\n'); - - // Get rid of 'at' variable (which has a line number / path of its own that's difficult to check). - var withStack = yaml.safeLoad(diag); - delete withStack.at; - return withStack; + var yamlStart = body.indexOf(' ---'); + var yamlEnd = body.indexOf(' ...\n'); + var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { + return line.slice(2); + }).join('\n'); + + // Get rid of 'at' variable (which has a line number / path of its own that's difficult to check). + var withStack = yaml.safeLoad(diag); + delete withStack.at; + return withStack; } function stripAt(body) { - return body.replace(/^\s*at:\s+Test.*$\n/m, ''); + return body.replace(/^\s*at:\s+Test.*$\n/m, ''); } diff --git a/test/subcount.js b/test/subcount.js index 62b94746..c670b460 100644 --- a/test/subcount.js +++ b/test/subcount.js @@ -3,14 +3,14 @@ var test = require('../'); test('parent test', function (t) { - t.plan(2); - t.test('first child', function (st) { - st.plan(1); - st.pass('pass first child'); - }); + t.plan(2); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); + }); - t.test(function (st) { - st.plan(1); - st.pass('pass second child'); - }); + t.test(function (st) { + st.plan(1); + st.pass('pass second child'); + }); }); diff --git a/test/subtest_and_async.js b/test/subtest_and_async.js index a5843e53..6f26a689 100644 --- a/test/subtest_and_async.js +++ b/test/subtest_and_async.js @@ -3,25 +3,25 @@ var test = require('../'); var asyncFunction = function (callback) { - setTimeout(callback, Math.random * 50); + setTimeout(callback, Math.random * 50); }; test('master test', function (t) { - t.test('subtest 1', function (st) { - st.pass('subtest 1 before async call'); - asyncFunction(function () { - st.pass('subtest 1 in async callback'); - st.end(); - }); - }); + t.test('subtest 1', function (st) { + st.pass('subtest 1 before async call'); + asyncFunction(function () { + st.pass('subtest 1 in async callback'); + st.end(); + }); + }); - t.test('subtest 2', function (st) { - st.pass('subtest 2 before async call'); - asyncFunction(function () { - st.pass('subtest 2 in async callback'); - st.end(); - }); - }); + t.test('subtest 2', function (st) { + st.pass('subtest 2 before async call'); + asyncFunction(function () { + st.pass('subtest 2 in async callback'); + st.end(); + }); + }); - t.end(); + t.end(); }); diff --git a/test/subtest_plan.js b/test/subtest_plan.js index b3063b96..04c2dad3 100644 --- a/test/subtest_plan.js +++ b/test/subtest_plan.js @@ -3,21 +3,21 @@ var test = require('../'); test('parent', function (t) { - t.plan(3); + t.plan(3); - var firstChildRan = false; + var firstChildRan = false; - t.pass('assertion in parent'); + t.pass('assertion in parent'); - t.test('first child', function (st) { - st.plan(1); - st.pass('pass first child'); - firstChildRan = true; - }); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); + firstChildRan = true; + }); - t.test('second child', function (st) { - st.plan(2); - st.ok(firstChildRan, 'first child ran first'); - st.pass('pass second child'); - }); + t.test('second child', function (st) { + st.plan(2); + st.ok(firstChildRan, 'first child ran first'); + st.pass('pass second child'); + }); }); diff --git a/test/teardown.js b/test/teardown.js index f8e4c5fc..b213853c 100644 --- a/test/teardown.js +++ b/test/teardown.js @@ -11,308 +11,308 @@ var flatMap = require('array.prototype.flatmap'); var stripFullStack = require('./common').stripFullStack; tap.test('teardowns', function (tt) { - tt.plan(1); - - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [].concat( - 'TAP version 13', - '# success', - 'ok 1 should be truthy', - '# success teardown', - '# success teardown 2', - '# success (async)', - 'ok 2 should be truthy', - '# success (async) teardown', - '# success (async) teardown 2', - '# nested teardowns', - '# nested success', - 'ok 3 should be truthy', - '# nested teardown (nested success level)', - '# nested teardown (nested success level) 2', - '# nested failure', - 'not ok 4 nested failure!', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/teardown.js:$LINE:$COL)', - ' stack: |-', - ' Error: nested failure!', - ' [... stack stripped ...]', - ' at Test. ($TEST/teardown.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# nested teardown (nested fail level)', - '# nested teardown (nested fail level) 2', - '# nested teardown (top level)', - '# nested teardown (top level) 2', - '# fail', - 'not ok 5 failure!', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/teardown.js:$LINE:$COL)', - ' stack: |-', - ' Error: failure!', - ' [... stack stripped ...]', - ' at Test. ($TEST/teardown.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# failure teardown', - '# failure teardown 2', - '# teardown errors do not stop the next teardown fn from running', - 'ok 6 should be truthy', - 'not ok 7 SyntaxError: teardown error!', - ' ---', - ' operator: fail', - ' stack: |-', - ' Error: SyntaxError: teardown error!', - ' [... stack stripped ...]', - ' ...', - 'not ok 8 plan != count', - ' ---', - ' operator: fail', - ' expected: 1', - ' actual: 2', - ' stack: |-', - ' Error: plan != count', - ' [... stack stripped ...]', - ' ...', - '# teardown runs after teardown error', - '# teardown given non-function fails the test', - 'ok 9 should be truthy', - flatMap(v.nonFunctions, function (nonFunction, i) { - var offset = 10; - return [].concat( - 'not ok ' + (offset + (i > 0 ? i + 1 : i)) + ' teardown: ' + inspect(nonFunction) + ' is not a function', - ' ---', - ' operator: fail', - ' at: ($TEST/teardown.js:$LINE:$COL)', - ' stack: |-', - ' Error: teardown: ' + inspect(nonFunction) + ' is not a function', - ' [... stack stripped ...]', - ' at $TEST/teardown.js:$LINE:$COL', - ' [... stack stripped ...]', - ' at Test. ($TEST/teardown.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - i > 0 ? [] : [ - 'not ok ' + (offset + 1) + ' plan != count', - ' ---', - ' operator: fail', - ' expected: 1', - ' actual: 2', - ' at: ($TEST/teardown.js:$LINE:$COL)', - ' stack: |-', - ' Error: plan != count', - ' [... stack stripped ...]', - ' at $TEST/teardown.js:$LINE:$COL', - ' [... stack stripped ...]', - ' at Test. ($TEST/teardown.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...' - ] - ); - }), - typeof Promise === 'function' ? [ - '# teardown is only ever called once, even when async', - 'ok ' + (11 + v.nonFunctions.length) + ' passes', - '# teardown: once?', - '# success (promise)', - 'ok ' + (12 + v.nonFunctions.length) + ' should be truthy', - '# success (promise) teardown: 1', - '# success (promise) teardown: 2', - '# success (promise) teardown: 3' - ] : [ - '# SKIP teardown is only ever called once, even when async', - '# SKIP success (promise)' - ], - [ - '', - '1..' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), - '# tests ' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), - '# pass ' + ((typeof Promise === 'function' ? 2 : 0) + 5), - '# fail ' + (5 + v.nonFunctions.length), - '' - ] - )); - })); - - test('success', function (t) { - t.plan(1); - t.teardown(function () { - t.comment('success teardown'); - }); - t.teardown(function () { - t.comment('success teardown 2'); - }); - t.ok('success!'); - }); - - test('success (async)', function (t) { - t.plan(1); - t.teardown(function () { - t.comment('success (async) teardown'); - }); - t.teardown(function () { - t.comment('success (async) teardown 2'); - }); - setTimeout(function () { - t.ok('success!'); - }, 10); - }); - - test('nested teardowns', function (t) { - t.plan(2); - - t.teardown(function () { - t.comment('nested teardown (top level)'); - }); - t.teardown(function () { - t.comment('nested teardown (top level) 2'); - }); - - t.test('nested success', function (st) { - st.teardown(function () { - st.comment('nested teardown (nested success level)'); - }); - st.teardown(function () { - st.comment('nested teardown (nested success level) 2'); - }); - - st.ok('nested success!'); - st.end(); - }); - - t.test('nested failure', function (st) { - st.plan(1); - - st.teardown(function () { - st.comment('nested teardown (nested fail level)'); - }); - st.teardown(function () { - st.comment('nested teardown (nested fail level) 2'); - }); - - st.fail('nested failure!'); - }); - }); - - test('fail', function (t) { - t.plan(1); - - t.teardown(function () { - t.comment('failure teardown'); - }); - t.teardown(function () { - t.comment('failure teardown 2'); - }); - - t.fail('failure!'); - }); - - test('teardown errors do not stop the next teardown fn from running', function (t) { - t.plan(1); - - t.ok('teardown error test'); - - t.teardown(function () { - throw new SyntaxError('teardown error!'); - }); - t.teardown(function () { - t.comment('teardown runs after teardown error'); - }); - }); - - test('teardown given non-function fails the test', function (t) { - t.plan(1); - - t.ok('non-function test'); - - forEach(v.nonFunctions, function (nonFunction) { - t.teardown(nonFunction); - }); - }); - - test('teardown is only ever called once, even when async', { skip: typeof Promise !== 'function' }, function (t) { - t.plan(1); - - t.teardown(function () { - t.comment('teardown: once?'); - }); - - t.pass('passes'); - - return Promise.resolve(); - }); - - test('success (promise)', { skip: typeof Promise !== 'function' }, function (t) { - t.plan(1); - - t.teardown(function () { - return new Promise(function (resolve) { - t.comment('success (promise) teardown: 1'); - setTimeout(resolve, 10); - }).then(function () { - t.comment('success (promise) teardown: 2'); - }); - }); - t.teardown(function () { - t.comment('success (promise) teardown: 3'); - }); - - setTimeout(function () { - t.ok('success!'); - }, 10); - }); + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [].concat( + 'TAP version 13', + '# success', + 'ok 1 should be truthy', + '# success teardown', + '# success teardown 2', + '# success (async)', + 'ok 2 should be truthy', + '# success (async) teardown', + '# success (async) teardown 2', + '# nested teardowns', + '# nested success', + 'ok 3 should be truthy', + '# nested teardown (nested success level)', + '# nested teardown (nested success level) 2', + '# nested failure', + 'not ok 4 nested failure!', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: nested failure!', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# nested teardown (nested fail level)', + '# nested teardown (nested fail level) 2', + '# nested teardown (top level)', + '# nested teardown (top level) 2', + '# fail', + 'not ok 5 failure!', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: failure!', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# failure teardown', + '# failure teardown 2', + '# teardown errors do not stop the next teardown fn from running', + 'ok 6 should be truthy', + 'not ok 7 SyntaxError: teardown error!', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: SyntaxError: teardown error!', + ' [... stack stripped ...]', + ' ...', + 'not ok 8 plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 2', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' ...', + '# teardown runs after teardown error', + '# teardown given non-function fails the test', + 'ok 9 should be truthy', + flatMap(v.nonFunctions, function (nonFunction, i) { + var offset = 10; + return [].concat( + 'not ok ' + (offset + (i > 0 ? i + 1 : i)) + ' teardown: ' + inspect(nonFunction) + ' is not a function', + ' ---', + ' operator: fail', + ' at: ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: teardown: ' + inspect(nonFunction) + ' is not a function', + ' [... stack stripped ...]', + ' at $TEST/teardown.js:$LINE:$COL', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + i > 0 ? [] : [ + 'not ok ' + (offset + 1) + ' plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 2', + ' at: ($TEST/teardown.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at $TEST/teardown.js:$LINE:$COL', + ' [... stack stripped ...]', + ' at Test. ($TEST/teardown.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...' + ] + ); + }), + typeof Promise === 'function' ? [ + '# teardown is only ever called once, even when async', + 'ok ' + (11 + v.nonFunctions.length) + ' passes', + '# teardown: once?', + '# success (promise)', + 'ok ' + (12 + v.nonFunctions.length) + ' should be truthy', + '# success (promise) teardown: 1', + '# success (promise) teardown: 2', + '# success (promise) teardown: 3' + ] : [ + '# SKIP teardown is only ever called once, even when async', + '# SKIP success (promise)' + ], + [ + '', + '1..' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), + '# tests ' + ((typeof Promise === 'function' ? 2 : 0) + 10 + v.nonFunctions.length), + '# pass ' + ((typeof Promise === 'function' ? 2 : 0) + 5), + '# fail ' + (5 + v.nonFunctions.length), + '' + ] + )); + })); + + test('success', function (t) { + t.plan(1); + t.teardown(function () { + t.comment('success teardown'); + }); + t.teardown(function () { + t.comment('success teardown 2'); + }); + t.ok('success!'); + }); + + test('success (async)', function (t) { + t.plan(1); + t.teardown(function () { + t.comment('success (async) teardown'); + }); + t.teardown(function () { + t.comment('success (async) teardown 2'); + }); + setTimeout(function () { + t.ok('success!'); + }, 10); + }); + + test('nested teardowns', function (t) { + t.plan(2); + + t.teardown(function () { + t.comment('nested teardown (top level)'); + }); + t.teardown(function () { + t.comment('nested teardown (top level) 2'); + }); + + t.test('nested success', function (st) { + st.teardown(function () { + st.comment('nested teardown (nested success level)'); + }); + st.teardown(function () { + st.comment('nested teardown (nested success level) 2'); + }); + + st.ok('nested success!'); + st.end(); + }); + + t.test('nested failure', function (st) { + st.plan(1); + + st.teardown(function () { + st.comment('nested teardown (nested fail level)'); + }); + st.teardown(function () { + st.comment('nested teardown (nested fail level) 2'); + }); + + st.fail('nested failure!'); + }); + }); + + test('fail', function (t) { + t.plan(1); + + t.teardown(function () { + t.comment('failure teardown'); + }); + t.teardown(function () { + t.comment('failure teardown 2'); + }); + + t.fail('failure!'); + }); + + test('teardown errors do not stop the next teardown fn from running', function (t) { + t.plan(1); + + t.ok('teardown error test'); + + t.teardown(function () { + throw new SyntaxError('teardown error!'); + }); + t.teardown(function () { + t.comment('teardown runs after teardown error'); + }); + }); + + test('teardown given non-function fails the test', function (t) { + t.plan(1); + + t.ok('non-function test'); + + forEach(v.nonFunctions, function (nonFunction) { + t.teardown(nonFunction); + }); + }); + + test('teardown is only ever called once, even when async', { skip: typeof Promise !== 'function' }, function (t) { + t.plan(1); + + t.teardown(function () { + t.comment('teardown: once?'); + }); + + t.pass('passes'); + + return Promise.resolve(); + }); + + test('success (promise)', { skip: typeof Promise !== 'function' }, function (t) { + t.plan(1); + + t.teardown(function () { + return new Promise(function (resolve) { + t.comment('success (promise) teardown: 1'); + setTimeout(resolve, 10); + }).then(function () { + t.comment('success (promise) teardown: 2'); + }); + }); + t.teardown(function () { + t.comment('success (promise) teardown: 3'); + }); + + setTimeout(function () { + t.ok('success!'); + }, 10); + }); }); tap.test('teardown with promise', { skip: typeof Promise !== 'function', timeout: 1e3 }, function (tt) { - tt.plan(2); - tape('dummy test', function (t) { - var resolved = false; - t.teardown(function () { - tt.pass('tape teardown'); - var p = Promise.resolve(); - p.then(function () { - resolved = true; - }); - return p; - }); - t.on('end', function () { - tt.is(resolved, true); - }); - t.end(); - }); + tt.plan(2); + tape('dummy test', function (t) { + var resolved = false; + t.teardown(function () { + tt.pass('tape teardown'); + var p = Promise.resolve(); + p.then(function () { + resolved = true; + }); + return p; + }); + t.on('end', function () { + tt.is(resolved, true); + }); + t.end(); + }); }); tap.test('teardown only runs once', { skip: typeof Promise !== 'function', timeout: 1e3 }, function (tt) { - tt.plan(1); - - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [].concat( - 'TAP version 13', - '# teardown is only called once, even with a plan', - 'ok 1 passes', - '# Tearing down!', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '' - )); - })); - - test('teardown is only called once, even with a plan', function (t) { - t.plan(1); - - t.teardown(function () { - t.comment('Tearing down!'); - }); - - t.pass('passes'); - - return Promise.resolve(); - }); + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [].concat( + 'TAP version 13', + '# teardown is only called once, even with a plan', + 'ok 1 passes', + '# Tearing down!', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '' + )); + })); + + test('teardown is only called once, even with a plan', function (t) { + t.plan(1); + + t.teardown(function () { + t.comment('Tearing down!'); + }); + + t.pass('passes'); + + return Promise.resolve(); + }); }); diff --git a/test/throws.js b/test/throws.js index e2a6d609..c1665030 100644 --- a/test/throws.js +++ b/test/throws.js @@ -10,298 +10,298 @@ var stripFullStack = require('./common').stripFullStack; var getter = function () { return 'message'; }; var messageGetterError = Object.defineProperty( - { custom: 'error' }, - 'message', - { - configurable: true, - enumerable: true, - get: getter - } + { custom: 'error' }, + 'message', + { + configurable: true, + enumerable: true, + get: getter + } ); var thrower = function () { throw messageGetterError; }; tap.test('failures', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# non functions', - 'ok 1 should throw', - 'ok 2 should throw', - 'ok 3 should throw', - 'ok 4 should throw', - 'ok 5 should throw', - 'ok 6 should throw', - 'ok 7 should throw', - 'ok 8 should throw', - '# function', - 'not ok 9 should throw', - ' ---', - ' operator: throws', - ' expected: undefined', - ' actual: undefined', - ' at: Test. ($TEST/throws.js:$LINE:$COL)', - ' stack: |-', - ' Error: should throw', - ' [... stack stripped ...]', - ' at Test. ($TEST/throws.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# custom error messages', - 'ok 10 "message" is enumerable', - "ok 11 { custom: 'error', message: 'message' }", - 'ok 12 getter is still the same', - '# throws null', - 'ok 13 throws null', - '# wrong type of error', - 'not ok 14 throws actual', - ' ---', - ' operator: throws', - ' expected: |-', - ' [Function: TypeError]', - ' actual: |-', - " { [RangeError: actual!] message: 'actual!' }", - ' at: Test. ($TEST/throws.js:$LINE:$COL)', - ' stack: |-', - ' RangeError: actual!', - ' at Test. ($TEST/throws.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '# object', - 'ok 15 object properties are validated', - '# object with regexes', - 'ok 16 object with regex values is validated', - '# similar error object', - 'ok 17 throwing a similar error', - '# validate with regex', - 'ok 18 regex against toString of error', - '# custom error validation', - 'ok 19 error is SyntaxError', - 'ok 20 error matches /value/', - 'ok 21 unexpected error', - '# throwing primitives', - 'ok 22 primitive: null', - 'ok 23 primitive: undefined', - 'ok 24 primitive: 0', - 'ok 25 primitive: NaN', - 'ok 26 primitive: 42', - 'ok 27 primitive: Infinity', - 'ok 28 primitive: \'\'', - 'ok 29 primitive: \'foo\'', - 'ok 30 primitive: true', - 'ok 31 primitive: false', - '# ambiguous arguments', - 'ok 32 Second', - 'ok 33 Second', - 'ok 34 Second', - 'ok 35 should throw', - 'not ok 36 should throw', - ' ---', - ' operator: throws', - ' expected: |-', - ' \'/Second$/\'', - ' actual: |-', - ' { [Error: First] message: \'First\' }', - ' at: Test. ($TEST/throws.js:$LINE:$COL)', - ' stack: |-', - ' Error: First', - ' at throwingFirst ($TEST/throws.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' at Test. ($TEST/throws.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..36', - '# tests 36', - '# pass 33', - '# fail 3', - '' - ]); - })); + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# non functions', + 'ok 1 should throw', + 'ok 2 should throw', + 'ok 3 should throw', + 'ok 4 should throw', + 'ok 5 should throw', + 'ok 6 should throw', + 'ok 7 should throw', + 'ok 8 should throw', + '# function', + 'not ok 9 should throw', + ' ---', + ' operator: throws', + ' expected: undefined', + ' actual: undefined', + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' Error: should throw', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# custom error messages', + 'ok 10 "message" is enumerable', + "ok 11 { custom: 'error', message: 'message' }", + 'ok 12 getter is still the same', + '# throws null', + 'ok 13 throws null', + '# wrong type of error', + 'not ok 14 throws actual', + ' ---', + ' operator: throws', + ' expected: |-', + ' [Function: TypeError]', + ' actual: |-', + " { [RangeError: actual!] message: 'actual!' }", + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' RangeError: actual!', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# object', + 'ok 15 object properties are validated', + '# object with regexes', + 'ok 16 object with regex values is validated', + '# similar error object', + 'ok 17 throwing a similar error', + '# validate with regex', + 'ok 18 regex against toString of error', + '# custom error validation', + 'ok 19 error is SyntaxError', + 'ok 20 error matches /value/', + 'ok 21 unexpected error', + '# throwing primitives', + 'ok 22 primitive: null', + 'ok 23 primitive: undefined', + 'ok 24 primitive: 0', + 'ok 25 primitive: NaN', + 'ok 26 primitive: 42', + 'ok 27 primitive: Infinity', + 'ok 28 primitive: \'\'', + 'ok 29 primitive: \'foo\'', + 'ok 30 primitive: true', + 'ok 31 primitive: false', + '# ambiguous arguments', + 'ok 32 Second', + 'ok 33 Second', + 'ok 34 Second', + 'ok 35 should throw', + 'not ok 36 should throw', + ' ---', + ' operator: throws', + ' expected: |-', + ' \'/Second$/\'', + ' actual: |-', + ' { [Error: First] message: \'First\' }', + ' at: Test. ($TEST/throws.js:$LINE:$COL)', + ' stack: |-', + ' Error: First', + ' at throwingFirst ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' at Test. ($TEST/throws.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..36', + '# tests 36', + '# pass 33', + '# fail 3', + '' + ]); + })); - test('non functions', function (t) { - t.plan(8); - t.throws(); - t.throws(null); - t.throws(true); - t.throws(false); - t.throws('abc'); - t.throws(/a/g); - t.throws([]); - t.throws({}); - }); + test('non functions', function (t) { + t.plan(8); + t.throws(); + t.throws(null); + t.throws(true); + t.throws(false); + t.throws('abc'); + t.throws(/a/g); + t.throws([]); + t.throws({}); + }); - test('function', function (t) { - t.plan(1); - t.throws(function () {}); - }); + test('function', function (t) { + t.plan(1); + t.throws(function () {}); + }); - test('custom error messages', function (t) { - t.plan(3); - t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable'); - t.throws(thrower, "{ custom: 'error', message: 'message' }"); - t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); - }); + test('custom error messages', function (t) { + t.plan(3); + t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable'); + t.throws(thrower, "{ custom: 'error', message: 'message' }"); + t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); + }); - test('throws null', function (t) { - t.plan(1); - t.throws(function () { throw null; }, 'throws null'); - t.end(); - }); + test('throws null', function (t) { + t.plan(1); + t.throws(function () { throw null; }, 'throws null'); + t.end(); + }); - test('wrong type of error', function (t) { - t.plan(1); - var actual = new RangeError('actual!'); - t.throws(function () { throw actual; }, TypeError, 'throws actual'); - t.end(); - }); + test('wrong type of error', function (t) { + t.plan(1); + var actual = new RangeError('actual!'); + t.throws(function () { throw actual; }, TypeError, 'throws actual'); + t.end(); + }); - // taken from https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message - var err = new TypeError('Wrong value'); - err.code = 404; - err.foo = 'bar'; - err.info = { - nested: true, - baz: 'text' - }; - err.reg = /abc/i; + // taken from https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message + var err = new TypeError('Wrong value'); + err.code = 404; + err.foo = 'bar'; + err.info = { + nested: true, + baz: 'text' + }; + err.reg = /abc/i; - test('object', function (t) { - t.plan(1); + test('object', function (t) { + t.plan(1); - t.throws( - function () { throw err; }, - { - name: 'TypeError', - message: 'Wrong value', - info: { - nested: true, - baz: 'text' - } - // Only properties on the validation object will be tested for. - // Using nested objects requires all properties to be present. Otherwise - // the validation is going to fail. - }, - 'object properties are validated' - ); + t.throws( + function () { throw err; }, + { + name: 'TypeError', + message: 'Wrong value', + info: { + nested: true, + baz: 'text' + } + // Only properties on the validation object will be tested for. + // Using nested objects requires all properties to be present. Otherwise + // the validation is going to fail. + }, + 'object properties are validated' + ); - t.end(); - }); + t.end(); + }); - test('object with regexes', function (t) { - t.plan(1); - t.throws( - function () { throw err; }, - { - // The `name` and `message` properties are strings and using regular - // expressions on those will match against the string. If they fail, an - // error is thrown. - name: /^TypeError$/, - message: /Wrong/, - foo: 'bar', - info: { - nested: true, - // It is not possible to use regular expressions for nested properties! - baz: 'text' - }, - // The `reg` property contains a regular expression and only if the - // validation object contains an identical regular expression, it is going - // to pass. - reg: /abc/i - }, - 'object with regex values is validated' - ); - t.end(); - }); + test('object with regexes', function (t) { + t.plan(1); + t.throws( + function () { throw err; }, + { + // The `name` and `message` properties are strings and using regular + // expressions on those will match against the string. If they fail, an + // error is thrown. + name: /^TypeError$/, + message: /Wrong/, + foo: 'bar', + info: { + nested: true, + // It is not possible to use regular expressions for nested properties! + baz: 'text' + }, + // The `reg` property contains a regular expression and only if the + // validation object contains an identical regular expression, it is going + // to pass. + reg: /abc/i + }, + 'object with regex values is validated' + ); + t.end(); + }); - test('similar error object', function (t) { - t.plan(1); - t.throws( - function () { - var otherErr = new TypeError('Not found'); - // Copy all enumerable properties from `err` to `otherErr`. - assign(otherErr, err); - throw otherErr; - }, - // The error's `message` and `name` properties will also be checked when using - // an error as validation object. - err, - 'throwing a similar error' - ); - t.end(); - }); + test('similar error object', function (t) { + t.plan(1); + t.throws( + function () { + var otherErr = new TypeError('Not found'); + // Copy all enumerable properties from `err` to `otherErr`. + assign(otherErr, err); + throw otherErr; + }, + // The error's `message` and `name` properties will also be checked when using + // an error as validation object. + err, + 'throwing a similar error' + ); + t.end(); + }); - test('validate with regex', function (t) { - t.plan(1); - t.throws( - function () { throw new Error('Wrong value'); }, - /^Error: Wrong value$/, - 'regex against toString of error' - ); - t.end(); - }); + test('validate with regex', function (t) { + t.plan(1); + t.throws( + function () { throw new Error('Wrong value'); }, + /^Error: Wrong value$/, + 'regex against toString of error' + ); + t.end(); + }); - test('custom error validation', function (t) { - t.plan(3); - t.throws( - function () { throw new SyntaxError('Wrong value'); }, - function (error) { - t.ok(error instanceof SyntaxError, 'error is SyntaxError'); - t.ok((/value/).test(error), 'error matches /value/'); - // Avoid returning anything from validation functions besides `true`. - // Otherwise, it's not clear what part of the validation failed. Instead, - // throw an error about the specific validation that failed (as done in this - // example) and add as much helpful debugging information to that error as - // possible. - return true; - }, - 'unexpected error' - ); - t.end(); - }); + test('custom error validation', function (t) { + t.plan(3); + t.throws( + function () { throw new SyntaxError('Wrong value'); }, + function (error) { + t.ok(error instanceof SyntaxError, 'error is SyntaxError'); + t.ok((/value/).test(error), 'error matches /value/'); + // Avoid returning anything from validation functions besides `true`. + // Otherwise, it's not clear what part of the validation failed. Instead, + // throw an error about the specific validation that failed (as done in this + // example) and add as much helpful debugging information to that error as + // possible. + return true; + }, + 'unexpected error' + ); + t.end(); + }); - test('throwing primitives', function (t) { - [null, undefined, 0, NaN, 42, Infinity, '', 'foo', true, false].forEach(function (primitive) { - t.throws(function () { throw primitive; }, 'primitive: ' + inspect(primitive)); - }); + test('throwing primitives', function (t) { + [null, undefined, 0, NaN, 42, Infinity, '', 'foo', true, false].forEach(function (primitive) { + t.throws(function () { throw primitive; }, 'primitive: ' + inspect(primitive)); + }); - t.end(); - }); + t.end(); + }); - test('ambiguous arguments', function (t) { - function throwingFirst() { - throw new Error('First'); - } + test('ambiguous arguments', function (t) { + function throwingFirst() { + throw new Error('First'); + } - function throwingSecond() { - throw new Error('Second'); - } + function throwingSecond() { + throw new Error('Second'); + } - function notThrowing() {} + function notThrowing() {} - // The second argument is a string and the input function threw an Error. - // The first case will not throw as it does not match for the error message - // thrown by the input function! - t.throws(throwingFirst, 'Second'); - // In the next example the message has no benefit over the message from the - // error and since it is not clear if the user intended to actually match - // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error. - t.throws(throwingSecond, 'Second'); - // TypeError [ERR_AMBIGUOUS_ARGUMENT] + // The second argument is a string and the input function threw an Error. + // The first case will not throw as it does not match for the error message + // thrown by the input function! + t.throws(throwingFirst, 'Second'); + // In the next example the message has no benefit over the message from the + // error and since it is not clear if the user intended to actually match + // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error. + t.throws(throwingSecond, 'Second'); + // TypeError [ERR_AMBIGUOUS_ARGUMENT] - // The string is only used (as message) in case the function does not throw: - t.doesNotThrow(notThrowing, 'Second'); - // AssertionError [ERR_ASSERTION]: Missing expected exception: Second + // The string is only used (as message) in case the function does not throw: + t.doesNotThrow(notThrowing, 'Second'); + // AssertionError [ERR_ASSERTION]: Missing expected exception: Second - // If it was intended to match for the error message do this instead: - // It does not fail because the error messages match. - t.throws(throwingSecond, /Second$/); + // If it was intended to match for the error message do this instead: + // It does not fail because the error messages match. + t.throws(throwingSecond, /Second$/); - // If the error message does not match, an AssertionError is thrown. - t.throws(throwingFirst, /Second$/); - // AssertionError [ERR_ASSERTION] - t.end(); - }); + // If the error message does not match, an AssertionError is thrown. + t.throws(throwingFirst, /Second$/); + // AssertionError [ERR_ASSERTION] + t.end(); + }); }); diff --git a/test/timeout.js b/test/timeout.js index bf11242d..27979678 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -4,14 +4,14 @@ var test = require('../'); var ran = 0; test('timeout', function (t) { - t.pass('this should run'); - ran++; - setTimeout(function () { - t.end(); - }, 100); + t.pass('this should run'); + ran++; + setTimeout(function () { + t.end(); + }, 100); }); test('should still run', { timeout: 50 }, function (t) { - t.equal(ran, 1); - t.end(); + t.equal(ran, 1); + t.end(); }); diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 45f77096..56c58586 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -7,95 +7,95 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('timeoutAfter test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# timeoutAfter', - 'not ok 1 timeoutAfter timed out after 1ms', - ' ---', - ' operator: fail', - ' stack: |-', - ' Error: timeoutAfter timed out after 1ms', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - }; + var test = tape.createHarness(); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# timeoutAfter', + 'not ok 1 timeoutAfter timed out after 1ms', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: timeoutAfter timed out after 1ms', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('timeoutAfter', function (t) { - t.plan(1); - t.timeoutAfter(1); - }); + test('timeoutAfter', function (t) { + t.plan(1); + t.timeoutAfter(1); + }); }); tap.test('timeoutAfter with Promises', { skip: typeof Promise === 'undefined' }, function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# timeoutAfter with promises', - '# fulfilled promise', - 'not ok 1 fulfilled promise timed out after 1ms', - ' ---', - ' operator: fail', - ' stack: |-', - ' Error: fulfilled promise timed out after 1ms', - ' [... stack stripped ...]', - ' ...', - '# rejected promise', - 'not ok 2 rejected promise timed out after 1ms', - ' ---', - ' operator: fail', - ' stack: |-', - ' Error: rejected promise timed out after 1ms', - ' [... stack stripped ...]', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 0', - '# fail 2', - '' - ]); - }; + var test = tape.createHarness(); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# timeoutAfter with promises', + '# fulfilled promise', + 'not ok 1 fulfilled promise timed out after 1ms', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: fulfilled promise timed out after 1ms', + ' [... stack stripped ...]', + ' ...', + '# rejected promise', + 'not ok 2 rejected promise timed out after 1ms', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: rejected promise timed out after 1ms', + ' [... stack stripped ...]', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 0', + '# fail 2', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('timeoutAfter with promises', function (t) { - t.plan(2); + test('timeoutAfter with promises', function (t) { + t.plan(2); - t.test('fulfilled promise', function (st) { - st.plan(1); - st.timeoutAfter(1); + t.test('fulfilled promise', function (st) { + st.plan(1); + st.timeoutAfter(1); - return new Promise(function (resolve) { - setTimeout(function () { - resolve(); - }, 10); - }); - }); + return new Promise(function (resolve) { + setTimeout(function () { + resolve(); + }, 10); + }); + }); - t.test('rejected promise', function (st) { - st.plan(1); - st.timeoutAfter(1); + t.test('rejected promise', function (st) { + st.plan(1); + st.timeoutAfter(1); - return new Promise(function (reject) { - setTimeout(function () { - reject(); - }, 10); - }); - }); - }); + return new Promise(function (reject) { + setTimeout(function () { + reject(); + }, 10); + }); + }); + }); }); diff --git a/test/todo.js b/test/todo.js index f234b1cf..a874d2c1 100644 --- a/test/todo.js +++ b/test/todo.js @@ -8,37 +8,37 @@ var common = require('./common'); var stripFullStack = common.stripFullStack; tap.test('tape todo test', function (assert) { - var test = tape.createHarness({ exit: false }); - assert.plan(1); + var test = tape.createHarness({ exit: false }); + assert.plan(1); - test.createStream().pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# success', - 'ok 1 this test runs', - '# TODO failure', - 'not ok 2 should never happen # TODO', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/todo.js:$LINE:$COL)', - ' ...', - '', - '1..2', - '# tests 2', - '# pass 2', - '', - '# ok', - '' - ]); - })); + test.createStream().pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# success', + 'ok 1 this test runs', + '# TODO failure', + 'not ok 2 should never happen # TODO', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/todo.js:$LINE:$COL)', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok', + '' + ]); + })); - test('success', function (t) { - t.equal(true, true, 'this test runs'); - t.end(); - }); + test('success', function (t) { + t.equal(true, true, 'this test runs'); + t.end(); + }); - test('failure', { todo: true }, function (t) { - t.fail('should never happen'); - t.end(); - }); + test('failure', { todo: true }, function (t) { + t.fail('should never happen'); + t.end(); + }); }); diff --git a/test/todo_explanation.js b/test/todo_explanation.js index 162219f4..33c623ad 100644 --- a/test/todo_explanation.js +++ b/test/todo_explanation.js @@ -8,63 +8,63 @@ var common = require('./common'); var stripFullStack = common.stripFullStack; tap.test('tape todo test', { todo: process.versions.node.match(/0\.8\.\d+/) ? 'Fails on node 0.8' : false }, function (assert) { - var test = tape.createHarness({ exit: false }); - assert.plan(1); + var test = tape.createHarness({ exit: false }); + assert.plan(1); - test.createStream().pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# success', - 'ok 1 this test runs', - '# TODO incomplete test1', - 'not ok 2 check output # TODO', - ' ---', - ' operator: equal', - ' expected: false', - ' actual: true', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - 'not ok 3 check vars output # TODO name conflict', - ' ---', - ' operator: equal', - ' expected: 0', - ' actual: 1', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - '# incomplete test2', - 'not ok 4 run openssl # TODO installer needs fix', - ' ---', - ' operator: fail', - ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', - ' ...', - '# TODO passing test', - '', - '1..4', - '# tests 4', - '# pass 4', - '', - '# ok', - '' - ]); - })); + test.createStream().pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# success', + 'ok 1 this test runs', + '# TODO incomplete test1', + 'not ok 2 check output # TODO', + ' ---', + ' operator: equal', + ' expected: false', + ' actual: true', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + 'not ok 3 check vars output # TODO name conflict', + ' ---', + ' operator: equal', + ' expected: 0', + ' actual: 1', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + '# incomplete test2', + 'not ok 4 run openssl # TODO installer needs fix', + ' ---', + ' operator: fail', + ' at: Test. ($TEST/todo_explanation.js:$LINE:$COL)', + ' ...', + '# TODO passing test', + '', + '1..4', + '# tests 4', + '# pass 4', + '', + '# ok', + '' + ]); + })); - test('success', function (t) { - t.equal(true, true, 'this test runs'); - t.end(); - }); + test('success', function (t) { + t.equal(true, true, 'this test runs'); + t.end(); + }); - test('incomplete test1', { todo: true }, function (t) { - t.equal(true, false, 'check output'); - t.equal(1, 0, 'check vars output', { todo: 'name conflict' }); - t.end(); - }); + test('incomplete test1', { todo: true }, function (t) { + t.equal(true, false, 'check output'); + t.equal(1, 0, 'check vars output', { todo: 'name conflict' }); + t.end(); + }); - test('incomplete test2', function (t) { - t.fail('run openssl', { todo: 'installer needs fix' }); - t.end(); - }); + test('incomplete test2', function (t) { + t.fail('run openssl', { todo: 'installer needs fix' }); + t.end(); + }); - test('passing test', { todo: 'yet incomplete' }, function (t) { - t.end(); - }); + test('passing test', { todo: 'yet incomplete' }, function (t) { + t.end(); + }); }); diff --git a/test/todo_single.js b/test/todo_single.js index 090fbe38..1dfeac80 100644 --- a/test/todo_single.js +++ b/test/todo_single.js @@ -8,32 +8,32 @@ var common = require('./common'); var stripFullStack = common.stripFullStack; tap.test('tape todo test', function (assert) { - var test = tape.createHarness({ exit: false }); - assert.plan(1); + var test = tape.createHarness({ exit: false }); + assert.plan(1); - test.createStream().pipe(concat(function (body) { - assert.deepEqual(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# TODO failure', - 'not ok 1 should be strictly equal # TODO', - ' ---', - ' operator: equal', - ' expected: false', - ' actual: true', - ' at: Test. ($TEST/todo_single.js:$LINE:$COL)', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 1', - '', - '# ok', - '' - ]); - })); + test.createStream().pipe(concat(function (body) { + assert.deepEqual(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# TODO failure', + 'not ok 1 should be strictly equal # TODO', + ' ---', + ' operator: equal', + ' expected: false', + ' actual: true', + ' at: Test. ($TEST/todo_single.js:$LINE:$COL)', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok', + '' + ]); + })); - test('failure', { todo: true }, function (t) { - t.equal(true, false); - t.end(); - }); + test('failure', { todo: true }, function (t) { + t.equal(true, false); + t.end(); + }); }); diff --git a/test/too_many.js b/test/too_many.js index dae8f36a..c22f61cf 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -8,74 +8,74 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness({ exit: false }); - var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ - 'TAP version 13', - '# array', - 'ok 1 should be deeply equivalent', - 'ok 2 should be deeply equivalent', - 'ok 3 should be deeply equivalent', - 'ok 4 should be deeply equivalent', - 'not ok 5 plan != count', - ' ---', - ' operator: fail', - ' expected: 3', - ' actual: 4', - ' at: ($TEST/too_many.js:$LINE:$COL)', - ' stack: |-', - ' Error: plan != count', - ' [... stack stripped ...]', - ' at $TEST/too_many.js:$LINE:$COL', - ' at eval (eval at ($TEST/too_many.js:$LINE:$COL))', - ' at eval (eval at ($TEST/too_many.js:$LINE:$COL))', - ' at Test. ($TEST/too_many.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - 'ok 6 should be deeply equivalent', - '', - '1..6', - '# tests 6', - '# pass 5', - '# fail 1', - '' - ]); - }; + var test = tape.createHarness({ exit: false }); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + 'TAP version 13', + '# array', + 'ok 1 should be deeply equivalent', + 'ok 2 should be deeply equivalent', + 'ok 3 should be deeply equivalent', + 'ok 4 should be deeply equivalent', + 'not ok 5 plan != count', + ' ---', + ' operator: fail', + ' expected: 3', + ' actual: 4', + ' at: ($TEST/too_many.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at $TEST/too_many.js:$LINE:$COL', + ' at eval (eval at ($TEST/too_many.js:$LINE:$COL))', + ' at eval (eval at ($TEST/too_many.js:$LINE:$COL))', + ' at Test. ($TEST/too_many.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + 'ok 6 should be deeply equivalent', + '', + '1..6', + '# tests 6', + '# pass 5', + '# fail 1', + '' + ]); + }; - test.createStream().pipe(concat(tc)); + test.createStream().pipe(concat(tc)); - test('array', function (t) { - t.plan(3); + test('array', function (t) { + t.plan(3); - var src = '(' + function () { - var xs = [1, 2, [3, 4]]; - var ys = [5, 6]; - g([xs, ys]); - } + ')()'; + var src = '(' + function () { + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); + } + ')()'; - var output = falafel(src, function (node) { - if (node.type === 'ArrayExpression') { - node.update('fn(' + node.source() + ')'); - } - }); + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); - var arrays = [ - [3, 4], - [1, 2, [3, 4]], - [5, 6], - [[1, 2, [3, 4]], [5, 6]] - ]; + var arrays = [ + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]] + ]; - Function(['fn', 'g'], output)( - function (xs) { - t.same(arrays.shift(), xs); - return xs; - }, - function (xs) { - t.same(xs, [[1, 2, [3, 4]], [5, 6]]); - } - ); - }); + Function(['fn', 'g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); + } + ); + }); }); diff --git a/test/undef.js b/test/undef.js index 204ac836..732f27e1 100644 --- a/test/undef.js +++ b/test/undef.js @@ -7,38 +7,38 @@ var concat = require('concat-stream'); var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { - tt.plan(1); + tt.plan(1); - var test = tape.createHarness(); - test.createStream().pipe(concat(function (body) { - tt.same(stripFullStack(body.toString('utf8')), [ - 'TAP version 13', - '# undef', - 'not ok 1 should be deeply equivalent', - ' ---', - ' operator: deepEqual', - ' expected: |-', - ' { beep: undefined }', - ' actual: |-', - ' {}', - ' at: Test. ($TEST/undef.js:$LINE:$COL)', - ' stack: |-', - ' Error: should be deeply equivalent', - ' [... stack stripped ...]', - ' at Test. ($TEST/undef.js:$LINE:$COL)', - ' [... stack stripped ...]', - ' ...', - '', - '1..1', - '# tests 1', - '# pass 0', - '# fail 1', - '' - ]); - })); + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [ + 'TAP version 13', + '# undef', + 'not ok 1 should be deeply equivalent', + ' ---', + ' operator: deepEqual', + ' expected: |-', + ' { beep: undefined }', + ' actual: |-', + ' {}', + ' at: Test. ($TEST/undef.js:$LINE:$COL)', + ' stack: |-', + ' Error: should be deeply equivalent', + ' [... stack stripped ...]', + ' at Test. ($TEST/undef.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1', + '' + ]); + })); - test('undef', function (t) { - t.plan(1); - t.deepEqual({}, { beep: undefined }); - }); + test('undef', function (t) { + t.plan(1); + t.deepEqual({}, { beep: undefined }); + }); });