From d56754a281edc6d9f9eac5b563cb8668952b8d09 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 14 Oct 2013 08:28:28 -0700 Subject: [PATCH 001/373] failing deep strict equal test --- test/deep.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/deep.js diff --git a/test/deep.js b/test/deep.js new file mode 100644 index 00000000..02f3681e --- /dev/null +++ b/test/deep.js @@ -0,0 +1,9 @@ +var test = require('../'); + +test('deep strict equal', function (t) { + t.notDeepEqual( + [ { a: '3' } ], + [ { a: 3 } ] + ); + t.end(); +}); From 95f827d8121cc751ba6c9f7d66bc8626105e0792 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 14 Oct 2013 08:32:49 -0700 Subject: [PATCH 002/373] strict deep equal comparisons --- lib/test.js | 30 +++++++++++++++++++++++++++--- package.json | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/test.js b/lib/test.js index 6475dc6d..435c39f2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -279,13 +279,24 @@ Test.prototype.notEqual Test.prototype.deepEqual = Test.prototype.deepEquals = Test.prototype.isEquivalent += Test.prototype.same += function (a, b, msg, extra) { + this._assert(deepEqual(a, b, { strict: true }), { + message : defined(msg, 'should be equivalent'), + operator : 'deepEqual', + actual : a, + expected : b, + extra : extra + }); +}; + +Test.prototype.deepLooseEqual = Test.prototype.looseEqual = Test.prototype.looseEquals -= Test.prototype.same = function (a, b, msg, extra) { this._assert(deepEqual(a, b), { message : defined(msg, 'should be equivalent'), - operator : 'deepEqual', + operator : 'deepLooseEqual', actual : a, expected : b, extra : extra @@ -301,7 +312,7 @@ Test.prototype.notDeepEqual = Test.prototype.isNotEquivalent = Test.prototype.isInequivalent = function (a, b, msg, extra) { - this._assert(!deepEqual(a, b), { + this._assert(!deepEqual(a, b, { strict: true }), { message : defined(msg, 'should not be equivalent'), operator : 'notDeepEqual', actual : a, @@ -310,6 +321,19 @@ Test.prototype.notDeepEqual }); }; +Test.prototype.notDeepLooseEqual += Test.prototype.notLooseEqual += Test.prototype.notLooseEquals += function (a, b, msg, extra) { + this._assert(deepEqual(a, b), { + message : defined(msg, 'should be equivalent'), + operator : 'notDeepLooseEqual', + actual : a, + expected : b, + extra : extra + }); +}; + Test.prototype['throws'] = function (fn, expected, msg, extra) { if (typeof expected === 'string') { msg = expected; diff --git a/package.json b/package.json index 11d08a2a..e4a73a76 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "dependencies" : { "jsonify" : "~0.0.0", - "deep-equal" : "~0.0.0", + "deep-equal" : "~0.1.0", "defined" : "~0.0.0", "through": "~2.3.4" }, From 785be995ef8165c0c67534429f9de879512a9bb0 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 14 Oct 2013 08:35:53 -0700 Subject: [PATCH 003/373] document strict/loose deep equals --- readme.markdown | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/readme.markdown b/readme.markdown index e3ae322a..800da36a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -125,21 +125,38 @@ Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, Assert that `a` and `b` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with an optional description `msg`. +with strict comparisons (`===`) on leaf nodes and an optional description +`msg`. -Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.looseEqual()`, -`t.looseEquals()`, `t.same()` +Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.same()` ## t.notDeepEqual(a, b, msg) Assert that `a` and `b` do not have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with an optional description `msg`. +with strict comparisons (`===`) on leaf nodes and an optional description +`msg`. Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, `t.isNotDeepEqual()`, `t.isNotDeeply()`, `t.isNotEquivalent()`, `t.isInequivalent()` +## t.deepLooseEqual(a, b, msg) + +Assert that `a` and `b` have the same structure and nested values using +[node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) +with loose comparisons (`==`) on leaf nodes and an optional description `msg`. + +Aliases: `t.looseEqual()`, `t.looseEquals()` + +## t.notDeepLooseEqual(a, b, msg) + +Assert that `a` and `b` do not have the same structure and nested values using +[node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) +with loose comparisons (`==`) on leaf nodes and an optional description `msg`. + +Aliases: `t.notLooseEqual()`, `t.notLooseEquals()` + ## t.throws(fn, expected, msg) Assert that the function call `fn()` throws an exception. From 9eb1fd16c988da7e63f2f4603da955dabf50c077 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 14 Oct 2013 08:36:02 -0700 Subject: [PATCH 004/373] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4a73a76..a03c8498 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "1.1.1", + "version" : "2.0.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 37305c2626c430bebdb646fddab91c30b2d3c247 Mon Sep 17 00:00:00 2001 From: michaelrhodes Date: Sat, 26 Oct 2013 02:22:32 +1000 Subject: [PATCH 005/373] toStringified msg to prevent TypeError --- lib/results.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/results.js b/lib/results.js index 0bbde297..af63ef6b 100644 --- a/lib/results.js +++ b/lib/results.js @@ -132,7 +132,7 @@ Results.prototype.close = function () { function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; - output += res.name ? ' ' + res.name.replace(/\s+/g, ' ') : ''; + output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; if (res.skip) output += ' # SKIP'; else if (res.todo) output += ' # TODO'; From 8622bd5c7004f5dbd062145fa5cd18e4a1519d4d Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 25 Oct 2013 18:08:39 -0500 Subject: [PATCH 006/373] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a03c8498..ae7ab95d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.0.0", + "version" : "2.0.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From cfff35b68a5d2701c08d32797bb73d92eabb3bed Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sat, 12 Oct 2013 11:41:23 -0700 Subject: [PATCH 007/373] Add checks against double-execution of child tests --- test/child_ordering.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/child_ordering.js b/test/child_ordering.js index 03b88e20..12efafe9 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -20,10 +20,13 @@ 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(t) { + t.ok(!parentRan, 'parent ran twice'); parentRan = true; t.test('grandchild', function(t) { + t.ok(!grandChildRan, 'grand child ran twice'); grandChildRan = true; t.pass('grand child ran'); t.end(); From 48964a6b479df326248dfe8ddeb056a667ea5f55 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sat, 12 Oct 2013 11:40:33 -0700 Subject: [PATCH 008/373] Refactor test-ordering logic Emit child tests to be run on successive calls to .end rather than explicitly ordering them as they are created. --- lib/results.js | 81 +++++++++++--------------------------------------- lib/test.js | 1 + 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/lib/results.js b/lib/results.js index af63ef6b..961ffde3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -20,9 +20,8 @@ module.exports = function () { nextTick(function next () { var t = getNextTest(results); - if (!t && results.running) return; - if (!t) return results.close(); - t.run(); + if (t) t.run(); + else results.close(); }); return output; @@ -34,52 +33,26 @@ function Results (stream) { this.pass = 0; this.stream = stream; this.tests = []; - this.running = 0; } -Results.prototype.push = function (t, parentT) { +Results.prototype.push = function (t) { + var self = this; + self.tests.push(t); + self._watch(t); + t.once('end', function () { + var nt = getNextTest(self); + if (nt) nt.run(); + else self.close(); + }); +}; + +Results.prototype._watch = function (t) { var self = this; var write = function (s) { self.stream.queue(s) }; t.once('prerun', function () { - if (self.only && self.only !== t.name && !parentT) { - var nt = getNextTest(self); - if (nt) nt.run() - else self.close(); - return; - } - - self.running ++; write('# ' + t.name + '\n'); }); - if (parentT) { - var ix = self.tests.indexOf(parentT); - if (ix >= 0) self.tests.splice(ix, 0, t); - } - else self.tests.push(t); - - var plan; - t.on('plan', function (n) { plan = n }); - - var subtests = 0; - - t.on('test', function (st) { - subtests ++; - st.on('end', function () { - subtests --; - if (subtests === 1) nextTick(function () { st.run() }); - else if (subtests === 0 && !t.ended) { - t.end(); - } - }); - self.push(st, t); - if (subtests === 1) { - if (plan === undefined) st.run(); - else nextTick(function () { - st.run(); - }); - } - }); - + t.on('result', function (res) { if (typeof res === 'string') { write('# ' + res + '\n'); @@ -91,27 +64,9 @@ Results.prototype.push = function (t, parentT) { if (res.ok) self.pass ++ else self.fail ++ }); - - t.once('end', function () { - if (t._skip) { - var nt = getNextTest(self); - if (nt) nt.run(); - else self.close(); - return; - } - - self.running --; - if (subtests !== 0) return; - - if (self.running === 0 && self.tests.length) { - var nt = getNextTest(self); - if (nt) nt.run(); - else self.close(); - } - else if (self.running === 0) { - self.close(); - } - }); + + t.on('test', function (st) { self._watch(st) }); + t.on('next', function (st) { st.run() }); }; Results.prototype.close = function () { diff --git a/lib/test.js b/lib/test.js index 435c39f2..c53abb5a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -79,6 +79,7 @@ Test.prototype.end = function () { if (this._progeny.length) { var t = this._progeny.shift(); t.on('end', function () { self.end() }); + this.emit('next', t); return; } From bc037437d658b050347220c0f8c2ff101d669dd9 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sun, 13 Oct 2013 14:33:45 -0700 Subject: [PATCH 009/373] Add failing test for planning # of subtests --- test/subtest_plan.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/subtest_plan.js diff --git a/test/subtest_plan.js b/test/subtest_plan.js new file mode 100644 index 00000000..67a4c464 --- /dev/null +++ b/test/subtest_plan.js @@ -0,0 +1,21 @@ +var test = require('../'); + +test('parent', function (t) { + t.plan(3) + + var firstChildRan = false; + + t.pass('assertion in parent'); + + t.test('first child', function (t) { + t.plan(1); + t.pass('pass first child'); + firstChildRan = true; + }); + + t.test('second child', function (t) { + t.plan(2); + t.ok(firstChildRan, 'first child ran'); + t.pass('pass second child'); + }); +}); From 978431c8a6db8cf3925a8b1b95a771aa872b9283 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Sun, 13 Oct 2013 12:27:24 -0700 Subject: [PATCH 010/373] Count subtests against the plan --- lib/test.js | 68 ++++++++++++++++++++++++++++++++++++-------- test/nested.js | 2 +- test/subtest_plan.js | 2 +- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/lib/test.js b/lib/test.js index c53abb5a..5edb47fe 100644 --- a/lib/test.js +++ b/lib/test.js @@ -5,6 +5,25 @@ var path = require('path'); var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; +/** + * Transitions: + * + * From -> To : Triggered by + * + * PENDING -> RUNNING : Results object calls .run + * RUNNING -> FINISHED : .end no remaining subtest + * RUNNING -> SUBTESTS : .end with subtests + * SUBTESTS -> FINISHED : .end after all subtests end + * + * .end is called when: + * + * - it's called by the test itself + * - there is a plan and: + * - The assertion count + number of children == plan + * + */ + + module.exports = Test; var nextTick = typeof setImmediate !== 'undefined' @@ -36,6 +55,7 @@ function Test (name_, opts_, cb_) { this.readable = true; this.name = name || '(anonymous)'; this.assertCount = 0; + this.pendingCount = 0; this._skip = opts.skip || false; this._plan = undefined; this._cb = cb; @@ -60,9 +80,19 @@ Test.prototype.run = function () { }; Test.prototype.test = function (name, opts, cb) { + var self = this; var t = new Test(name, opts, cb); this._progeny.push(t); + this.pendingCount++; this.emit('test', t); + t.on('prerun', function () { + self.assertCount++; + }) + if (!self._pendingAsserts()) { + nextTick(function () { + self.end(); + }); + } }; Test.prototype.comment = function (msg) { @@ -76,16 +106,19 @@ Test.prototype.plan = function (n) { Test.prototype.end = function () { var self = this; + if (this._progeny.length) { var t = this._progeny.shift(); - t.on('end', function () { self.end() }); + t.on('end', function () { + self.end(); + }); this.emit('next', t); return; } if (!this.ended) this.emit('end'); - if (this._plan !== undefined && - !this._planError && this.assertCount !== this._plan) { + var pendingAsserts = this._pendingAsserts(); + if (!this._planError && this._plan !== undefined && pendingAsserts) { this._planError = true; this.fail('plan != count', { expected : this._plan, @@ -112,6 +145,15 @@ Test.prototype._exit = function () { } }; +Test.prototype._pendingAsserts = function () { + if (this._plan === undefined) { + return 1; + } else { + return this._plan - + (this._progeny.length + this.assertCount); + } +} + Test.prototype._assert = function assert (ok, opts) { var self = this; var extra = opts.extra || {}; @@ -160,20 +202,22 @@ Test.prototype._assert = function assert (ok, opts) { self.emit('result', res); - if (self._plan === self.assertCount && extra.exiting) { - if (!self.ended) self.end(); - } - else if (self._plan === self.assertCount) { - nextTick(function () { - if (!self.ended) self.end(); - }); + var pendingAsserts = self._pendingAsserts(); + if (!pendingAsserts) { + if (extra.exiting) { + self.end(); + } else { + nextTick(function () { + self.end(); + }); + } } - if (!self._planError && self.assertCount > self._plan) { + if (!self._planError && pendingAsserts < 0) { self._planError = true; self.fail('plan != count', { expected : self._plan, - actual : self.assertCount + actual : self._plan - pendingAsserts }); } }; diff --git a/test/nested.js b/test/nested.js index 6af123bc..673465d4 100644 --- a/test/nested.js +++ b/test/nested.js @@ -39,7 +39,7 @@ tap.test('array test', function (tt) { test.createStream().pipe(tc); test('nested array test', function (t) { - t.plan(5); + t.plan(6); var src = '(' + function () { var xs = [ 1, 2, [ 3, 4 ] ]; diff --git a/test/subtest_plan.js b/test/subtest_plan.js index 67a4c464..2b075ae5 100644 --- a/test/subtest_plan.js +++ b/test/subtest_plan.js @@ -15,7 +15,7 @@ test('parent', function (t) { t.test('second child', function (t) { t.plan(2); - t.ok(firstChildRan, 'first child ran'); + t.ok(firstChildRan, 'first child ran first'); t.pass('pass second child'); }); }); From 2c068521e2db12327ee381cb09a5a2b81af7d06c Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 12:09:17 -0700 Subject: [PATCH 011/373] Remove comment block That was just me thinking out loud --- lib/test.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/test.js b/lib/test.js index 5edb47fe..9a7199a8 100644 --- a/lib/test.js +++ b/lib/test.js @@ -5,25 +5,6 @@ var path = require('path'); var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; -/** - * Transitions: - * - * From -> To : Triggered by - * - * PENDING -> RUNNING : Results object calls .run - * RUNNING -> FINISHED : .end no remaining subtest - * RUNNING -> SUBTESTS : .end with subtests - * SUBTESTS -> FINISHED : .end after all subtests end - * - * .end is called when: - * - * - it's called by the test itself - * - there is a plan and: - * - The assertion count + number of children == plan - * - */ - - module.exports = Test; var nextTick = typeof setImmediate !== 'undefined' From 709c36afe5d9aef36a35cc0dbb461bcfe8714a94 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 14:20:03 -0700 Subject: [PATCH 012/373] Add test for running children asynchronously --- test/child_ordering_async.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/child_ordering_async.js diff --git a/test/child_ordering_async.js b/test/child_ordering_async.js new file mode 100644 index 00000000..32576455 --- /dev/null +++ b/test/child_ordering_async.js @@ -0,0 +1,15 @@ +var test = require('../'); + +test('parent', function (t) { + var parentFinished = false; + setTimeout(function () { + t.pass('pass parent test'); + parentFinished = true; + t.end(); + }) + + t.test('child', function (t) { + t.ok(parentFinished, 'parent should finish before child runs'); + t.end(); + }) +}) From 8449f1c1600eec44153eab0b430bd00e50598d40 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 14:24:14 -0700 Subject: [PATCH 013/373] Add nested-sync-noplan-noend --- test/nested-sync-noplan-noend.js | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/nested-sync-noplan-noend.js diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js new file mode 100644 index 00000000..a206c501 --- /dev/null +++ b/test/nested-sync-noplan-noend.js @@ -0,0 +1,50 @@ +var tape = require('../'); +var tap = require('tap'); + +tap.test('nested sync test without plan or end', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : r.name.trim() }; + } + else return r; + }); + var expected = [ + 'TAP version 13', + 'nested without plan or end', + 'first', + { id: 1, ok: true, name: '(unnamed assert)' }, + 'second', + { id: 2, ok: true, name: '(unnamed assert)' }, + 'tests 2', + 'pass 2', + 'ok' + ] + tt.same(rs, expected); + }); + + test.createStream().pipe(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); + }); + }); + +}); From 188fbb15456774a917619f95af8d04dfcd28f1b2 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 14:24:23 -0700 Subject: [PATCH 014/373] Add patch from @spion to make nested-sync-noplan-noend pass --- lib/test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/test.js b/lib/test.js index 9a7199a8..4920a83e 100644 --- a/lib/test.js +++ b/lib/test.js @@ -58,6 +58,10 @@ Test.prototype.run = function () { return; } this.emit('run'); + var self = this; + if (!this._plan && this._progeny.length) nextTick(function () { + self.end(); + }); }; Test.prototype.test = function (name, opts, cb) { From 78e48c9fa90d1326abb5623b08f7617bfd730a47 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 14:27:57 -0700 Subject: [PATCH 015/373] Remove 'next' event After all the other changes, it turns out to be redundant. --- lib/results.js | 1 - lib/test.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/results.js b/lib/results.js index 961ffde3..4b4c4b8a 100644 --- a/lib/results.js +++ b/lib/results.js @@ -66,7 +66,6 @@ Results.prototype._watch = function (t) { }); t.on('test', function (st) { self._watch(st) }); - t.on('next', function (st) { st.run() }); }; Results.prototype.close = function () { diff --git a/lib/test.js b/lib/test.js index 4920a83e..a97fbd30 100644 --- a/lib/test.js +++ b/lib/test.js @@ -97,7 +97,7 @@ Test.prototype.end = function () { t.on('end', function () { self.end(); }); - this.emit('next', t); + t.run(); return; } From c39be29cd9063497506b63e27ba715e3101ca666 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 15:21:49 -0700 Subject: [PATCH 016/373] Revert "Add test for running children asynchronously" This reverts commit 018690fe0a49dc5b3b24e2733b74d6d676f897a8. --- test/child_ordering_async.js | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 test/child_ordering_async.js diff --git a/test/child_ordering_async.js b/test/child_ordering_async.js deleted file mode 100644 index 32576455..00000000 --- a/test/child_ordering_async.js +++ /dev/null @@ -1,15 +0,0 @@ -var test = require('../'); - -test('parent', function (t) { - var parentFinished = false; - setTimeout(function () { - t.pass('pass parent test'); - parentFinished = true; - t.end(); - }) - - t.test('child', function (t) { - t.ok(parentFinished, 'parent should finish before child runs'); - t.end(); - }) -}) From a43860b1225e43c2894cf85472f22ec5d5e31c94 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 15:21:59 -0700 Subject: [PATCH 017/373] Revert "Add patch from @spion to make nested-sync-noplan-noend pass" This reverts commit 892c605f6efb713a6be8fe4475035921e312f576. --- lib/test.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/test.js b/lib/test.js index a97fbd30..d9f65b65 100644 --- a/lib/test.js +++ b/lib/test.js @@ -58,10 +58,6 @@ Test.prototype.run = function () { return; } this.emit('run'); - var self = this; - if (!this._plan && this._progeny.length) nextTick(function () { - self.end(); - }); }; Test.prototype.test = function (name, opts, cb) { From 35f29a8d12857e28a04acc374682704a0359c942 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 15:18:00 -0700 Subject: [PATCH 018/373] Add second @spion patch --- lib/test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/test.js b/lib/test.js index d9f65b65..9d03a887 100644 --- a/lib/test.js +++ b/lib/test.js @@ -69,11 +69,18 @@ Test.prototype.test = function (name, opts, cb) { 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 (msg) { From 8b59a8010fb4441f9fc5f17c70d06ddb903d7aae Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 14 Oct 2013 15:21:14 -0700 Subject: [PATCH 019/373] add test for asynchronously adding subtests --- test/add-subtest-async.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/add-subtest-async.js diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js new file mode 100644 index 00000000..74b4d8a0 --- /dev/null +++ b/test/add-subtest-async.js @@ -0,0 +1,11 @@ +var test = require('../') + +test('parent', function (t) { + t.pass('parent'); + setTimeout(function () { + t.test('child', function (t) { + t.pass('child'); + t.end(); + }); + }, 100) +}) From 9d64ad33a9e74d48614136e0ec54e1f2eac01dad Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Wed, 16 Oct 2013 20:11:48 -0700 Subject: [PATCH 020/373] Add test for async asserts in subtests ref #42 It passes on this branch with no changes, w00t --- test/subtest_and_async.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/subtest_and_async.js diff --git a/test/subtest_and_async.js b/test/subtest_and_async.js new file mode 100644 index 00000000..719dbf5b --- /dev/null +++ b/test/subtest_and_async.js @@ -0,0 +1,23 @@ +var test = require('../'); + +var asyncFunction = function (callback) { + setTimeout(callback, Math.random * 50); +}; + +test('master test', function (t) { + t.test('subtest 1', function (t) { + t.pass('subtest 1 before async call'); + asyncFunction(function () { + t.pass('subtest 1 in async callback'); + t.end(); + }) + }); + + t.test('subtest 2', function (t) { + t.pass('subtest 2 before async call'); + asyncFunction(function () { + t.pass('subtest 2 in async callback'); + t.end(); + }) + }); +}); From e8b7c72f082da89b281c8ef54ddf4717fa13cd0e Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 25 Oct 2013 18:20:30 -0500 Subject: [PATCH 021/373] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae7ab95d..ace1ac11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.0.1", + "version" : "2.1.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 021da85e63a6748fc85825663c6db69a2a370451 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 14:50:42 +0800 Subject: [PATCH 022/373] rip out the old `new Stream` default stream to just use split, duplexer, and through --- lib/default_stream.js | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index 0e3861fb..ceb5e5b4 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -1,30 +1,11 @@ -var Stream = require('stream'); +var through = require('through'); +var duplexer = require('duplexer'); +var split = require('split'); module.exports = function () { - var out = new Stream; - out.writable = true; - var buffered = ''; + return duplexer(split(), through(write)); - out.write = function (buf) { - var s = buffered + String(buf); - var lines = s.split('\n'); - for (var i = 0; i < lines.length - 1; i++) { - console.log(lines[i]); - } - buffered = lines[i]; - }; - - out.destroy = function () { - out.writable = false; - out.emit('close'); - }; - - out.end = function (msg) { - if (msg !== undefined) out.write(msg); - if (buffered) console.log(buffered); - out.writable = false; - out.emit('close'); - }; - - return out; + function write (line) { + console.log(line); + } }; From 2ce40f57216d647ca49f86c4b717aa1a1fc36774 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 14:55:45 +0800 Subject: [PATCH 023/373] properly fixed the default stream --- lib/default_stream.js | 4 ++-- package.json | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index ceb5e5b4..be4fa4bd 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -1,9 +1,9 @@ var through = require('through'); -var duplexer = require('duplexer'); +var combine = require('stream-combiner'); var split = require('split'); module.exports = function () { - return duplexer(split(), through(write)); + return combine(split(), through(write)); function write (line) { console.log(line); diff --git a/package.json b/package.json index ace1ac11..92247b69 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "jsonify" : "~0.0.0", "deep-equal" : "~0.1.0", "defined" : "~0.0.0", - "through": "~2.3.4" + "through": "~2.3.4", + "stream-combiner": "~0.0.2", + "split": "~0.2.10" }, "devDependencies" : { "tap" : "~0.3.0", From 2954dacdef87324ae0a192deac194f83c6200441 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 16:08:18 +0800 Subject: [PATCH 024/373] is now properly noisy when more commits than expected were run --- index.js | 41 ++++++++++++++--------------- lib/results.js | 70 ++++++++++++++++++++++++++++---------------------- package.json | 3 ++- 3 files changed, 63 insertions(+), 51 deletions(-) diff --git a/index.js b/index.js index b39936df..b8f0b563 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ +var defined = require('defined'); var createDefaultStream = require('./lib/default_stream'); var Test = require('./lib/test'); -var createResultStream = require('./lib/results'); +var createResult = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process && typeof process.on === 'function' @@ -17,13 +18,17 @@ var nextTick = typeof setImmediate !== 'undefined' exports = module.exports = (function () { var harness; var lazyLoad = function () { - if (!harness) harness = createExitHarness(); + if (!harness) harness = createExitHarness({ + autoclose: !canEmitExit + }); return harness.apply(this, arguments); }; lazyLoad.only = function () { - if (!harness) harness = createExitHarness(); + if (!harness) harness = createExitHarness({ + autoclose: !canEmitExit + }); return harness.only.apply(this, arguments); } @@ -33,7 +38,10 @@ exports = module.exports = (function () { function createExitHarness (conf) { if (!conf) conf = {}; - var harness = createHarness(); + var harness = createHarness({ + autoclose: defined(conf.autoclose, false) + }); + var stream = harness.createStream(); stream.pipe(createDefaultStream()); @@ -62,6 +70,7 @@ function createExitHarness (conf) { t._exit(); } } + harness.close(); process.exit(code || harness._exitCode); }); return harness; @@ -74,14 +83,13 @@ exports.test = exports; // tap compat var exitInterval; function createHarness (conf_) { - var results; + if (!conf_) conf_ = {}; + var results = createResult(); + if (conf_.autoclose !== false) { + results.once('done', function () { results.close() }); + } var test = function (name, conf, cb) { - if (!results) { - results = createResultStream(); - results.pause(); - } - var t = new Test(name, conf, cb); test._tests.push(t); @@ -101,16 +109,7 @@ function createHarness (conf_) { test._tests = []; test.createStream = function () { - if (!results) results = createResultStream(); - - var _pause = results.pause; - var paused = false; - results.pause = function () { paused = true }; - - nextTick(function () { - if (!paused) results.resume(); - }); - return results; + return results.createStream(); }; var only = false; @@ -122,5 +121,7 @@ function createHarness (conf_) { }; test._exitCode = 0; + test.close = function () { results.close() }; + return test; } diff --git a/lib/results.js b/lib/results.js index 4b4c4b8a..d8ba3f07 100644 --- a/lib/results.js +++ b/lib/results.js @@ -1,54 +1,64 @@ var Stream = require('stream'); +var EventEmitter = require('events').EventEmitter; +var inherits = require('inherits'); var json = typeof JSON === 'object' ? JSON : require('jsonify'); var through = require('through'); +var resumer = require('resumer'); var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; -module.exports = function () { - var output = through(); - output.pause(); - output.queue('TAP version 13\n'); - - var results = new Results(output); - output.push = function (t) { results.push(t) }; - - output.only = function (name) { - results.only = name; - }; - - nextTick(function next () { - var t = getNextTest(results); - if (t) t.run(); - else results.close(); - }); - - return output; -}; +module.exports = Results; +inherits(Results, EventEmitter); -function Results (stream) { +function Results () { + if (!(this instanceof Results)) return new Results; this.count = 0; this.fail = 0; this.pass = 0; - this.stream = stream; + this._stream = through(); this.tests = []; } +Results.prototype.createStream = function () { + var self = this; + var output = resumer(); + output.queue('TAP version 13\n'); + + nextTick(function () { + var t = getNextTest(self); + if (t) t.run() + else self.emit('done') + }); + self._stream.pipe(output); + + return output; +}; + Results.prototype.push = function (t) { var self = this; self.tests.push(t); self._watch(t); t.once('end', function () { var nt = getNextTest(self); - if (nt) nt.run(); - else self.close(); + if (nt) nt.run() + else self.emit('done') }); }; +Results.prototype.only = function (name) { + if (this._only) { + self.count ++; + self.fail ++; + write('not ok ' + self.count + ' already called .only()\n'); + } + this._only = name; +}; + Results.prototype._watch = function (t) { var self = this; - var write = function (s) { self.stream.queue(s) }; + var write = function (s) { self._stream.queue(s) }; t.once('prerun', function () { write('# ' + t.name + '\n'); }); @@ -70,9 +80,9 @@ Results.prototype._watch = function (t) { Results.prototype.close = function () { var self = this; - if (self.closed) self.stream.emit('error', new Error('ALREADY CLOSED')); + if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED')); self.closed = true; - var write = function (s) { self.stream.queue(s) }; + var write = function (s) { self._stream.queue(s) }; write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); @@ -80,7 +90,7 @@ Results.prototype.close = function () { if (self.fail) write('# fail ' + self.fail + '\n') else write('\n# ok\n') - self.stream.queue(null); + self._stream.queue(null); }; function encodeResult (res, count) { @@ -148,7 +158,7 @@ function getSerialize () { } function getNextTest(results) { - if (!results.only) { + if (!results._only) { return results.tests.shift(); } @@ -157,7 +167,7 @@ function getNextTest(results) { if (!t) { return null; } - if (results.only === t.name) { + if (results._only === t.name) { return t; } } while (results.tests.length !== 0) diff --git a/package.json b/package.json index 92247b69..c315dcfc 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "defined" : "~0.0.0", "through": "~2.3.4", "stream-combiner": "~0.0.2", - "split": "~0.2.10" + "split": "~0.2.10", + "inherits": "~2.0.1" }, "devDependencies" : { "tap" : "~0.3.0", From 9ab2e1f9c780414eb4f3dcec457c9e22090f256b Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 16:08:27 +0800 Subject: [PATCH 025/373] 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c315dcfc..6e07697c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.1.0", + "version" : "2.2.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 9882d3499d3157a230bccebd9476202a04b37c0e Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 16:12:54 +0800 Subject: [PATCH 026/373] forgot the resumer dep --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e07697c..2411a39d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.2.0", + "version" : "2.2.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", @@ -13,6 +13,7 @@ "deep-equal" : "~0.1.0", "defined" : "~0.0.0", "through": "~2.3.4", + "resumer": "~0.0.0", "stream-combiner": "~0.0.2", "split": "~0.2.10", "inherits": "~2.0.1" From 158969558f9d1376344a15ba6bb590cae41609a7 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 17:32:03 +0800 Subject: [PATCH 027/373] suppress EPIPE but set the exit code to 1 so test results may be piped around to head/grep/tail --- index.js | 9 ++++++++- lib/default_stream.js | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b8f0b563..007733fc 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,10 @@ function createExitHarness (conf) { }); var stream = harness.createStream(); - stream.pipe(createDefaultStream()); + var es = stream.pipe(createDefaultStream()); + if (canEmitExit) { + es.on('error', function (err) { harness._exitCode = 1 }); + } var ended = false; stream.on('end', function () { ended = true }); @@ -54,6 +57,9 @@ function createExitHarness (conf) { var _error; process.on('uncaughtException', function (err) { + if (err && err.code === 'EPIPE' && err.errno === 'EPIPE' + && err.syscall === 'write') return; + _error = err throw err @@ -73,6 +79,7 @@ function createExitHarness (conf) { harness.close(); process.exit(code || harness._exitCode); }); + return harness; } diff --git a/lib/default_stream.js b/lib/default_stream.js index be4fa4bd..6cf4bc82 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -3,9 +3,11 @@ var combine = require('stream-combiner'); var split = require('split'); module.exports = function () { - return combine(split(), through(write)); + var stream = combine(split(), through(write)); + return stream; function write (line) { - console.log(line); + try { console.log(line); } + catch (e) { stream.emit('error', e) } } }; From 9b8a7719122f2c921761ad6a75e17cd1832c1c40 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 22 Nov 2013 17:32:13 +0800 Subject: [PATCH 028/373] 2.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2411a39d..5fdbe2a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.2.1", + "version" : "2.3.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From ea562557b7598c13ce498a64d47b299e967d04bc Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 17 Dec 2013 14:16:50 -0800 Subject: [PATCH 029/373] drop split and stream-combiner to make the default stream not drop newlines in ie<9 --- lib/default_stream.js | 20 +++++++++++++++----- package.json | 2 -- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index 6cf4bc82..42e8d390 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -1,13 +1,23 @@ var through = require('through'); -var combine = require('stream-combiner'); -var split = require('split'); module.exports = function () { - var stream = combine(split(), through(write)); - return stream; + var line = ''; + return through(write, flush); - function write (line) { + 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 () { try { console.log(line); } catch (e) { stream.emit('error', e) } + line = ''; } }; diff --git a/package.json b/package.json index 5fdbe2a2..348c7a5b 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,6 @@ "defined" : "~0.0.0", "through": "~2.3.4", "resumer": "~0.0.0", - "stream-combiner": "~0.0.2", - "split": "~0.2.10", "inherits": "~2.0.1" }, "devDependencies" : { From 871cc2b781f79810a7badc18469fe436c4b2b9c0 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 17 Dec 2013 14:17:01 -0800 Subject: [PATCH 030/373] 2.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 348c7a5b..9fecd201 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.3.0", + "version" : "2.3.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 00af8ed795202356b172fcd8b48b8d64037397c4 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 17 Dec 2013 15:48:31 -0800 Subject: [PATCH 031/373] fix to define the stream so it can emit errors --- lib/default_stream.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index 42e8d390..a267dde3 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -2,7 +2,8 @@ var through = require('through'); module.exports = function () { var line = ''; - return through(write, flush); + var stream = through(write, flush); + return stream; function write (buf) { for (var i = 0; i < buf.length; i++) { From 44748e46a005c334bcb216113c9a13b05219698a Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 17 Dec 2013 15:48:41 -0800 Subject: [PATCH 032/373] 2.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fecd201..36d44e32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.3.1", + "version" : "2.3.2", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From fe3fe9648ab5fef5e0a8e2c76e1cb2d378667d1e Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 17 Dec 2013 15:55:10 -0800 Subject: [PATCH 033/373] remove the browser compat section since there is already a giant testling badge --- readme.markdown | 6 ------ 1 file changed, 6 deletions(-) diff --git a/readme.markdown b/readme.markdown index 800da36a..1bfdcc3d 100644 --- a/readme.markdown +++ b/readme.markdown @@ -8,12 +8,6 @@ tap-producing test harness for node and browsers ![tape](http://substack.net/images/tape_drive.png) -# browser compatibility - -chrome, firefox, opera, safari, IE6, IE7, IE8, IE9 - -using browserify@1.16.5 - # example ``` js From 97fede5b5cc1746a53c15d26d75a6c3381a6f32b Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 19 Dec 2013 18:59:17 -0800 Subject: [PATCH 034/373] drop require stream --- lib/results.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/results.js b/lib/results.js index d8ba3f07..da6220d9 100644 --- a/lib/results.js +++ b/lib/results.js @@ -1,4 +1,3 @@ -var Stream = require('stream'); var EventEmitter = require('events').EventEmitter; var inherits = require('inherits'); var json = typeof JSON === 'object' ? JSON : require('jsonify'); From dcf6b46b1cadfebea25ef34f26719734349b742d Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 29 Jan 2014 14:22:08 -0800 Subject: [PATCH 035/373] upgrade deep-equal to 0.2.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 36d44e32..e1495d9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.3.2", + "version" : "2.4.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", @@ -10,7 +10,7 @@ }, "dependencies" : { "jsonify" : "~0.0.0", - "deep-equal" : "~0.1.0", + "deep-equal" : "~0.2.0", "defined" : "~0.0.0", "through": "~2.3.4", "resumer": "~0.0.0", From 04f37515d27b0ce846f108f72930da28b45a6100 Mon Sep 17 00:00:00 2001 From: Damon Oehlman Date: Thu, 2 May 2013 14:09:41 +1000 Subject: [PATCH 036/373] should throw --> should not throw for the doesNotThrow assertion --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 9d03a887..614b67d7 100644 --- a/lib/test.js +++ b/lib/test.js @@ -413,7 +413,7 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { caught = { error : err }; } this._assert(!caught, { - message : defined(msg, 'should throw'), + message : defined(msg, 'should not throw'), operator : 'throws', actual : caught && caught.error, expected : expected, From 7fe6486ed3a57dd5cc0768afeeff7de648a07cfd Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 31 Jan 2014 18:56:22 -0800 Subject: [PATCH 037/373] 2.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e1495d9f..f4bd05b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.4.0", + "version" : "2.4.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 3b0552657177cd56635b19b135021342d4fecb2c Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Sat, 1 Feb 2014 10:16:20 -0500 Subject: [PATCH 038/373] Reduce stack size. --- lib/results.js | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/results.js b/lib/results.js index da6220d9..b0a09cf3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -24,14 +24,17 @@ Results.prototype.createStream = function () { var self = this; var output = resumer(); output.queue('TAP version 13\n'); - - nextTick(function () { - var t = getNextTest(self); - if (t) t.run() - else self.emit('done') + + nextTick(function next() { + var t; + while (t = getNextTest(self)) { + t.run(); + if (!t.ended) return t.once('end', function(){ nextTick(next); }); + } + self.emit('done'); }); self._stream.pipe(output); - + return output; }; @@ -39,11 +42,6 @@ Results.prototype.push = function (t) { var self = this; self.tests.push(t); self._watch(t); - t.once('end', function () { - var nt = getNextTest(self); - if (nt) nt.run() - else self.emit('done') - }); }; Results.prototype.only = function (name) { @@ -69,7 +67,7 @@ Results.prototype._watch = function (t) { } write(encodeResult(res, self.count + 1)); self.count ++; - + if (res.ok) self.pass ++ else self.fail ++ }); @@ -82,13 +80,13 @@ Results.prototype.close = function () { 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 + '\n'); if (self.fail) write('# fail ' + self.fail + '\n') else write('\n# ok\n') - + self._stream.queue(null); }; @@ -96,21 +94,21 @@ function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; - + if (res.skip) output += ' # SKIP'; else if (res.todo) output += ' # TODO'; - + output += '\n'; if (res.ok) return output; - + var outer = ' '; var inner = outer + ' '; output += outer + '---\n'; output += inner + 'operator: ' + res.operator + '\n'; - + var ex = json.stringify(res.expected, getSerialize()) || ''; var ac = json.stringify(res.actual, getSerialize()) || ''; - + if (Math.max(ex.length, ac.length) > 65) { output += inner + 'expected:\n' + inner + ' ' + ex + '\n'; output += inner + 'actual:\n' + inner + ' ' + ac + '\n'; @@ -130,14 +128,14 @@ function encodeResult (res, count) { output += inner + lines[i] + '\n'; } } - + output += outer + '...\n'; return output; } function getSerialize () { var seen = []; - + return function (key, value) { var ret = value; if (typeof value === 'object' && value) { @@ -148,7 +146,7 @@ function getSerialize () { break; } } - + if (found) ret = '[Circular]' else seen.push(value) } From 52f3541e8610af4534997ace0339b417434d2e66 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 1 Feb 2014 11:28:08 -0800 Subject: [PATCH 039/373] re-indent. Fuck whichever editor does this by default. --- lib/results.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/results.js b/lib/results.js index b0a09cf3..e626716a 100644 --- a/lib/results.js +++ b/lib/results.js @@ -24,7 +24,7 @@ Results.prototype.createStream = function () { var self = this; var output = resumer(); output.queue('TAP version 13\n'); - + nextTick(function next() { var t; while (t = getNextTest(self)) { @@ -34,7 +34,7 @@ Results.prototype.createStream = function () { self.emit('done'); }); self._stream.pipe(output); - + return output; }; @@ -59,7 +59,7 @@ Results.prototype._watch = function (t) { t.once('prerun', function () { write('# ' + t.name + '\n'); }); - + t.on('result', function (res) { if (typeof res === 'string') { write('# ' + res + '\n'); @@ -71,7 +71,7 @@ Results.prototype._watch = function (t) { if (res.ok) self.pass ++ else self.fail ++ }); - + t.on('test', function (st) { self._watch(st) }); }; @@ -80,7 +80,7 @@ Results.prototype.close = function () { 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 + '\n'); @@ -94,21 +94,21 @@ function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; - + if (res.skip) output += ' # SKIP'; else if (res.todo) output += ' # TODO'; - + output += '\n'; if (res.ok) return output; - + var outer = ' '; var inner = outer + ' '; output += outer + '---\n'; output += inner + 'operator: ' + res.operator + '\n'; - + var ex = json.stringify(res.expected, getSerialize()) || ''; var ac = json.stringify(res.actual, getSerialize()) || ''; - + if (Math.max(ex.length, ac.length) > 65) { output += inner + 'expected:\n' + inner + ' ' + ex + '\n'; output += inner + 'actual:\n' + inner + ' ' + ac + '\n'; @@ -128,14 +128,14 @@ function encodeResult (res, count) { output += inner + lines[i] + '\n'; } } - + output += outer + '...\n'; return output; } function getSerialize () { var seen = []; - + return function (key, value) { var ret = value; if (typeof value === 'object' && value) { @@ -146,7 +146,7 @@ function getSerialize () { break; } } - + if (found) ret = '[Circular]' else seen.push(value) } @@ -158,7 +158,7 @@ function getNextTest(results) { if (!results._only) { return results.tests.shift(); } - + do { var t = results.tests.shift(); if (!t) { From 46c15beacbca83b3079a1f3f48e79d1d0d43e474 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 1 Feb 2014 11:31:48 -0800 Subject: [PATCH 040/373] 2.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4bd05b7..b03ed1bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.4.1", + "version" : "2.4.2", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 61df434423785afa8597c8dba1df80cded0f6139 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Wed, 5 Feb 2014 16:44:53 -0500 Subject: [PATCH 041/373] Fixes #55 - Callback optional. --- lib/test.js | 3 ++- test/no_callback.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/no_callback.js diff --git a/lib/test.js b/lib/test.js index 614b67d7..c9a9c94f 100644 --- a/lib/test.js +++ b/lib/test.js @@ -50,7 +50,8 @@ Test.prototype.run = function () { } this.emit('prerun'); try { - this._cb(this); + if (this._cb) this._cb(this); + else this.end(); } catch (err) { this.error(err); diff --git a/test/no_callback.js b/test/no_callback.js new file mode 100644 index 00000000..760ff26c --- /dev/null +++ b/test/no_callback.js @@ -0,0 +1,3 @@ +var test = require('../'); + +test('No callback.'); From 9f7a2d0516d316e9128abbb737376f59c7dae647 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Thu, 6 Feb 2014 20:48:36 -0500 Subject: [PATCH 042/373] No callback is equivalent to skipping. --- lib/test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index c9a9c94f..ee4f7ff2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -45,13 +45,12 @@ function Test (name_, opts_, cb_) { } Test.prototype.run = function () { - if (this._skip) { + if (!this._cb || this._skip) { return this.end(); } this.emit('prerun'); try { - if (this._cb) this._cb(this); - else this.end(); + this._cb(this); } catch (err) { this.error(err); From de036338fa9bff931637a303208590ae708bc079 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 20 Feb 2014 22:19:00 -0800 Subject: [PATCH 043/373] 2.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b03ed1bd..6956aca6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.4.2", + "version" : "2.5.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 3f25f795f8165ee0dbe7288a29ee7403e65f55dc Mon Sep 17 00:00:00 2001 From: James Hiscock Date: Tue, 25 Feb 2014 08:04:44 +1100 Subject: [PATCH 044/373] Clarify how to access the output stream Fixes #63 --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 1bfdcc3d..cf380ccf 100644 --- a/readme.markdown +++ b/readme.markdown @@ -172,7 +172,7 @@ a new pending stack and test state. By default the TAP output goes to `process.stdout` or `console.log()` if the environment doesn't have `process.stdout`. You can pipe the output to someplace -else if you `test.stream.pipe()` to a destination stream on the first tick. +else if you `htest.createStream().pipe()` to a destination stream on the first tick. ## test.only(name, cb) From 5d2cd6319dc33696b874c9908d28eab195eff675 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:14:43 -0800 Subject: [PATCH 045/373] .createStream() for tap output on the default harness --- index.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 007733fc..def1a55c 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var defined = require('defined'); var createDefaultStream = require('./lib/default_stream'); var Test = require('./lib/test'); var createResult = require('./lib/results'); +var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process && typeof process.on === 'function' @@ -18,22 +19,30 @@ var nextTick = typeof setImmediate !== 'undefined' exports = module.exports = (function () { var harness; var lazyLoad = function () { - if (!harness) harness = createExitHarness({ - autoclose: !canEmitExit - }); - - return harness.apply(this, arguments); + return getHarness().apply(this, arguments); }; - + lazyLoad.only = function () { - if (!harness) harness = createExitHarness({ - autoclose: !canEmitExit - }); - - return harness.only.apply(this, arguments); + return getHarness.only.apply(this, arguments); } - + + lazyLoad.createStream = function () { + if (!harness) { + var output = through(); + getHarness({ stream: output }); + return output; + } + return harness.createStream(); + }; + return lazyLoad + + function getHarness (opts) { + if (!opts) opts = {}; + opts.autoclose = !canEmitExit; + if (!harness) harness = createExitHarness(opts); + return harness; + } })(); function createExitHarness (conf) { @@ -43,7 +52,7 @@ function createExitHarness (conf) { }); var stream = harness.createStream(); - var es = stream.pipe(createDefaultStream()); + var es = stream.pipe(conf.stream || createDefaultStream()); if (canEmitExit) { es.on('error', function (err) { harness._exitCode = 1 }); } From 26c05e33e7a2ee4e157f6049ed6ee712cbe3da6a Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:39:41 -0800 Subject: [PATCH 046/373] objectMode for stream output --- index.js | 13 +++++++------ lib/results.js | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index def1a55c..2528dfef 100644 --- a/index.js +++ b/index.js @@ -26,13 +26,14 @@ exports = module.exports = (function () { return getHarness.only.apply(this, arguments); } - lazyLoad.createStream = function () { + lazyLoad.createStream = function (opts) { + if (!opts) opts = {}; if (!harness) { var output = through(); - getHarness({ stream: output }); + getHarness({ stream: output, objectMode: opts.objectMode }); return output; } - return harness.createStream(); + return harness.createStream(opts); }; return lazyLoad @@ -51,7 +52,7 @@ function createExitHarness (conf) { autoclose: defined(conf.autoclose, false) }); - var stream = harness.createStream(); + var stream = harness.createStream({ objectMode: conf.objectMode }); var es = stream.pipe(conf.stream || createDefaultStream()); if (canEmitExit) { es.on('error', function (err) { harness._exitCode = 1 }); @@ -124,8 +125,8 @@ function createHarness (conf_) { test._tests = []; - test.createStream = function () { - return results.createStream(); + test.createStream = function (opts) { + return results.createStream(opts); }; var only = false; diff --git a/lib/results.js b/lib/results.js index e626716a..9555e9f1 100644 --- a/lib/results.js +++ b/lib/results.js @@ -20,10 +20,43 @@ function Results () { this.tests = []; } -Results.prototype.createStream = function () { +Results.prototype.createStream = function (opts) { + if (!opts) opts = {}; var self = this; - var output = resumer(); - output.queue('TAP version 13\n'); + var output, testId = 0; + if (opts.objectMode) { + output = through(); + self.on('_push', function ontest (t, extra) { + if (!extra) extra = {}; + var id = testId++; + var row = { + type: 'test', + name: t.name, + id: id + }; + if (extra.parent) { + row.parent = extra.parent; + } + output.queue(row); + t.on('test', function (st) { + ontest(st, { parent: id }); + }); + t.on('result', function (res) { + 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); + } nextTick(function next() { var t; @@ -33,7 +66,6 @@ Results.prototype.createStream = function () { } self.emit('done'); }); - self._stream.pipe(output); return output; }; @@ -42,6 +74,7 @@ Results.prototype.push = function (t) { var self = this; self.tests.push(t); self._watch(t); + self.emit('_push', t); }; Results.prototype.only = function (name) { @@ -154,7 +187,7 @@ function getSerialize () { }; } -function getNextTest(results) { +function getNextTest (results) { if (!results._only) { return results.tests.shift(); } From 47848f2dd52f09b4cc0752b87d15529590517d69 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:41:22 -0800 Subject: [PATCH 047/373] stream example --- example/stream/object.js | 10 ++++++++++ example/stream/tap.js | 8 ++++++++ example/stream/test/x.js | 5 +++++ example/stream/test/y.js | 11 +++++++++++ 4 files changed, 34 insertions(+) create mode 100644 example/stream/object.js create mode 100644 example/stream/tap.js create mode 100644 example/stream/test/x.js create mode 100644 example/stream/test/y.js diff --git a/example/stream/object.js b/example/stream/object.js new file mode 100644 index 00000000..40c5841f --- /dev/null +++ b/example/stream/object.js @@ -0,0 +1,10 @@ +var test = require('../../'); +var path = require('path'); +var fs = require('fs'); +test.createStream({ objectMode: true }).on('data', function (row) { + console.log(JSON.stringify(row)) +}); + +process.argv.slice(2).forEach(function (file) { + require(path.resolve(file)); +}); diff --git a/example/stream/tap.js b/example/stream/tap.js new file mode 100644 index 00000000..cb6f81b8 --- /dev/null +++ b/example/stream/tap.js @@ -0,0 +1,8 @@ +var test = require('../../'); +var path = require('path'); +var fs = require('fs'); +test.createStream().pipe(process.stdout); + +process.argv.slice(2).forEach(function (file) { + require(path.resolve(file)); +}); diff --git a/example/stream/test/x.js b/example/stream/test/x.js new file mode 100644 index 00000000..7dbb98ad --- /dev/null +++ b/example/stream/test/x.js @@ -0,0 +1,5 @@ +var test = require('../../../'); +test(function (t) { + t.plan(1); + t.equal('beep', 'boop'); +}); diff --git a/example/stream/test/y.js b/example/stream/test/y.js new file mode 100644 index 00000000..28606d51 --- /dev/null +++ b/example/stream/test/y.js @@ -0,0 +1,11 @@ +var test = require('../../../'); +test(function (t) { + t.plan(2); + t.equal(1+1, 2); + t.ok(true); +}); + +test('wheee', function (t) { + t.ok(true); + t.end(); +}); From 9da8dff8670f73f8a57fa636947aea3b687a9edd Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:51:29 -0800 Subject: [PATCH 048/373] only render the test events right before they begin --- lib/results.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/results.js b/lib/results.js index 9555e9f1..b357b81f 100644 --- a/lib/results.js +++ b/lib/results.js @@ -29,15 +29,17 @@ Results.prototype.createStream = function (opts) { self.on('_push', function ontest (t, extra) { if (!extra) extra = {}; var id = testId++; - var row = { - type: 'test', - name: t.name, - id: id - }; - if (extra.parent) { - row.parent = extra.parent; - } - output.queue(row); + t.once('prerun', function () { + var row = { + type: 'test', + name: t.name, + id: id + }; + if (extra.parent) { + row.parent = extra.parent; + } + output.queue(row); + }); t.on('test', function (st) { ontest(st, { parent: id }); }); From 75728289fa5e3b00103662e820cb1319c4cef2ef Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:52:18 -0800 Subject: [PATCH 049/373] documented custom reporters --- example/stream/object.js | 2 +- example/stream/tap.js | 2 +- readme.markdown | 82 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/example/stream/object.js b/example/stream/object.js index 40c5841f..8f77f0f1 100644 --- a/example/stream/object.js +++ b/example/stream/object.js @@ -1,6 +1,6 @@ var test = require('../../'); var path = require('path'); -var fs = require('fs'); + test.createStream({ objectMode: true }).on('data', function (row) { console.log(JSON.stringify(row)) }); diff --git a/example/stream/tap.js b/example/stream/tap.js index cb6f81b8..9ea9ff74 100644 --- a/example/stream/tap.js +++ b/example/stream/tap.js @@ -1,6 +1,6 @@ var test = require('../../'); var path = require('path'); -var fs = require('fs'); + test.createStream().pipe(process.stdout); process.argv.slice(2).forEach(function (file) { diff --git a/readme.markdown b/readme.markdown index 1bfdcc3d..62584e35 100644 --- a/readme.markdown +++ b/readme.markdown @@ -180,6 +180,88 @@ Like `test(name, cb)` except if you use `.only` this is the only test case that will run for the entire process, all other test cases using tape will be ignored +## var stream = test.createStream(opts) + +Create a stream of output, bypassing the default output stream that writes +messages to `console.log()`. By default `stream` will be a text stream of TAP +output, but you can get an object stream instead by setting `opts.objectMode` to +`true`. + +### tap stream reporter + +You can create your own custom test reporter using this `createStream()` api: + +``` js +var test = require('tape'); +var path = require('path'); + +test.createStream().pipe(process.stdout); + +process.argv.slice(2).forEach(function (file) { + require(path.resolve(file)); +}); +``` + +You could substitute `process.stdout` for whatever other output stream you want, +like a network connection or a file. + +Pass in test files to run as arguments: + +``` +$ node tap.js test/x.js test/y.js +TAP version 13 +# (anonymous) +not ok 1 should be equal + --- + operator: equal + expected: "boop" + actual: "beep" + ... +# (anonymous) +ok 2 should be equal +ok 3 (unnamed assert) +# wheee +ok 4 (unnamed assert) + +1..4 +# tests 4 +# pass 3 +# fail 1 +``` + +### object stream reporter + +Here's how you can render an object stream instead of TAP: + +``` js +var test = require('tape'); +var path = require('path'); + +test.createStream({ objectMode: true }).on('data', function (row) { + console.log(JSON.stringify(row)) +}); + +process.argv.slice(2).forEach(function (file) { + require(path.resolve(file)); +}); +``` + +The output for this runner is: + +``` +$ node object.js test/x.js test/y.js +{"type":"test","name":"(anonymous)","id":0} +{"id":0,"ok":false,"name":"should be equal","operator":"equal","actual":"beep","expected":"boop","error":{},"test":0,"type":"assert"} +{"type":"end","test":0} +{"type":"test","name":"(anonymous)","id":1} +{"id":0,"ok":true,"name":"should be equal","operator":"equal","actual":2,"expected":2,"test":1,"type":"assert"} +{"id":1,"ok":true,"name":"(unnamed assert)","operator":"ok","actual":true,"expected":true,"test":1,"type":"assert"} +{"type":"end","test":1} +{"type":"test","name":"wheee","id":2} +{"id":0,"ok":true,"name":"(unnamed assert)","operator":"ok","actual":true,"expected":true,"test":2,"type":"assert"} +{"type":"end","test":2} +``` + # install With [npm](https://npmjs.org) do: From dfc13b846405723407160712b84b74b191c5cb90 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 17:52:42 -0800 Subject: [PATCH 050/373] 2.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6956aca6..a963142b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.5.0", + "version" : "2.6.0", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 984b21fbbb5b3bf2c1a1cfc2fea33894ec042619 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Mar 2014 18:00:36 -0800 Subject: [PATCH 051/373] update docs --- readme.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.markdown b/readme.markdown index 99058ba4..551d52a0 100644 --- a/readme.markdown +++ b/readme.markdown @@ -170,9 +170,9 @@ after `t` will not be run until all subtests finish. Create a new test harness instance, which is a function like `test()`, but with a new pending stack and test state. -By default the TAP output goes to `process.stdout` or `console.log()` if the -environment doesn't have `process.stdout`. You can pipe the output to someplace -else if you `htest.createStream().pipe()` to a destination stream on the first tick. +By default the TAP output goes to `console.log()`. You can pipe the output to +someplace else if you `htest.createStream().pipe()` to a destination stream on +the first tick. ## test.only(name, cb) From 9ee84219bde718af19cdd7f14d268fd59530c024 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:09:35 -0800 Subject: [PATCH 052/373] failing undef test --- test/undef.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/undef.js diff --git a/test/undef.js b/test/undef.js new file mode 100644 index 00000000..e856a54b --- /dev/null +++ b/test/undef.js @@ -0,0 +1,32 @@ +var tape = require('../'); +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 (body) { + tt.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# undef\n' + + 'not ok 1 should be equivalent\n' + + ' ---\n' + + ' operator: deepEqual\n' + + ' expected: { beep: undefined }\n' + + ' actual: {}\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + })); + + test('undef', function (t) { + t.plan(1); + t.deepEqual({}, { beep: undefined }); + }); +}); From 49963b3d1abf71e72a4a71f40c271bc9afe13d78 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:11:44 -0800 Subject: [PATCH 053/373] using object-inspect for comparisons, passing the undef test --- lib/results.js | 27 ++-------- package.json | 108 ++++++++++++++++++++-------------------- test/circular-things.js | 2 +- 3 files changed, 59 insertions(+), 78 deletions(-) diff --git a/lib/results.js b/lib/results.js index b357b81f..c89157fb 100644 --- a/lib/results.js +++ b/lib/results.js @@ -1,8 +1,8 @@ var EventEmitter = require('events').EventEmitter; var inherits = require('inherits'); -var json = typeof JSON === 'object' ? JSON : require('jsonify'); var through = require('through'); var resumer = require('resumer'); +var inspect = require('object-inspect'); var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick @@ -141,8 +141,8 @@ function encodeResult (res, count) { output += outer + '---\n'; output += inner + 'operator: ' + res.operator + '\n'; - var ex = json.stringify(res.expected, getSerialize()) || ''; - var ac = json.stringify(res.actual, getSerialize()) || ''; + var ex = inspect(res.expected); + var ac = inspect(res.actual); if (Math.max(ex.length, ac.length) > 65) { output += inner + 'expected:\n' + inner + ' ' + ex + '\n'; @@ -168,27 +168,6 @@ function encodeResult (res, count) { return output; } -function getSerialize () { - var seen = []; - - return function (key, value) { - var ret = value; - if (typeof value === 'object' && value) { - var found = false; - for (var i = 0; i < seen.length; i++) { - if (seen[i] === value) { - found = true - break; - } - } - - if (found) ret = '[Circular]' - else seen.push(value) - } - return ret; - }; -} - function getNextTest (results) { if (!results._only) { return results.tests.shift(); diff --git a/package.json b/package.json index a963142b..1b113517 100644 --- a/package.json +++ b/package.json @@ -1,55 +1,57 @@ { - "name" : "tape", - "version" : "2.6.0", - "description" : "tap-producing test harness for node and browsers", - "main" : "index.js", - "bin" : "./bin/tape", - "directories" : { - "example" : "example", - "test" : "test" - }, - "dependencies" : { - "jsonify" : "~0.0.0", - "deep-equal" : "~0.2.0", - "defined" : "~0.0.0", - "through": "~2.3.4", - "resumer": "~0.0.0", - "inherits": "~2.0.1" - }, - "devDependencies" : { - "tap" : "~0.3.0", - "falafel" : "~0.1.4" - }, - "scripts" : { - "test" : "tap test/*.js" - }, - "testling" : { - "files" : "test/browser/*.js", - "browsers" : [ - "ie/6..latest", - "chrome/20..latest", - "firefox/10..latest", - "safari/latest", - "opera/11.0..latest", - "iphone/6", "ipad/6" - ] - }, - "repository" : { - "type" : "git", - "url" : "git://github.com/substack/tape.git" - }, - "homepage" : "https://github.com/substack/tape", - "keywords" : [ - "tap", - "test", - "harness", - "assert", - "browser" - ], - "author" : { - "name" : "James Halliday", - "email" : "mail@substack.net", - "url" : "http://substack.net" - }, - "license" : "MIT" + "name": "tape", + "version": "2.6.0", + "description": "tap-producing test harness for node and browsers", + "main": "index.js", + "bin": "./bin/tape", + "directories": { + "example": "example", + "test": "test" + }, + "dependencies": { + "deep-equal": "~0.2.0", + "defined": "~0.0.0", + "inherits": "~2.0.1", + "object-inspect": "~0.3.0", + "resumer": "~0.0.0", + "through": "~2.3.4" + }, + "devDependencies": { + "tap": "~0.3.0", + "concat": "~1.4.1", + "falafel": "~0.1.4" + }, + "scripts": { + "test": "tap test/*.js" + }, + "testling": { + "files": "test/browser/*.js", + "browsers": [ + "ie/6..latest", + "chrome/20..latest", + "firefox/10..latest", + "safari/latest", + "opera/11.0..latest", + "iphone/6", + "ipad/6" + ] + }, + "repository": { + "type": "git", + "url": "git://github.com/substack/tape.git" + }, + "homepage": "https://github.com/substack/tape", + "keywords": [ + "tap", + "test", + "harness", + "assert", + "browser" + ], + "author": { + "name": "James Halliday", + "email": "mail@substack.net", + "url": "http://substack.net" + }, + "license": "MIT" } diff --git a/test/circular-things.js b/test/circular-things.js index 4ff4fece..1a0368d6 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -20,7 +20,7 @@ tap.test('circular test', function (assert) { , name: " should be equal" , operator: "equal" , expected: "{}" - , actual: '{"circular":"[Circular]"}' + , actual: '{ circular: [Circular] }' } , "tests 1" , "pass 0" From 1aa0b66f4e294d1a77bf4784d4f815977e1f36d4 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:11:59 -0800 Subject: [PATCH 054/373] 2.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b113517..0d9ae314 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.6.0", + "version": "2.7.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From d5f87c030c8ac1f96ba98d38cdb96f17a79f42cb Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:48:08 -0800 Subject: [PATCH 055/373] fix wrong package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d9ae314..b2d01317 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "devDependencies": { "tap": "~0.3.0", - "concat": "~1.4.1", + "concat-stream": "~1.4.1", "falafel": "~0.1.4" }, "scripts": { From 705daaed2ed1fc90fe2efb387c4cdb447b0e8682 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 17:48:16 -0800 Subject: [PATCH 056/373] 2.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b2d01317..018c81d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.7.0", + "version": "2.7.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 412d16988e47cfce7cba27c94ac2bba70cefc6e3 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 18:50:34 -0800 Subject: [PATCH 057/373] failing test.only test --- test/only2.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/only2.js diff --git a/test/only2.js b/test/only2.js new file mode 100644 index 00000000..fcf4f439 --- /dev/null +++ b/test/only2.js @@ -0,0 +1,9 @@ +var test = require('../'); + +test('only2 test 1', function (t) { + t.end(); +}); + +test.only('only2 test 2', function (t) { + t.end(); +}); From 40cad7d313b9513b6e3ab4a4d4cafbe9c9b94934 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 19:58:19 -0800 Subject: [PATCH 058/373] fix for test.only only2 test --- index.js | 7 +++++-- lib/results.js | 4 +--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2528dfef..18067789 100644 --- a/index.js +++ b/index.js @@ -23,8 +23,8 @@ exports = module.exports = (function () { }; lazyLoad.only = function () { - return getHarness.only.apply(this, arguments); - } + return getHarness().only.apply(this, arguments); + }; lazyLoad.createStream = function (opts) { if (!opts) opts = {}; @@ -81,8 +81,10 @@ function createExitHarness (conf) { } if (!ended) { + var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; + if (only && t.name !== only) continue; t._exit(); } } @@ -122,6 +124,7 @@ function createHarness (conf_) { results.push(t); return t; }; + test._results = results; test._tests = []; diff --git a/lib/results.js b/lib/results.js index c89157fb..ea6d5bf7 100644 --- a/lib/results.js +++ b/lib/results.js @@ -175,9 +175,7 @@ function getNextTest (results) { do { var t = results.tests.shift(); - if (!t) { - return null; - } + if (!t) continue; if (results._only === t.name) { return t; } From ff3c79b51a345f4815bb45182d464e3e8b14f049 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 19:59:08 -0800 Subject: [PATCH 059/373] another only test, passes --- test/only3.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/only3.js diff --git a/test/only3.js b/test/only3.js new file mode 100644 index 00000000..b192a4e0 --- /dev/null +++ b/test/only3.js @@ -0,0 +1,15 @@ +var test = require('../'); + +test('only3 test 1', function (t) { + t.fail('not 1'); + t.end(); +}); + +test.only('only3 test 2', function (t) { + t.end(); +}); + +test('only3 test 3', function (t) { + t.fail('not 3'); + t.end(); +}); From dad32ff7c8f8e5f148e3b1581233ffe1653ae083 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 19:59:22 -0800 Subject: [PATCH 060/373] 2.7.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 018c81d5..2d9af678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.7.1", + "version": "2.7.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 7092104828b58d6ddb409211b1606ee5f42a1236 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 20:13:18 -0800 Subject: [PATCH 061/373] remove .bind(), formatting --- lib/test.js | 18 +++++++---- test/end-as-callback.js | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 test/end-as-callback.js diff --git a/lib/test.js b/lib/test.js index ee4f7ff2..b2330a03 100644 --- a/lib/test.js +++ b/lib/test.js @@ -42,6 +42,9 @@ function Test (name_, opts_, cb_) { this._cb = cb; this._progeny = []; this._ok = true; + this.end = function () { + return Test.prototype.end.apply(self, arguments); + }; } Test.prototype.run = function () { @@ -92,9 +95,12 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; -Test.prototype.end = function () { +Test.prototype.end = function (err) { var self = this; - + if (arguments.length === 1) { + this.ifError(err); + } + if (this._progeny.length) { var t = this._progeny.shift(); t.on('end', function () { @@ -136,11 +142,11 @@ Test.prototype._exit = function () { Test.prototype._pendingAsserts = function () { if (this._plan === undefined) { return 1; - } else { - return this._plan - - (this._progeny.length + this.assertCount); } -} + else { + return this._plan - (this._progeny.length + this.assertCount); + } +}; Test.prototype._assert = function assert (ok, opts) { var self = this; diff --git a/test/end-as-callback.js b/test/end-as-callback.js new file mode 100644 index 00000000..6d24a0c3 --- /dev/null +++ b/test/end-as-callback.js @@ -0,0 +1,66 @@ +var tap = require("tap"); +var tape = require("../"); + +tap.test("tape assert.end as callback", function (tt) { + var test = tape.createHarness({ exit: false }) + var tc = tap.createConsumer() + + var rows = [] + tc.on("data", function (r) { rows.push(r) }) + tc.on("end", function () { + var rs = rows.map(function (r) { + return r && typeof r === "object" ? + { id: r.id, ok: r.ok, name: r.name.trim() } : + r + }) + + tt.deepEqual(rs, [ + "TAP version 13", + "do a task and write", + { id: 1, ok: true, name: "null" }, + { id: 2, ok: true, name: "should be equal" }, + { id: 3, ok: true, name: "null" }, + "do a task and write fail", + { id: 4, ok: true, name: "null" }, + { id: 5, ok: true, name: "should be equal" }, + { id: 6, ok: false, name: "Error: fail" }, + "tests 6", + "pass 5", + "fail 1" + ]) + + tt.end() + }) + + test.createStream().pipe(tc) + + test("do a task and write", function (assert) { + fakeAsyncTask("foo", function (err, value) { + assert.ifError(err) + assert.equal(value, "taskfoo") + + 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") + + fakeAsyncWriteFail("baz", assert.end) + }) + }) +}) + +function fakeAsyncTask(name, cb) { + cb(null, "task" + name) +} + +function fakeAsyncWrite(name, cb) { + cb(null) +} + +function fakeAsyncWriteFail(name, cb) { + cb(new Error("fail")) +} From f8c72eaea5a02bb70d4572d5dd397927c564eb74 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 20:13:31 -0800 Subject: [PATCH 062/373] 2.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d9af678..5730ef21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.7.2", + "version": "2.8.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From c0a9a297abd168d4fa0ae2b29897d30ab532b121 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 20:23:42 -0800 Subject: [PATCH 063/373] failing test for calling .end() twice --- test/double_end.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/double_end.js diff --git a/test/double_end.js b/test/double_end.js new file mode 100644 index 00000000..bc4f8ae7 --- /dev/null +++ b/test/double_end.js @@ -0,0 +1,34 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +tap.test(function (t) { + t.plan(1); + + var test = tape.createHarness(); + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (row) { rows.push(row) }); + tc.on('end', function () { + t.deepEqual(rows, [ + 'TAP version 13', + 'double end', + { id: 1, ok: true, name: 'should be equivalent' }, + { id: 2, ok: false, name: '.end() called twice' }, + 'tests 2', + 'pass 1', + 'fail 1', + ]); + }); + + test.createStream().pipe(tc); + + test('double end', function (tt) { + tt.equal(1 + 1, 2); + tt.end(); + setTimeout(function () { + tt.end(); + }, 5); + }); +}); From 8d25028500e76d49e907fc118dd2a6a9502d7071 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 20:51:01 -0800 Subject: [PATCH 064/373] guard against calling .end() twice --- lib/test.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/test.js b/lib/test.js index b2330a03..fb92893c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -49,7 +49,7 @@ function Test (name_, opts_, cb_) { Test.prototype.run = function () { if (!this._cb || this._skip) { - return this.end(); + return this._end(); } this.emit('prerun'); try { @@ -57,7 +57,7 @@ Test.prototype.run = function () { } catch (err) { this.error(err); - this.end(); + this._end(); return; } this.emit('run'); @@ -75,13 +75,13 @@ Test.prototype.test = function (name, opts, cb) { if (!self._pendingAsserts()) { nextTick(function () { - self.end(); + self._end(); }); } nextTick(function() { if (!self._plan && self.pendingCount == self._progeny.length) { - self.end(); + self._end(); } }); }; @@ -95,16 +95,24 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; -Test.prototype.end = function (err) { +Test.prototype.end = function (err) { var self = this; - if (arguments.length === 1) { + if (arguments.length >= 1) { this.ifError(err); } + if (this.calledEnd) { + this.fail('.end() called twice'); + } + this.calledEnd = true; + this._end(); +}; + +Test.prototype._end = function (err) { if (this._progeny.length) { var t = this._progeny.shift(); t.on('end', function () { - self.end(); + self._end(); }); t.run(); return; @@ -199,10 +207,10 @@ Test.prototype._assert = function assert (ok, opts) { var pendingAsserts = self._pendingAsserts(); if (!pendingAsserts) { if (extra.exiting) { - self.end(); + self._end(); } else { nextTick(function () { - self.end(); + self._end(); }); } } From 45add173cf5ed739fae31a90c64eb3d8b308260e Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:03:20 -0800 Subject: [PATCH 065/373] complete double end test --- test/double_end.js | 53 +++++++++++++++++---------------------- test/double_end/double.js | 9 +++++++ 2 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 test/double_end/double.js diff --git a/test/double_end.js b/test/double_end.js index bc4f8ae7..c405d45e 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -1,34 +1,27 @@ -var tape = require('../'); -var tap = require('tap'); +var test = require('tap').test; var concat = require('concat-stream'); +var spawn = require('child_process').spawn; -tap.test(function (t) { - t.plan(1); - - var test = tape.createHarness(); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (row) { rows.push(row) }); - tc.on('end', function () { - t.deepEqual(rows, [ - 'TAP version 13', - 'double end', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: false, name: '.end() called twice' }, - 'tests 2', - 'pass 1', - 'fail 1', - ]); - }); - - test.createStream().pipe(tc); - - test('double end', function (tt) { - tt.equal(1 + 1, 2); - tt.end(); - setTimeout(function () { - tt.end(); - }, 5); +test(function (t) { + t.plan(2); + var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]); + ps.on('exit', function (code) { + t.equal(code, 1); }); + ps.stdout.pipe(concat(function (body) { + t.equal(body.toString('utf8'), [ + 'TAP version 13', + '# double end', + 'ok 1 should be equal', + 'not ok 2 .end() called twice', + ' ---', + ' operator: fail', + ' ...', + '', + '1..2', + '# tests 2', + '# pass 1', + '# fail 1', + ].join('\n') + '\n\n'); + })); }); diff --git a/test/double_end/double.js b/test/double_end/double.js new file mode 100644 index 00000000..44734824 --- /dev/null +++ b/test/double_end/double.js @@ -0,0 +1,9 @@ +var test = require('../../'); + +test('double end', function (t) { + t.equal(1 + 1, 2); + t.end(); + setTimeout(function () { + t.end(); + }, 5); +}); From b6ac9bf80615ffcda4b9a3a16e8792dee3db1d89 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:05:07 -0800 Subject: [PATCH 066/373] omit expected and actual if there is no actual or expected --- lib/results.js | 26 ++++++++++++++++---------- lib/test.js | 17 ++++++++++++----- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/results.js b/lib/results.js index ea6d5bf7..43b43b2c 100644 --- a/lib/results.js +++ b/lib/results.js @@ -141,16 +141,18 @@ function encodeResult (res, count) { output += outer + '---\n'; output += inner + 'operator: ' + res.operator + '\n'; - var ex = inspect(res.expected); - var ac = inspect(res.actual); - - if (Math.max(ex.length, ac.length) > 65) { - 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 (has(res, 'expected') || has(res, 'actual')) { + var ex = inspect(res.expected); + var ac = inspect(res.actual); + + if (Math.max(ex.length, ac.length) > 65) { + 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'; @@ -181,3 +183,7 @@ function getNextTest (results) { } } while (results.tests.length !== 0) } + +function has (obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} diff --git a/lib/test.js b/lib/test.js index fb92893c..7a0412e7 100644 --- a/lib/test.js +++ b/lib/test.js @@ -109,11 +109,10 @@ Test.prototype.end = function (err) { }; Test.prototype._end = function (err) { + var self = this; if (this._progeny.length) { var t = this._progeny.shift(); - t.on('end', function () { - self._end(); - }); + t.on('end', function () { self._end() }); t.run(); return; } @@ -166,9 +165,13 @@ Test.prototype._assert = function assert (ok, opts) { skip : defined(extra.skip, opts.skip), name : defined(extra.message, opts.message, '(unnamed assert)'), operator : defined(extra.operator, opts.operator), - actual : defined(extra.actual, opts.actual), - expected : defined(extra.expected, opts.expected) }; + 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 = Boolean(this._ok && ok); if (!ok) { @@ -436,4 +439,8 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { }); }; +function has (obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + // vim: set softtabstop=4 shiftwidth=4: From 748117852753b4038f0e3f9a35632319efc32384 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:07:21 -0800 Subject: [PATCH 067/373] 2.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5730ef21..e6e35cb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.8.0", + "version": "2.9.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From db1baf02bc1982fa177e99c39e08fa2224708156 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:13:16 -0800 Subject: [PATCH 068/373] passing nested test --- test/nested2.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/nested2.js diff --git a/test/nested2.js b/test/nested2.js new file mode 100644 index 00000000..58ae8f3d --- /dev/null +++ b/test/nested2.js @@ -0,0 +1,19 @@ +var test = require('../'); + +test(function(t) { + var i = 0 + t.test('setup', function(t) { + process.nextTick(function() { + t.equal(i, 0, 'called once') + i++ + t.end() + }) + }) + + + t.test('teardown', function(t) { + t.end() + }) + + t.end() +}) From e98ead5752c64ea958393fa0782209c978b1f92f Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:24:19 -0800 Subject: [PATCH 069/373] subcount test --- test/subcount.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/subcount.js diff --git a/test/subcount.js b/test/subcount.js new file mode 100644 index 00000000..3a5df3fb --- /dev/null +++ b/test/subcount.js @@ -0,0 +1,14 @@ +var test = require('../'); + +test('parent test', function (t) { + t.plan(2); + t.test('first child', function (t) { + t.plan(1); + t.pass('pass first child'); + }) + + t.test(function (t) { + t.plan(1); + t.pass('pass second child'); + }) +}) From c9da9ff9c446eae438703608e8c02b9a09b60da8 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:29:02 -0800 Subject: [PATCH 070/373] glob files in the runner --- bin/tape | 10 ++++++++-- package.json | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/tape b/bin/tape index 332befe8..500f1b14 100755 --- a/bin/tape +++ b/bin/tape @@ -1,8 +1,14 @@ #!/usr/bin/env node var path = require('path'); -process.argv.slice(2).forEach(function(file) { - require(path.resolve(process.cwd(), file)); +var glob = require('glob'); + +process.argv.slice(2).forEach(function (arg) { + glob(arg, function (err, files) { + files.forEach(function (file) { + require(path.resolve(process.cwd(), file)); + }); + }); }); // vim: ft=javascript diff --git a/package.json b/package.json index e6e35cb0..ba2ac8e1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "deep-equal": "~0.2.0", "defined": "~0.0.0", + "glob": "~3.2.9", "inherits": "~2.0.1", "object-inspect": "~0.3.0", "resumer": "~0.0.0", From f51697f0513ead6b0db5e316c481dc1fe611b8e5 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 21:29:08 -0800 Subject: [PATCH 071/373] 2.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba2ac8e1..e8b9646e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.9.0", + "version": "2.10.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 29437f7805064ef41a7128c92bb6b1c826eb8042 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 22:16:30 -0800 Subject: [PATCH 072/373] merged --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e8b9646e..40f37086 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "through": "~2.3.4" }, "devDependencies": { - "tap": "~0.3.0", - "concat-stream": "~1.4.1", - "falafel": "~0.1.4" + "tap" : "~0.4.8", + "falafel" : "~0.3.1", + "concat-stream": "~1.4.1" }, "scripts": { "test": "tap test/*.js" From b52c1bec8ad3da3c855f89ff3f6a7e20dfddcef0 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 22:16:50 -0800 Subject: [PATCH 073/373] 2.10.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40f37086..88a4401b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.10.0", + "version": "2.10.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 71adf6a50fdc2fc76b81350fd72ffecf574f8777 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 22:18:48 -0800 Subject: [PATCH 074/373] fix trailing comma --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 7a0412e7..9bc5a1df 100644 --- a/lib/test.js +++ b/lib/test.js @@ -164,7 +164,7 @@ Test.prototype._assert = function assert (ok, opts) { ok : Boolean(ok), skip : defined(extra.skip, opts.skip), name : defined(extra.message, opts.message, '(unnamed assert)'), - operator : defined(extra.operator, opts.operator), + operator : defined(extra.operator, opts.operator) }; if (has(opts, 'actual') || has(extra, 'actual')) { res.actual = defined(extra.actual, opts.actual); From 01f320ea8681256a70be5f4d41d54aad37c6d03f Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 4 Mar 2014 22:18:55 -0800 Subject: [PATCH 075/373] 2.10.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88a4401b..5730d422 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.10.1", + "version": "2.10.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 30cd35cbda79bf5c302650dd619327410a0eeae8 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 21 Mar 2014 19:19:40 -0700 Subject: [PATCH 076/373] upgrade object-inspect --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5730d422..ea36c5d9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "defined": "~0.0.0", "glob": "~3.2.9", "inherits": "~2.0.1", - "object-inspect": "~0.3.0", + "object-inspect": "~0.4.0", "resumer": "~0.0.0", "through": "~2.3.4" }, From 2aa91e84af3a29422619e71961d46fd81513ed12 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 21 Mar 2014 19:19:51 -0700 Subject: [PATCH 077/373] 2.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea36c5d9..b9130d21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.10.2", + "version": "2.11.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 88e296ff8179f9f270c0eefdf2f4cacb17c933d4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 23 Mar 2014 17:25:30 -0700 Subject: [PATCH 078/373] Moving the name/opts/cb code out into a reusable internal function. --- lib/test.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9bc5a1df..5ef7e662 100644 --- a/lib/test.js +++ b/lib/test.js @@ -14,12 +14,11 @@ var nextTick = typeof setImmediate !== 'undefined' inherits(Test, EventEmitter); -function Test (name_, opts_, cb_) { - var self = this; +var getTestArgs = function (name_, opts_, cb_) { var name = '(anonymous)'; var opts = {}; var cb; - + for (var i = 0; i < arguments.length; i++) { switch (typeof arguments[i]) { case 'string': @@ -32,14 +31,26 @@ function Test (name_, opts_, cb_) { cb = arguments[i]; } } - + + return { + name: name, + opts: opts, + cb: cb + }; +}; + +function Test (name_, opts_, cb_) { + var self = this; + + var args = getTestArgs(name_, opts_, cb_); + this.readable = true; - this.name = name || '(anonymous)'; + this.name = args.name || '(anonymous)'; this.assertCount = 0; this.pendingCount = 0; - this._skip = opts.skip || false; + this._skip = args.opts.skip || false; this._plan = undefined; - this._cb = cb; + this._cb = args.cb; this._progeny = []; this._ok = true; this.end = function () { From f9aa1856d377fb80ec0b8e955964d562696a6cd6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 23 Mar 2014 17:26:35 -0700 Subject: [PATCH 079/373] Adding Test.skip. --- index.js | 1 + lib/test.js | 6 ++++++ readme.markdown | 4 ++++ test/skip.js | 12 ++++++++++++ 4 files changed, 23 insertions(+) diff --git a/index.js b/index.js index 18067789..da68e81f 100644 --- a/index.js +++ b/index.js @@ -98,6 +98,7 @@ function createExitHarness (conf) { exports.createHarness = createHarness; exports.Test = Test; exports.test = exports; // tap compat +exports.test.skip = Test.skip; var exitInterval; diff --git a/lib/test.js b/lib/test.js index 5ef7e662..94669d7d 100644 --- a/lib/test.js +++ b/lib/test.js @@ -454,4 +454,10 @@ function has (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } +Test.skip = function (name_, _opts, _cb) { + var args = getTestArgs.apply(null, arguments); + args.opts.skip = true; + return Test(args.name, args.opts, args.cb); +}; + // vim: set softtabstop=4 shiftwidth=4: diff --git a/readme.markdown b/readme.markdown index 551d52a0..4f53a0d5 100644 --- a/readme.markdown +++ b/readme.markdown @@ -60,6 +60,10 @@ test object `t` once all preceeding tests have finished. Tests execute serially. If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. +## test.skip(name, cb) + +Generate a new test that will be skipped over. + ## t.plan(n) Declare that `n` assertions should be run. `t.end()` will be called diff --git a/test/skip.js b/test/skip.js index 13dd9cfc..216b6006 100644 --- a/test/skip.js +++ b/test/skip.js @@ -8,6 +8,18 @@ test('do not skip this', { skip: false }, function(t) { }); test('skip this', { skip: true }, function(t) { + t.fail('this should not even run'); + ran++; + t.end(); +}); + +test.skip('skip this too', function(t) { + t.fail('this should not even run'); + ran++; + t.end(); +}); + +test.skip('skip this too', function(t) { t.fail('this should not even run'); t.end(); }); From aae89ee56d2a7b47c6a074c8a8ca7a1b66a7f0a7 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 23 Mar 2014 22:42:09 -0700 Subject: [PATCH 080/373] switches are weird --- lib/test.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/test.js b/lib/test.js index 94669d7d..8b233233 100644 --- a/lib/test.js +++ b/lib/test.js @@ -18,32 +18,28 @@ var getTestArgs = function (name_, opts_, cb_) { var name = '(anonymous)'; var opts = {}; var cb; - + for (var i = 0; i < arguments.length; i++) { - switch (typeof arguments[i]) { - case 'string': - name = arguments[i]; - break; - case 'object': - opts = arguments[i] || opts; - break; - case 'function': - cb = arguments[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 - }; + return { name: name, opts: opts, cb: cb }; }; function Test (name_, opts_, cb_) { var self = this; - + var args = getTestArgs(name_, opts_, cb_); - + this.readable = true; this.name = args.name || '(anonymous)'; this.assertCount = 0; @@ -83,13 +79,13 @@ Test.prototype.test = function (name, opts, cb) { 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(); From 8e7574ecc7ca6b565a7c575188f0f16a9e0e81f6 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 23 Mar 2014 22:42:19 -0700 Subject: [PATCH 081/373] 2.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9130d21..c143137f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.11.0", + "version": "2.12.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 0212262b2c80665486219e92c2ab421aa8907715 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 082/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index da68e81f..0e8855bd 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From ce1fe6c5005f111f5f2cf70b551bf2a70410c9b1 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 29 Mar 2014 22:07:06 -0700 Subject: [PATCH 083/373] 2.12.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c143137f..76f6b83f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.12.0", + "version": "2.12.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 66c0a7d6a48498ae58df7ecc75c4f3cfa39eb08e Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 084/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b39936df..4286014a 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ var Test = require('./lib/test'); var createResultStream = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From deb04f47e02c21ae0abe78a03eed792ce8b6df22 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:00:24 -0700 Subject: [PATCH 085/373] 2.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ae7ab95d..7a5e4640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.0.1", + "version" : "2.0.2", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From c9d502ec3da3971e34e4493593506c17ec466fcf Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 086/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b39936df..4286014a 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ var Test = require('./lib/test'); var createResultStream = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 940444603272565e0829854a76295224d8624c13 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:02:27 -0700 Subject: [PATCH 087/373] 2.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ace1ac11..67c689fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.1.0", + "version" : "2.1.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 87eb6bc455a6d931f5bf0efa0fefb5e710360e10 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 088/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b8f0b563..fb1884ba 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var Test = require('./lib/test'); var createResult = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From ce216d703339cde0c786a65b3c4b8ad764903558 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 089/373] 2.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2411a39d..4acc32da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.2.1", + "version" : "2.2.2", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 59fd1dc6aa4e3c2c399c727b3e9324038dbf87ca Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 090/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 007733fc..d88aaac1 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var Test = require('./lib/test'); var createResult = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 9d63df9975c145365513448f7f5c4981aae0c2fc Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:07:36 -0700 Subject: [PATCH 091/373] 2.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36d44e32..c35c9ba7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.3.2", + "version" : "2.3.3", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From d282191d2657d37cfb8d8e1250dba06744b349e7 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 092/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 007733fc..d88aaac1 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var Test = require('./lib/test'); var createResult = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 3d72979518a76d6d6da85d1d158edffa9381b394 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:09:15 -0700 Subject: [PATCH 093/373] 2.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b03ed1bd..09067fb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.4.2", + "version" : "2.4.3", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 40cf48878991e0d66509e1f36f4c191265c77ea0 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 094/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 007733fc..d88aaac1 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var Test = require('./lib/test'); var createResult = require('./lib/results'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 6a6888d6d93071b9f6e623882e5bea55eba02578 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:10:03 -0700 Subject: [PATCH 095/373] 2.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6956aca6..03a0df99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.5.0", + "version" : "2.5.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From 7164a031b828c0493175867b92e69512f9223867 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 096/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2528dfef..27e3f535 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 17c34bb95080a1a651dec17b71e06b38d08d2115 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:11:15 -0700 Subject: [PATCH 097/373] 2.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a963142b..176f3a72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "tape", - "version" : "2.6.0", + "version" : "2.6.1", "description" : "tap-producing test harness for node and browsers", "main" : "index.js", "bin" : "./bin/tape", From ff3e84f94f1e4b26bab4aabeee2c1f8ed1015684 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 098/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 18067789..1053b8cc 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 3d63e121d15b82d275fa372c42401c2dcf4ad472 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:12:12 -0700 Subject: [PATCH 099/373] 2.7.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d9af678..9630cdee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.7.2", + "version": "2.7.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 0e47a9359b9e6df0d5fd7bc1d17d7d8159b5d218 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 100/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 18067789..1053b8cc 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 2db6c69e89d8773f1e5dca36a9ab299b4c6f9cff Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:13:01 -0700 Subject: [PATCH 101/373] 2.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5730ef21..f3fe2176 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.8.0", + "version": "2.8.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 4f33ae5f9236f9fc8a4f4f88390ae5400de821a7 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 102/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 18067789..1053b8cc 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 87b32e8c13f295df378934215f30c6b1b11a747c Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:14:10 -0700 Subject: [PATCH 103/373] 2.9.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e6e35cb0..d3519056 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.9.0", + "version": "2.9.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From ebdbba6cd9daabd981538646f27fa152f77c2c20 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 104/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 18067789..1053b8cc 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From c181ca5b2bf0bd752e67ac0904d6c4a8f4cbc9ac Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:14:52 -0700 Subject: [PATCH 105/373] 2.10.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5730d422..c40989cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.10.2", + "version": "2.10.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From a28db7eb238f679591d6019a1511b4ebfab8ec39 Mon Sep 17 00:00:00 2001 From: Marcus Berner Date: Sat, 29 Mar 2014 21:37:55 +0100 Subject: [PATCH 106/373] do not set canEmitExit with browserify process shim --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 18067789..1053b8cc 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var createResult = require('./lib/results'); var through = require('through'); var canEmitExit = typeof process !== 'undefined' && process - && typeof process.on === 'function' + && typeof process.on === 'function' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' From 86959302744a19d191976fd1fbda2419dae0e1cc Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:15:30 -0700 Subject: [PATCH 107/373] 2.11.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9130d21..a81890ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.11.0", + "version": "2.11.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 3e20271dbee59823aaed22c8ce5df1a5af1e08db Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 2 Apr 2014 12:16:47 -0700 Subject: [PATCH 108/373] 2.12.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76f6b83f..788d43fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.12.1", + "version": "2.12.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From d39b0ebaa6639d4d9ca568547ef977259d10d465 Mon Sep 17 00:00:00 2001 From: Andrew Petersen Date: Fri, 4 Apr 2014 19:05:53 -0400 Subject: [PATCH 109/373] Remove dependency on util builtin No need just for inherits :) --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 8b233233..b610e212 100644 --- a/lib/test.js +++ b/lib/test.js @@ -2,7 +2,7 @@ var Stream = require('stream'); var deepEqual = require('deep-equal'); var defined = require('defined'); var path = require('path'); -var inherits = require('util').inherits; +var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; module.exports = Test; From 46246e8fe90ba4224f57b507d48fa7bc022e8400 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 4 Apr 2014 17:51:58 -0700 Subject: [PATCH 110/373] 2.12.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 788d43fc..5a8430ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.12.2", + "version": "2.12.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From f9774cc078142081c0133e090723f27cad367534 Mon Sep 17 00:00:00 2001 From: Joshua T Corbin Date: Wed, 14 May 2014 13:42:41 -0700 Subject: [PATCH 111/373] Test that we can call assertion functions directly --- test/bound.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/bound.js diff --git a/test/bound.js b/test/bound.js new file mode 100644 index 00000000..d3981954 --- /dev/null +++ b/test/bound.js @@ -0,0 +1,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(); +}); From 1ca29e26ea7821ed30be982494c3e9d3c3100c06 Mon Sep 17 00:00:00 2001 From: Joshua T Corbin Date: Wed, 14 May 2014 13:31:18 -0700 Subject: [PATCH 112/373] Bind all test methods --- lib/test.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/test.js b/lib/test.js index b610e212..2550a246 100644 --- a/lib/test.js +++ b/lib/test.js @@ -36,10 +36,8 @@ var getTestArgs = function (name_, opts_, cb_) { }; function Test (name_, opts_, cb_) { - var self = this; - var args = getTestArgs(name_, opts_, cb_); - + this.readable = true; this.name = args.name || '(anonymous)'; this.assertCount = 0; @@ -49,9 +47,18 @@ function Test (name_, opts_, cb_) { this._cb = args.cb; this._progeny = []; this._ok = true; - this.end = function () { - return Test.prototype.end.apply(self, arguments); - }; + + for (prop in this) { + this[prop] = (function bind(self, val) { + if (typeof val === 'function') { + return function bound() { + return val.apply(self, arguments); + }; + } else { + return val; + } + })(this, this[prop]); + } } Test.prototype.run = function () { From ba3bcbb8a62194ee79f814ff688065c6041cb0ed Mon Sep 17 00:00:00 2001 From: Joshua T Corbin Date: Wed, 14 May 2014 13:30:04 -0700 Subject: [PATCH 113/373] Fix Test constructor so that it doesn't accidentally mutate global scope As used by Test.skip itself circa lib/test.js:464 --- lib/test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/test.js b/lib/test.js index 2550a246..a8c090b4 100644 --- a/lib/test.js +++ b/lib/test.js @@ -36,6 +36,10 @@ var getTestArgs = function (name_, opts_, 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; From aacd7a90d1ac5f306ffaf66d21884e2cff941408 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 15 May 2014 00:52:03 +0200 Subject: [PATCH 114/373] formatting --- lib/test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index a8c090b4..171eea05 100644 --- a/lib/test.js +++ b/lib/test.js @@ -58,9 +58,8 @@ function Test (name_, opts_, cb_) { return function bound() { return val.apply(self, arguments); }; - } else { - return val; } + else return val; })(this, this[prop]); } } From a9f5302ade18a0f8a79c578e29c599a94cc38287 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 15 May 2014 00:52:21 +0200 Subject: [PATCH 115/373] 2.13.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a8430ae..6c7636e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.12.3", + "version": "2.13.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 14ab9d1ad38bd619a60e60269db66d724f4bd99c Mon Sep 17 00:00:00 2001 From: Matt Esch Date: Fri, 16 May 2014 22:25:58 -0700 Subject: [PATCH 116/373] write sync to stdout --- lib/default_stream.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index a267dde3..0fcbb663 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -1,10 +1,11 @@ var through = require('through'); +var fs = require('fs'); module.exports = function () { 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' @@ -15,9 +16,9 @@ module.exports = function () { else line += c; } } - + function flush () { - try { console.log(line); } + try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e) } line = ''; } From ffcff1e8bce257f0d50cd99906ab96286ea50d35 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 17 May 2014 11:11:20 +0200 Subject: [PATCH 117/373] formatting --- lib/default_stream.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index 0fcbb663..a0a3c7b8 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -5,7 +5,7 @@ module.exports = function () { 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' @@ -16,7 +16,7 @@ module.exports = function () { else line += c; } } - + function flush () { try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e) } From b28520cdd0dad25ddeaecc4660a2797b47ff42bd Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 17 May 2014 11:18:17 +0200 Subject: [PATCH 118/373] test if fs.writeSync is defined and on windows --- lib/default_stream.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index a0a3c7b8..c8e99180 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -18,8 +18,14 @@ module.exports = function () { } function flush () { - try { fs.writeSync(1, line + '\n'); } - catch (e) { stream.emit('error', e) } + if (fs.writeSync && /^win/.test(process.platform)) { + try { fs.writeSync(1, line + '\n'); } + catch (e) { stream.emit('error', e) } + } + else { + try { console.log(line) } + catch (e) { stream.emit('error', e) } + } line = ''; } }; From 14b4eef7b1acfeb73024c6906f96db7095aadde1 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 17 May 2014 11:18:44 +0200 Subject: [PATCH 119/373] 2.13.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c7636e5..6b3930c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.0", + "version": "2.13.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 9579246f09a274747fefbd8b358e94774acb85be Mon Sep 17 00:00:00 2001 From: Alex Maslennikov Date: Mon, 2 Jun 2014 22:03:57 +0200 Subject: [PATCH 120/373] FIX: handling `if (extra.parent)` when parent == 0 --- lib/results.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/results.js b/lib/results.js index 43b43b2c..fa414f47 100644 --- a/lib/results.js +++ b/lib/results.js @@ -35,7 +35,7 @@ Results.prototype.createStream = function (opts) { name: t.name, id: id }; - if (extra.parent) { + if (has(extra, 'parent')) { row.parent = extra.parent; } output.queue(row); From 47163ebcc5329bfe23a0e7213d66669310af2368 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 2 Jun 2014 13:32:18 -0700 Subject: [PATCH 121/373] 2.13.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b3930c8..3e7ac4f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.1", + "version": "2.13.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From ef78c1f9c704a165f80544ea17914c1e8c18c97b Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Wed, 11 Jun 2014 19:08:13 -0700 Subject: [PATCH 122/373] Add a section about reports to the README --- readme.markdown | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/readme.markdown b/readme.markdown index 4f53a0d5..9ef41e93 100644 --- a/readme.markdown +++ b/readme.markdown @@ -43,6 +43,27 @@ not ok 2 should be equal # fail 1 ``` +# pretty reporters + +The default TAP output is good for machines and humans that are robots. + +If you want a more colorful / pretty output there are lots of modules on npm +that will output something pretty if you pipe TAP into them: + + - https://github.com/scottcorgan/tap-spec + - https://github.com/scottcorgan/tap-dot + - https://github.com/substack/faucet + - https://github.com/juliangruber/tap-bail + - https://github.com/kirbysayshi/tap-browser-color + - https://github.com/gummesson/tap-json + - https://github.com/gummesson/tap-min + - https://github.com/calvinmetcalf/tap-nyan + - https://www.npmjs.org/package/tap-pessimist + - https://github.com/toolness/tap-prettify + +To use them, try `node test/index.js | tap-spec` or pipe it into one +of the modules of your choice! + # methods The assertion methods in tape are heavily influenced or copied from the methods From 467ce7a19686fc61aaad9633df64319ec416d61d Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Wed, 11 Jun 2014 20:17:57 -0700 Subject: [PATCH 123/373] add colortape --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index 9ef41e93..d7dc1433 100644 --- a/readme.markdown +++ b/readme.markdown @@ -60,6 +60,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/calvinmetcalf/tap-nyan - https://www.npmjs.org/package/tap-pessimist - https://github.com/toolness/tap-prettify + - https://github.com/shuhei/colortape To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From 390c2c6e5df3a117d3137d9e114b243b75661c95 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 12 Jun 2014 10:42:01 -0700 Subject: [PATCH 124/373] 2.13.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e7ac4f6..d5f07fc1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.2", + "version": "2.13.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 1292b8cf62a87726c6b984f1ba71c1bc947de872 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 19 Jul 2014 18:18:56 -0400 Subject: [PATCH 125/373] Comments should not make exit code incorrect. Fixes #92 --- index.js | 2 +- test/exit.js | 1 + test/exit/ok.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0e8855bd..60ddb153 100644 --- a/index.js +++ b/index.js @@ -118,7 +118,7 @@ function createHarness (conf_) { inspectCode(st_); }); st.on('result', function (r) { - if (!r.ok) test._exitCode = 1 + if (!r.ok && typeof r !== 'string') test._exitCode = 1 }); })(t); diff --git a/test/exit.js b/test/exit.js index 7f7c5d01..8055e5e6 100644 --- a/test/exit.js +++ b/test/exit.js @@ -18,6 +18,7 @@ tap.test('exit ok', function (t) { t.same(rs, [ 'TAP version 13', 'array', + 'hi', { id: 1, ok: true, name: 'should be equivalent' }, { id: 2, ok: true, name: 'should be equivalent' }, { id: 3, ok: true, name: 'should be equivalent' }, diff --git a/test/exit/ok.js b/test/exit/ok.js index a02c7b69..f1068e57 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -2,6 +2,7 @@ var falafel = require('falafel'); var test = require('../../'); test('array', function (t) { + t.comment('hi'); t.plan(5); var src = '(' + function () { From 17894caf61fbaa908bfc625a1119c16ab316afb6 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sat, 19 Jul 2014 18:23:31 -0700 Subject: [PATCH 126/373] 2.13.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5f07fc1..f6e128f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.3", + "version": "2.13.4", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 6ecc842e53a8c25c93323c1f1a41bd4966346041 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 5 Aug 2014 14:06:17 +1200 Subject: [PATCH 127/373] hats, has module --- lib/test.js | 5 +---- package.json | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/test.js b/lib/test.js index 171eea05..e3dda4a1 100644 --- a/lib/test.js +++ b/lib/test.js @@ -4,6 +4,7 @@ var defined = require('defined'); var path = require('path'); var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; +var has = require('has'); module.exports = Test; @@ -456,10 +457,6 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { }); }; -function has (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - Test.skip = function (name_, _opts, _cb) { var args = getTestArgs.apply(null, arguments); args.opts.skip = true; diff --git a/package.json b/package.json index f6e128f8..2897eee4 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,12 @@ "dependencies": { "deep-equal": "~0.2.0", "defined": "~0.0.0", - "glob": "~3.2.9", - "inherits": "~2.0.1", - "object-inspect": "~0.4.0", + "glob": "^3.2.9", + "inherits": "^2.0.1", + "object-inspect": "^1.0.0", "resumer": "~0.0.0", - "through": "~2.3.4" + "through": "^2.3.4", + "has": "~0.0.1" }, "devDependencies": { "tap" : "~0.4.8", From 066542a8a0d7ec4e8c1f3a5aabfba6eb01abf9f9 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 5 Aug 2014 14:06:34 +1200 Subject: [PATCH 128/373] better travis yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index cc4dba29..9672e129 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ language: node_js node_js: - "0.8" - "0.10" +before_install: + - npm install -g npm@~1.4.6 From aa5bd84bd656f270fc59e343b797ea63b4b08390 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 5 Aug 2014 14:06:51 +1200 Subject: [PATCH 129/373] 2.14.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2897eee4..07ac10ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.4", + "version": "2.14.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 8b85ca8eda8f980341351864f548660e8e3f6fc1 Mon Sep 17 00:00:00 2001 From: Andrew de Andrade Date: Thu, 14 Aug 2014 14:55:36 -0700 Subject: [PATCH 130/373] Asynchronously declared nested tests w/ plan() w/o end() --- test/nested-async-plan-noend.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/nested-async-plan-noend.js diff --git a/test/nested-async-plan-noend.js b/test/nested-async-plan-noend.js new file mode 100644 index 00000000..6f8cfdd0 --- /dev/null +++ b/test/nested-async-plan-noend.js @@ -0,0 +1,36 @@ +var test = require('../'); + +test('Harness async test support', function(t) { + t.plan(3); + + t.ok(true, 'sync child A'); + + 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 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); +}); From 51278a29c0f0c04145f93dd2bd5095fed7d549c8 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Wed, 27 Aug 2014 11:53:28 -0400 Subject: [PATCH 131/373] Document that expected must be a RegExp You get silent false positives if you use e.g. TypeError instead of /TypeError/. --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index d7dc1433..f33a5d62 100644 --- a/readme.markdown +++ b/readme.markdown @@ -179,7 +179,7 @@ Aliases: `t.notLooseEqual()`, `t.notLooseEquals()` ## t.throws(fn, expected, msg) -Assert that the function call `fn()` throws an exception. +Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp`. ## t.doesNotThrow(fn, expected, msg) From b74737415c98be5e68fcd28213d86c3e32433a05 Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Mon, 15 Sep 2014 10:29:38 -0700 Subject: [PATCH 132/373] remove try catch --- lib/test.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/test.js b/lib/test.js index 171eea05..48a37dae 100644 --- a/lib/test.js +++ b/lib/test.js @@ -69,14 +69,7 @@ Test.prototype.run = function () { return this._end(); } this.emit('prerun'); - try { - this._cb(this); - } - catch (err) { - this.error(err); - this._end(); - return; - } + this._cb(this); this.emit('run'); }; From 672b8d30f9c528c635ff273bf8e08870e4009a30 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 17 Sep 2014 00:20:58 +0300 Subject: [PATCH 133/373] remove failing throw test --- test/throw.js | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 test/throw.js diff --git a/test/throw.js b/test/throw.js deleted file mode 100644 index 32970b26..00000000 --- a/test/throw.js +++ /dev/null @@ -1,38 +0,0 @@ -var falafel = require('falafel'); -var tape = require('../'); -var tap = require('tap'); - -tap.test('throw test', function (tt) { - tt.plan(1); - - var test = tape.createHarness({ exit : false }); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; - } - else return r; - }); - tt.same(rs, [ - 'TAP version 13', - 'thrower', - { id: 1, ok: true, name: 'should be equal' }, - { id: 2, ok: false, name: 'Error: rawr' }, - 'tests 2', - 'pass 1', - 'fail 1', - ]); - }); - - test.createStream().pipe(tc); - - test('thrower', function (t) { - t.equal(1 + 1, 2); - - throw new Error('rawr'); - }); -}); From 82e8b74de899354eb626e99392cfdb895d2db9ea Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 17 Sep 2014 00:21:10 +0300 Subject: [PATCH 134/373] 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5f07fc1..a2ab89bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.13.3", + "version": "3.0.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 9eb3ecd8a0637d55d120656f64ddc09c18debfac Mon Sep 17 00:00:00 2001 From: Nuno Job Date: Fri, 17 Oct 2014 14:58:16 +0100 Subject: [PATCH 135/373] Fixes global leak `prop` --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 48a37dae..761fffa6 100644 --- a/lib/test.js +++ b/lib/test.js @@ -52,7 +52,7 @@ function Test (name_, opts_, cb_) { this._progeny = []; this._ok = true; - for (prop in this) { + for (var prop in this) { this[prop] = (function bind(self, val) { if (typeof val === 'function') { return function bound() { From 51afa0b0ea5135c76c6fa9f6bbde36b7a9872e77 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 17 Oct 2014 22:00:29 +0800 Subject: [PATCH 136/373] 3.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a2ab89bc..c44442fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.0.0", + "version": "3.0.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 8d27b7b630a76d23adb28d8f62861822ae14e23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Baunb=C3=A6k?= Date: Wed, 5 Nov 2014 17:24:49 +0100 Subject: [PATCH 137/373] Change "a,b" into "actual,expected" --- readme.markdown | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/readme.markdown b/readme.markdown index f33a5d62..8a65055e 100644 --- a/readme.markdown +++ b/readme.markdown @@ -127,32 +127,32 @@ description message. Aliases: `t.ifError()`, `t.ifErr()`, `t.iferror()` -## t.equal(a, b, msg) +## t.equal(actual, expected, msg) -Assert that `a === b` with an optional description `msg`. +Assert that `actual === expected` with an optional description `msg`. Aliases: `t.equals()`, `t.isEqual()`, `t.is()`, `t.strictEqual()`, `t.strictEquals()` -## t.notEqual(a, b, msg) +## t.notEqual(actual, expected, msg) -Assert that `a !== b` with an optional description `msg`. +Assert that `actual !== expected` with an optional description `msg`. Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNotEqual()`, `t.isNot()`, `t.not()`, `t.doesNotEqual()`, `t.isInequal()` -## t.deepEqual(a, b, msg) +## t.deepEqual(actual, expected, msg) -Assert that `a` and `b` have the same structure and nested values using +Assert that `actual` and `bexpected` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with strict comparisons (`===`) on leaf nodes and an optional description `msg`. Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.same()` -## t.notDeepEqual(a, b, msg) +## t.notDeepEqual(actual, expected, msg) -Assert that `a` and `b` do not have the same structure and nested values using +Assert that `actual` and `expected` do not have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with strict comparisons (`===`) on leaf nodes and an optional description `msg`. @@ -161,17 +161,17 @@ Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, `t.isNotDeepEqual()`, `t.isNotDeeply()`, `t.isNotEquivalent()`, `t.isInequivalent()` -## t.deepLooseEqual(a, b, msg) +## t.deepLooseEqual(actual, expected, msg) -Assert that `a` and `b` have the same structure and nested values using +Assert that `actual` and `expected` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with loose comparisons (`==`) on leaf nodes and an optional description `msg`. Aliases: `t.looseEqual()`, `t.looseEquals()` -## t.notDeepLooseEqual(a, b, msg) +## t.notDeepLooseEqual(actual, expected, msg) -Assert that `a` and `b` do not have the same structure and nested values using +Assert that `actual` and `expected` do not have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with loose comparisons (`==`) on leaf nodes and an optional description `msg`. From 249f96135aee110cdba93a8596543d5c12551d96 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Wed, 5 Nov 2014 10:47:06 -0800 Subject: [PATCH 138/373] 3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c44442fd..757e2e45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.0.1", + "version": "3.0.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 5121547ab28ac6b16be594772680a3364956e2d9 Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Mon, 10 Nov 2014 13:57:32 -0800 Subject: [PATCH 139/373] notLooseEquals should be !deepEqual --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 761fffa6..9bd34c24 100644 --- a/lib/test.js +++ b/lib/test.js @@ -385,7 +385,7 @@ Test.prototype.notDeepLooseEqual = Test.prototype.notLooseEqual = Test.prototype.notLooseEquals = function (a, b, msg, extra) { - this._assert(deepEqual(a, b), { + this._assert(!deepEqual(a, b), { message : defined(msg, 'should be equivalent'), operator : 'notDeepLooseEqual', actual : a, From fbb5966f9f3a3478429b4c2d33dabb51c84ce16f Mon Sep 17 00:00:00 2001 From: James Halliday Date: Tue, 11 Nov 2014 01:22:00 -0800 Subject: [PATCH 140/373] 3.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 757e2e45..65fa71a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.0.2", + "version": "3.0.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From ca27f594ea3bc12c81a667ca019fb31a37ff7b60 Mon Sep 17 00:00:00 2001 From: Ali Ghassemi Date: Wed, 3 Dec 2014 19:46:02 -0800 Subject: [PATCH 141/373] Adding a tap-xunit to reporters. Just adding a TAP -> xUnit XML converter I wrote to the list of third-party reporters. --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index 8a65055e..fa554bcf 100644 --- a/readme.markdown +++ b/readme.markdown @@ -61,6 +61,7 @@ that will output something pretty if you pipe TAP into them: - https://www.npmjs.org/package/tap-pessimist - https://github.com/toolness/tap-prettify - https://github.com/shuhei/colortape + - https://github.com/aghassemi/tap-xunit To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From dd661b0b4bddce16b1d92c8d8faca10cca4bcaf6 Mon Sep 17 00:00:00 2001 From: "Raynos (Jake Verbaten)" Date: Sat, 13 Dec 2014 22:21:46 -0800 Subject: [PATCH 142/373] Remove uncaught-exception. --- index.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/index.js b/index.js index 0e8855bd..d848d2e3 100644 --- a/index.js +++ b/index.js @@ -63,23 +63,9 @@ function createExitHarness (conf) { if (conf.exit === false) return harness; if (!canEmitExit || !canExit) return harness; - - var _error; - process.on('uncaughtException', function (err) { - if (err && err.code === 'EPIPE' && err.errno === 'EPIPE' - && err.syscall === 'write') return; - - _error = err - - throw err - }) process.on('exit', function (code) { - if (_error) { - return - } - if (!ended) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { From 9c60d320a58016f3f914f30eb468aa5e3a9a3c2e Mon Sep 17 00:00:00 2001 From: Raynos Date: Sat, 13 Dec 2014 22:38:53 -0800 Subject: [PATCH 143/373] Add back to do not call exit() if error semantics. The previous commit removed the uncaught exception interception. However that code was needed to get the process to write the uncaught stack trace on failures. Since messing with uncaught exception messes with the way we exit the only way to know if exit is called from uncaught exception is to monkey patch node core and keep track of the state --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index d848d2e3..6bf1498f 100644 --- a/index.js +++ b/index.js @@ -64,8 +64,20 @@ function createExitHarness (conf) { if (conf.exit === false) return harness; if (!canEmitExit || !canExit) return harness; + var inErrorState = false; + + var $_fatalException = process._fatalException + process._fatalException = function fakeFatalException() { + inErrorState = true; + $_fatalException.apply(this, arguments) + } process.on('exit', function (code) { + // let the process exit cleanly. + if (inErrorState) { + return + } + if (!ended) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { From 4233eefe6a80db66d9d608ef4a092352604bf505 Mon Sep 17 00:00:00 2001 From: jesse keane Date: Wed, 31 Dec 2014 15:50:17 -0800 Subject: [PATCH 144/373] remove unused require --- lib/test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 9bd34c24..f683930e 100644 --- a/lib/test.js +++ b/lib/test.js @@ -1,4 +1,3 @@ -var Stream = require('stream'); var deepEqual = require('deep-equal'); var defined = require('defined'); var path = require('path'); From 13efd546192dcc7fd58abdafe6f6831c9e1e269c Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Tue, 30 Dec 2014 21:35:06 -0700 Subject: [PATCH 145/373] add t.throws(fn, Function) --- lib/test.js | 12 +++++++++--- readme.markdown | 2 +- test/throws.js | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/throws.js diff --git a/lib/test.js b/lib/test.js index 9bd34c24..1660e984 100644 --- a/lib/test.js +++ b/lib/test.js @@ -18,7 +18,7 @@ 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; @@ -399,11 +399,12 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { msg = expected; expected = undefined; } + var caught = undefined; + try { fn(); - } - catch (err) { + } catch (err) { caught = { error : err }; var message = err.message; delete err.message; @@ -417,6 +418,11 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { expected = String(expected); } + if (typeof expected === 'function') { + passed = caught.error instanceof expected; + caught.error = caught.error.constructor; + } + this._assert(passed, { message : defined(msg, 'should throw'), operator : 'throws', diff --git a/readme.markdown b/readme.markdown index fa554bcf..07310fd7 100644 --- a/readme.markdown +++ b/readme.markdown @@ -180,7 +180,7 @@ Aliases: `t.notLooseEqual()`, `t.notLooseEquals()` ## t.throws(fn, expected, msg) -Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp`. +Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp` or `Function`. ## t.doesNotThrow(fn, expected, msg) diff --git a/test/throws.js b/test/throws.js new file mode 100644 index 00000000..ec91fb8d --- /dev/null +++ b/test/throws.js @@ -0,0 +1,20 @@ +var test = require('../'); + +function fn() { + throw new TypeError('RegExp'); +} + +test('throws', function (t) { + t.throws(fn); + t.end(); +}); + +test('throws (RegExp match)', function (t) { + t.throws(fn, /RegExp/); + t.end(); +}); + +test('throws (Function match)', function (t) { + t.throws(fn, TypeError); + t.end(); +}); From d417991fa2669c605756d6491732afb9b602399b Mon Sep 17 00:00:00 2001 From: Raynos Date: Thu, 15 Jan 2015 13:40:32 -0800 Subject: [PATCH 146/373] 3.1.0 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 65fa71a6..2c2274a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.0.3", + "version": "3.1.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", @@ -18,8 +18,8 @@ "through": "~2.3.4" }, "devDependencies": { - "tap" : "~0.4.8", - "falafel" : "~0.3.1", + "tap": "~0.4.8", + "falafel": "~0.3.1", "concat-stream": "~1.4.1" }, "scripts": { From 811cf0abc32b5bf5fef1a5c14f91fa14b3b0b7cd Mon Sep 17 00:00:00 2001 From: Raynos Date: Thu, 15 Jan 2015 13:40:46 -0800 Subject: [PATCH 147/373] 3.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c2274a1..eb0a713b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.1.0", + "version": "3.2.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 9fb94232b211accc97f971946412e5ab0ec2eb86 Mon Sep 17 00:00:00 2001 From: Fredrik Noren Date: Thu, 15 Jan 2015 17:00:27 -0500 Subject: [PATCH 148/373] Add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..07e6e472 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules From 926122a14823605b2881dbb12b35bc76904c8fa4 Mon Sep 17 00:00:00 2001 From: Fredrik Noren Date: Thu, 15 Jan 2015 17:00:47 -0500 Subject: [PATCH 149/373] Add timeoutAfter method to Test --- lib/test.js | 12 ++++++++++++ test/timeoutAfter.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/timeoutAfter.js diff --git a/lib/test.js b/lib/test.js index 9bd34c24..3a8d60bd 100644 --- a/lib/test.js +++ b/lib/test.js @@ -105,6 +105,18 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; +Test.prototype.timeoutAfter = function(ms) { + if (!ms) throw new Error('timeoutAfter requires a timespan'); + var self = this; + var timeout = setTimeout(function() { + self.fail('test timed out after ' + ms + 'ms'); + self.end(); + }, ms); + this.once('end', function() { + clearTimeout(timeout); + }); +} + Test.prototype.end = function (err) { var self = this; if (arguments.length >= 1) { diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js new file mode 100644 index 00000000..bd2a4f1b --- /dev/null +++ b/test/timeoutAfter.js @@ -0,0 +1,35 @@ +var tape = require('../'); +var tap = require('tap'); + +tap.test('timeoutAfter test', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : r.name.trim() }; + } + else return r; + }); + tt.same(rs, [ + 'TAP version 13', + 'timeoutAfter', + { id: 1, ok: false, name: 'test timed out after 1ms' }, + 'tests 1', + 'pass 0', + 'fail 1' + ]); + }); + + test.createStream().pipe(tc); + + test('timeoutAfter', function (t) { + t.plan(1); + t.timeoutAfter(1); + }); +}); From 00a8ba85255d9be9dc1cf6c1d00e501418dc7ea8 Mon Sep 17 00:00:00 2001 From: Fredrik Noren Date: Thu, 15 Jan 2015 17:02:35 -0500 Subject: [PATCH 150/373] Add timeoutAfter to readme --- readme.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.markdown b/readme.markdown index fa554bcf..7a61354b 100644 --- a/readme.markdown +++ b/readme.markdown @@ -105,6 +105,10 @@ Generate a failing assertion with a message `msg`. Generate a passing assertion with a message `msg`. +## t.timeoutAfter(ms) + +Automatically timeout the test after X ms. + ## t.skip(msg) Generate an assertion that will be skipped over. From 7133ca5fdba8df304f259342468fb143c7dcd565 Mon Sep 17 00:00:00 2001 From: Fredrik Noren Date: Fri, 16 Jan 2015 14:29:09 -0500 Subject: [PATCH 151/373] Support timeout in opts --- lib/test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/test.js b/lib/test.js index 3a8d60bd..d105e299 100644 --- a/lib/test.js +++ b/lib/test.js @@ -52,6 +52,10 @@ function Test (name_, opts_, cb_) { this._progeny = []; this._ok = true; + if (args.opts.timeout !== undefined) { + this.timeoutAfter(args.opts.timeout); + } + for (var prop in this) { this[prop] = (function bind(self, val) { if (typeof val === 'function') { From 4ed7caf6f70ac7fc835760d1482741ff19b234ac Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 16 Jan 2015 16:40:54 -0800 Subject: [PATCH 152/373] Improve at error detection - Improve performance by only computing stack if its not ok. - Fix bug where stack pretty printers prepend stuff to the stack. i.e. we now allows ^[^\s]*\s* instead of ^\s* - Fix edgecase stack line is `[Object object].method`. We now test s[1], s[2] and s[3] to work around this. This improves the detection of `at` and makes it more likely to be correct. This is a very important feature as it's the only thing that makes debugging failed assertions easy. Not fixing this causes some assertions to just not print an `at` statement at all. cc @substack --- lib/test.js | 59 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9bd34c24..d2e8f3f0 100644 --- a/lib/test.js +++ b/lib/test.js @@ -188,33 +188,45 @@ Test.prototype._assert = function assert (ok, opts) { res.error = defined(extra.error, opts.error, new Error(res.name)); } - var e = new Error('exception'); - var err = (e.stack || '').split('\n'); - var dir = path.dirname(__dirname) + '/'; - - for (var i = 0; i < err.length; i++) { - var m = /^\s*\bat\s+(.+)/.exec(err[i]); - if (!m) continue; + if (!ok) { + var e = new Error('exception'); + var err = (e.stack || '').split('\n'); + var dir = path.dirname(__dirname) + '/'; - var s = m[1].split(/\s+/); - var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]); - if (!filem) { - filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]); + for (var i = 0; i < err.length; i++) { + var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]); + if (!m) { + continue; + } + + var s = m[1].split(/\s+/); + var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]); + if (!filem) { + filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]); + + if (!filem) { + filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]); + + if (!filem) { + continue; + } + } + } + + if (filem[1].slice(0, dir.length) === dir) { + continue; + } - if (!filem) continue; + res.functionName = s[0]; + res.file = filem[1]; + res.line = Number(filem[2]); + if (filem[3]) res.column = filem[3]; + + res.at = m[1]; + break; } - - if (filem[1].slice(0, dir.length) === dir) continue; - - res.functionName = s[0]; - res.file = filem[1]; - res.line = Number(filem[2]); - if (filem[3]) res.column = filem[3]; - - res.at = m[1]; - break; } - + self.emit('result', res); var pendingAsserts = self._pendingAsserts(); @@ -460,3 +472,4 @@ Test.skip = function (name_, _opts, _cb) { }; // vim: set softtabstop=4 shiftwidth=4: + From ea6dc65c059683b32dea8c7456bed9ad95007e59 Mon Sep 17 00:00:00 2001 From: Fredrik Noren Date: Sun, 18 Jan 2015 18:48:58 -0500 Subject: [PATCH 153/373] Add opts to readme --- readme.markdown | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/readme.markdown b/readme.markdown index 7a61354b..02a9f409 100644 --- a/readme.markdown +++ b/readme.markdown @@ -75,10 +75,16 @@ in [node-tap](https://github.com/isaacs/node-tap). var test = require('tape') ``` -## test(name, cb) +## test([name], [opts], cb) -Create a new test with an optional `name` string. `cb(t)` fires with the new -test object `t` once all preceeding tests have finished. Tests execute serially. +Create a new test with an optional `name` string and optional `opts` object. +`cb(t)` fires with the new test object `t` once all preceeding tests have +finished. Tests execute serially. + +Available `opts` options are: +- opts.skip = true/false. See test.skip. +- opts.timeout = 500. Set a timeout for the test, after which it will fail. + See test.timeoutAfter. If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. From 3bbfec14443741e353deaac37c6b8c87e5c30a36 Mon Sep 17 00:00:00 2001 From: michaelrhodes Date: Mon, 19 Jan 2015 10:13:30 +1000 Subject: [PATCH 154/373] Add section about uncaught exceptions to readme. --- readme.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.markdown b/readme.markdown index fa554bcf..614ac972 100644 --- a/readme.markdown +++ b/readme.markdown @@ -66,6 +66,10 @@ that will output something pretty if you pipe TAP into them: To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! +# uncaught exceptions + +By default, uncaught exceptions in your tests will not be intercepted, and will cause tape to crash. If you find this behavior undesirable, use [tape-catch](https://github.com/michaelrhodes/tape-catch) to report any exceptions as TAP errors. + # methods The assertion methods in tape are heavily influenced or copied from the methods From d2afc96ac95a6cf62c94a58739a859aa691fbaa1 Mon Sep 17 00:00:00 2001 From: Raynos Date: Sun, 18 Jan 2015 16:49:18 -0800 Subject: [PATCH 155/373] 3.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb0a713b..66e78b18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.2.0", + "version": "3.3.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From d1e043a9a0cc069a97ee46ed9929934bc4c9a823 Mon Sep 17 00:00:00 2001 From: Raynos Date: Sun, 18 Jan 2015 17:02:31 -0800 Subject: [PATCH 156/373] 3.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66e78b18..ea8a6866 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.3.0", + "version": "3.4.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From e3f9d0193bdf2f8ce03912959fb762a56e908426 Mon Sep 17 00:00:00 2001 From: Raynos Date: Wed, 21 Jan 2015 16:44:54 -0800 Subject: [PATCH 157/373] Detect `inErrorState` with code not equal to zero --- index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/index.js b/index.js index 6bf1498f..a44daf9a 100644 --- a/index.js +++ b/index.js @@ -66,15 +66,9 @@ function createExitHarness (conf) { var inErrorState = false; - var $_fatalException = process._fatalException - process._fatalException = function fakeFatalException() { - inErrorState = true; - $_fatalException.apply(this, arguments) - } - process.on('exit', function (code) { // let the process exit cleanly. - if (inErrorState) { + if (code !== 0) { return } From b65d28c58ce3b68c83dba6e6e543fab3673f8762 Mon Sep 17 00:00:00 2001 From: Nowell Strite Date: Thu, 22 Jan 2015 14:04:07 -0500 Subject: [PATCH 158/373] Added tap-difflet to README --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index 7a8422b5..b86e2302 100644 --- a/readme.markdown +++ b/readme.markdown @@ -62,6 +62,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/toolness/tap-prettify - https://github.com/shuhei/colortape - https://github.com/aghassemi/tap-xunit + - https://github.com/namuol/tap-difflet To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From 35fd42bb725c1876af5cfe8bfc0ddde41c4d018e Mon Sep 17 00:00:00 2001 From: AWinterman Date: Mon, 26 Jan 2015 14:10:28 -0800 Subject: [PATCH 159/373] adds note on t.end(arg) behavior --- readme.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/readme.markdown b/readme.markdown index 7a8422b5..3a920ed5 100644 --- a/readme.markdown +++ b/readme.markdown @@ -103,9 +103,10 @@ Declare that `n` assertions should be run. `t.end()` will be called automatically after the `n`th assertion. If there are any more assertions after the `n`th, or after `t.end()` is called, they will generate errors. -## t.end() +## t.end(err) -Declare the end of a test explicitly. +Declare the end of a test explicitly. If `err` is passed in `t.end` will assert +that it is non-falsey. ## t.fail(msg) From 89f79a83494360a61f89ee7d04681dbcdebc956b Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Thu, 29 Jan 2015 19:53:02 -0600 Subject: [PATCH 160/373] Fixing backwards t.end explanation t.end asserts that the "err" object is not truthy https://github.com/substack/tape/blob/master/lib/test.js#L323 --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 3a920ed5..7a3263f5 100644 --- a/readme.markdown +++ b/readme.markdown @@ -106,7 +106,7 @@ the `n`th, or after `t.end()` is called, they will generate errors. ## t.end(err) Declare the end of a test explicitly. If `err` is passed in `t.end` will assert -that it is non-falsey. +that it is falsey. ## t.fail(msg) From 51f2f97d7eade23b1e23b7cfea37f449ade5b9c3 Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 30 Jan 2015 10:52:29 -0800 Subject: [PATCH 161/373] 3.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea8a6866..46458ca6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.4.0", + "version": "3.5.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 47f507f5b98f62855e9c8f16362290521c12fa95 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Thu, 5 Feb 2015 14:54:29 -0700 Subject: [PATCH 162/373] add caught guard to avoid referencing undefined property --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index b9d6111b..a242e271 100644 --- a/lib/test.js +++ b/lib/test.js @@ -445,7 +445,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { expected = String(expected); } - if (typeof expected === 'function') { + if (typeof expected === 'function' && caught) { passed = caught.error instanceof expected; caught.error = caught.error.constructor; } From 65ef27e12a3016843a24e8791684ab11f1a77ddd Mon Sep 17 00:00:00 2001 From: Raynos Date: Thu, 5 Feb 2015 14:04:56 -0800 Subject: [PATCH 163/373] 3.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 46458ca6..fab6d50b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.5.0", + "version": "3.5.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From bafca7b444f5bc9338658301004688607d625b27 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Wed, 11 Feb 2015 23:15:16 +0000 Subject: [PATCH 164/373] Fixed typo in README --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 7a3263f5..c1d585c6 100644 --- a/readme.markdown +++ b/readme.markdown @@ -159,7 +159,7 @@ Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, ## t.deepEqual(actual, expected, msg) -Assert that `actual` and `bexpected` have the same structure and nested values using +Assert that `actual` and `expected` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with strict comparisons (`===`) on leaf nodes and an optional description `msg`. From 4205104c47c211d1b52547d4922bdd3def8b56e4 Mon Sep 17 00:00:00 2001 From: Raynos Date: Mon, 9 Mar 2015 17:48:59 -0700 Subject: [PATCH 165/373] only ifError if we have an err value --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index b9d6111b..f5cf5ead 100644 --- a/lib/test.js +++ b/lib/test.js @@ -122,7 +122,7 @@ Test.prototype.timeoutAfter = function(ms) { Test.prototype.end = function (err) { var self = this; - if (arguments.length >= 1) { + if (arguments.length >= 1 && !!err) { this.ifError(err); } From 7329ddc629b44b22ef0724da846f81de7c49dab1 Mon Sep 17 00:00:00 2001 From: Raynos Date: Mon, 9 Mar 2015 18:49:36 -0700 Subject: [PATCH 166/373] fix test --- test/end-as-callback.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/end-as-callback.js b/test/end-as-callback.js index 6d24a0c3..678ddf68 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -19,13 +19,12 @@ tap.test("tape assert.end as callback", function (tt) { "do a task and write", { id: 1, ok: true, name: "null" }, { id: 2, ok: true, name: "should be equal" }, - { id: 3, ok: true, name: "null" }, "do a task and write fail", - { id: 4, ok: true, name: "null" }, - { id: 5, ok: true, name: "should be equal" }, - { id: 6, ok: false, name: "Error: fail" }, - "tests 6", - "pass 5", + { id: 3, ok: true, name: "null" }, + { id: 4, ok: true, name: "should be equal" }, + { id: 5, ok: false, name: "Error: fail" }, + "tests 5", + "pass 4", "fail 1" ]) From 04bb03eeda4e2369b1d4c277aeaf811117b5e126 Mon Sep 17 00:00:00 2001 From: Sequoia McDowell Date: Tue, 24 Mar 2015 22:34:37 -0400 Subject: [PATCH 167/373] Add documentation of test.comment Tried to work the term `console.log` in there for people like me with `console.log` issues searching the docs for a solution. --- readme.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.markdown b/readme.markdown index 882a24c6..05aa6e8d 100644 --- a/readme.markdown +++ b/readme.markdown @@ -217,6 +217,11 @@ By default the TAP output goes to `console.log()`. You can pipe the output to someplace else if you `htest.createStream().pipe()` to a destination stream on the first tick. + +## test.comment(message) + +Print a message without breaking the tap output. (Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.) + ## test.only(name, cb) Like `test(name, cb)` except if you use `.only` this is the only test case From 4b1e452ea64cd4e25f91ea6155e6888dbc513382 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 24 Mar 2014 09:37:46 -0700 Subject: [PATCH 168/373] Remove this extra test I mistakenly committed --- test/skip.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/skip.js b/test/skip.js index 216b6006..7b23126c 100644 --- a/test/skip.js +++ b/test/skip.js @@ -19,11 +19,6 @@ test.skip('skip this too', function(t) { t.end(); }); -test.skip('skip this too', function(t) { - t.fail('this should not even run'); - t.end(); -}); - test('skip subtest', function(t) { ran ++; t.test('do not skip this', { skip: false }, function(t) { From 91cb127a13979c849142b62494c6395b53ea0641 Mon Sep 17 00:00:00 2001 From: Raynos Date: Thu, 2 Apr 2015 13:01:26 -0700 Subject: [PATCH 169/373] 3.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fab6d50b..15e892f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.5.1", + "version": "3.6.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From d6acc1eeed6307ecfd9de7339d29ea4c0dc7a513 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 2 Apr 2015 14:51:23 -0400 Subject: [PATCH 170/373] Update dependencies Fixes #93. --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 15e892f4..e71dd319 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,17 @@ "test": "test" }, "dependencies": { - "deep-equal": "~0.2.0", + "deep-equal": "~1.0.0", "defined": "~0.0.0", - "glob": "~3.2.9", + "glob": "~5.0.3", "inherits": "~2.0.1", - "object-inspect": "~0.4.0", + "object-inspect": "~1.0.0", "resumer": "~0.0.0", "through": "~2.3.4" }, "devDependencies": { - "tap": "~0.4.8", - "falafel": "~0.3.1", + "tap": "~0.7.1", + "falafel": "~1.0.1", "concat-stream": "~1.4.1" }, "scripts": { From a6bdf9cdacb7ee01718f390ba21f8856df14d220 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 2 Apr 2015 15:11:25 -0400 Subject: [PATCH 171/373] Expand reporters section into "things that go well with tape" Closes #147. --- readme.markdown | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/readme.markdown b/readme.markdown index 05aa6e8d..b5d5dad2 100644 --- a/readme.markdown +++ b/readme.markdown @@ -43,7 +43,11 @@ not ok 2 should be equal # fail 1 ``` -# pretty reporters +# things that go well with tape + +tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape. + +## pretty reporters The default TAP output is good for machines and humans that are robots. @@ -67,10 +71,15 @@ that will output something pretty if you pipe TAP into them: To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! -# uncaught exceptions +## uncaught exceptions By default, uncaught exceptions in your tests will not be intercepted, and will cause tape to crash. If you find this behavior undesirable, use [tape-catch](https://github.com/michaelrhodes/tape-catch) to report any exceptions as TAP errors. +## other + +- CoffeeScript support with https://www.npmjs.com/package/coffeetape +- Promise support with https://www.npmjs.com/package/blue-tape + # methods The assertion methods in tape are heavily influenced or copied from the methods From cf56a1336f90a0dcac7f5a9afa4afc09e00bfb8b Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 3 Apr 2015 15:27:27 -0400 Subject: [PATCH 172/373] Drop 0.8 support --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cc4dba29..6064ca09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js node_js: - - "0.8" - "0.10" + - "0.12" + - "iojs" From 99f32f5e382f50ae2d9f9a5ddf469f23cc00dd93 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 3 Apr 2015 15:37:18 -0400 Subject: [PATCH 173/373] 4.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e71dd319..2168dee2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.6.0", + "version": "4.0.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From e1a6dd03410d89fb285f614ab441f09c4c1caae2 Mon Sep 17 00:00:00 2001 From: David Clark Date: Sat, 9 May 2015 10:37:06 -0700 Subject: [PATCH 174/373] Clarify comment documentation I'm getting that `test.comment()` is undefined; so I'm thinking that `t.comment()` is what was intended to be documented. Right? I moved it only so that it is next to the other `t` methods. --- readme.markdown | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/readme.markdown b/readme.markdown index b5d5dad2..256f989a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -217,6 +217,10 @@ Create a subtest with a new test handle `st` from `cb(st)` inside the current test `t`. `cb(st)` will only fire when `t` finishes. Additional tests queued up after `t` will not be run until all subtests finish. +## t.comment(message) + +Print a message without breaking the tap output. (Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.) + ## var htest = test.createHarness() Create a new test harness instance, which is a function like `test()`, but with @@ -226,11 +230,6 @@ By default the TAP output goes to `console.log()`. You can pipe the output to someplace else if you `htest.createStream().pipe()` to a destination stream on the first tick. - -## test.comment(message) - -Print a message without breaking the tap output. (Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.) - ## test.only(name, cb) Like `test(name, cb)` except if you use `.only` this is the only test case From b9e351572c1c4344768dceca48e0ff5b1eb2695b Mon Sep 17 00:00:00 2001 From: Jesse McCarthy Date: Wed, 3 Jun 2015 16:30:06 -0400 Subject: [PATCH 175/373] Add info about bin usage to readme. --- readme.markdown | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/readme.markdown b/readme.markdown index 256f989a..c462474e 100644 --- a/readme.markdown +++ b/readme.markdown @@ -43,6 +43,27 @@ not ok 2 should be equal # fail 1 ``` +# usage + +You always need to `require('tape')` in test files. You can run the tests by +usual node means (`require('test-file.js')` or `node test-file.js`). You can +also run tests using the `tape` binary to utilize globbing, on Windows for +example: + +```sh +$ tape tests/**/*.js +``` + +`tape`'s arguments are passed to the +[`glob`](https://www.npmjs.com/package/glob) module. If you want `glob` to +perform the expansion on a system where the shell performs such expansion, quote +the arguments as necessary: + +```sh +$ tape 'tests/**/*.js' +$ tape "tests/**/*.js" +``` + # things that go well with tape tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape. From f9a8088b93dfed09ae1a6e3be614e3e03ef8eed2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 14 Jul 2015 09:49:21 -0500 Subject: [PATCH 176/373] Cache `Object#hasOwnProperty` in case clients break it as part of tests Obviates https://github.com/substack/object-inspect/pull/2. --- lib/results.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/results.js b/lib/results.js index fa414f47..18ac3ba8 100644 --- a/lib/results.js +++ b/lib/results.js @@ -3,6 +3,7 @@ var inherits = require('inherits'); var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); +var hasOwn = Object.prototype.hasOwnProperty; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick @@ -185,5 +186,5 @@ function getNextTest (results) { } function has (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); + return hasOwn.call(obj, prop); } From 74635e759f43f3976f0e469ae28be82a3f7fb111 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 19 Jul 2015 00:38:37 -0700 Subject: [PATCH 177/373] 4.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2168dee2..eb2a8217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.0.0", + "version": "4.0.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 2280128cb25fd1544d5b35cb4da2f30bbe4945b9 Mon Sep 17 00:00:00 2001 From: Mathias Rangel Wulff Date: Tue, 21 Jul 2015 22:46:31 +0200 Subject: [PATCH 178/373] Added --save-dev to install instruction --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index c462474e..f4e82f06 100644 --- a/readme.markdown +++ b/readme.markdown @@ -344,7 +344,7 @@ $ node object.js test/x.js test/y.js With [npm](https://npmjs.org) do: ``` -npm install tape +npm install tape --save-dev ``` # license From 8d04af425d1e614abb9f6272187391dbb8fb5f1e Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 19 Jul 2014 18:18:56 -0400 Subject: [PATCH 179/373] Comments should not make exit code incorrect. Fixes #92 --- index.js | 2 +- test/exit.js | 1 + test/exit/ok.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a44daf9a..0725efd3 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ function createHarness (conf_) { inspectCode(st_); }); st.on('result', function (r) { - if (!r.ok) test._exitCode = 1 + if (!r.ok && typeof r !== 'string') test._exitCode = 1 }); })(t); diff --git a/test/exit.js b/test/exit.js index 7f7c5d01..8055e5e6 100644 --- a/test/exit.js +++ b/test/exit.js @@ -18,6 +18,7 @@ tap.test('exit ok', function (t) { t.same(rs, [ 'TAP version 13', 'array', + 'hi', { id: 1, ok: true, name: 'should be equivalent' }, { id: 2, ok: true, name: 'should be equivalent' }, { id: 3, ok: true, name: 'should be equivalent' }, diff --git a/test/exit/ok.js b/test/exit/ok.js index a02c7b69..f1068e57 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -2,6 +2,7 @@ var falafel = require('falafel'); var test = require('../../'); test('array', function (t) { + t.comment('hi'); t.plan(5); var src = '(' + function () { From 670e5f7837f005d3be2d8997798e768da27ce3d8 Mon Sep 17 00:00:00 2001 From: Raynos Date: Mon, 3 Aug 2015 11:35:15 -0700 Subject: [PATCH 180/373] 4.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eb2a8217..33a13789 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.0.1", + "version": "4.0.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 3eda12c110980a8348c23c0e544ab74fd1318693 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 6 Aug 2015 23:50:54 -0700 Subject: [PATCH 181/373] Cache `Object.prototype.hasOwnProperty` here also. Per f9a8088b93dfed09ae1a6e3be614e3e03ef8eed2 / #163 --- lib/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index f65f12ad..efb081b6 100644 --- a/lib/test.js +++ b/lib/test.js @@ -482,8 +482,9 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { }); }; +var hasOwn = Object.prototype.hasOwnProperty; function has (obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); + return hasOwn.call(obj, prop); } Test.skip = function (name_, _opts, _cb) { From 38a8a9de02c5bad422ed518d36c340e25c44f489 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 6 Aug 2015 23:52:02 -0700 Subject: [PATCH 182/373] v4.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 33a13789..d999085a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.0.2", + "version": "4.0.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From bea81d2068d6235d337cf98ac12321123d3d9780 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Sat, 8 Aug 2015 17:57:54 -0500 Subject: [PATCH 183/373] Expose the main harness's results object Allows reporting failed/succeeded tests to SauceLabs/BrowserStack. Fixes #148 --- index.js | 8 ++++++-- test/exposed-results.js | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/exposed-results.js diff --git a/index.js b/index.js index 0725efd3..a6454d08 100644 --- a/index.js +++ b/index.js @@ -35,9 +35,13 @@ exports = module.exports = (function () { } return harness.createStream(opts); }; - + + lazyLoad.results = function () { + return getHarness()._results + } + return lazyLoad - + function getHarness (opts) { if (!opts) opts = {}; opts.autoclose = !canEmitExit; diff --git a/test/exposed-results.js b/test/exposed-results.js new file mode 100644 index 00000000..a459c1a6 --- /dev/null +++ b/test/exposed-results.js @@ -0,0 +1,13 @@ +var tape = require('../'); +var tap = require('tap'); + +tap.test('results object is exposed', function (assert) { + + assert.equal(typeof tape.results, 'function', 'tape.results is a function') + + assert.equal(tape.results().pass, 0) + + assert.end() + +}) + From fc889f56b418fbb30150d517ed7d8b8aa5b943d4 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Tue, 11 Aug 2015 09:07:12 -0500 Subject: [PATCH 184/373] Exposing the whole test harness --- index.js | 4 +--- test/exposed-harness.js | 13 +++++++++++++ test/exposed-results.js | 13 ------------- 3 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 test/exposed-harness.js delete mode 100644 test/exposed-results.js diff --git a/index.js b/index.js index a6454d08..2bf2d328 100644 --- a/index.js +++ b/index.js @@ -36,9 +36,7 @@ exports = module.exports = (function () { return harness.createStream(opts); }; - lazyLoad.results = function () { - return getHarness()._results - } + lazyLoad.getHarness = getHarness return lazyLoad diff --git a/test/exposed-harness.js b/test/exposed-harness.js new file mode 100644 index 00000000..b790340c --- /dev/null +++ b/test/exposed-harness.js @@ -0,0 +1,13 @@ +var tape = require('../'); +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(tape.getHarness()._results.pass, 0) + + assert.end() + +}) + diff --git a/test/exposed-results.js b/test/exposed-results.js deleted file mode 100644 index a459c1a6..00000000 --- a/test/exposed-results.js +++ /dev/null @@ -1,13 +0,0 @@ -var tape = require('../'); -var tap = require('tap'); - -tap.test('results object is exposed', function (assert) { - - assert.equal(typeof tape.results, 'function', 'tape.results is a function') - - assert.equal(tape.results().pass, 0) - - assert.end() - -}) - From b73d2bfb69364f5332f5958bca2c69099aedc290 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Wed, 12 Aug 2015 12:13:46 -0700 Subject: [PATCH 185/373] improve yaml formatting of diagnostic information --- lib/results.js | 19 ++++++---- package.json | 6 ++- test/circular-things.js | 59 +++++++++++++---------------- test/deep-equal-failure.js | 68 +++++++++++++++++++++++++++++++++ test/stackTrace.js | 77 ++++++++++++++++++++++++++++++++++++++ test/undef.js | 6 ++- 6 files changed, 191 insertions(+), 44 deletions(-) create mode 100644 test/deep-equal-failure.js create mode 100644 test/stackTrace.js diff --git a/lib/results.js b/lib/results.js index 18ac3ba8..b9f6ac4d 100644 --- a/lib/results.js +++ b/lib/results.js @@ -4,6 +4,8 @@ var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); var hasOwn = Object.prototype.hasOwnProperty; +var regexpTest = RegExp.prototype.test; +var yamlIndicators = /\:|\-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick @@ -146,9 +148,9 @@ function encodeResult (res, count) { var ex = inspect(res.expected); var ac = inspect(res.actual); - if (Math.max(ex.length, ac.length) > 65) { - output += inner + 'expected:\n' + inner + ' ' + ex + '\n'; - output += inner + 'actual:\n' + inner + ' ' + ac + '\n'; + 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'; @@ -160,10 +162,9 @@ function encodeResult (res, count) { } if (res.operator === 'error' && res.actual && res.actual.stack) { var lines = String(res.actual.stack).split('\n'); - output += inner + 'stack:\n'; - output += inner + ' ' + lines[0] + '\n'; - for (var i = 1; i < lines.length; i++) { - output += inner + lines[i] + '\n'; + output += inner + 'stack: |-\n'; + for (var i = 0; i < lines.length; i++) { + output += inner + ' ' + lines[i] + '\n'; } } @@ -188,3 +189,7 @@ function getNextTest (results) { function has (obj, prop) { return hasOwn.call(obj, prop); } + +function invalidYaml (str) { + return regexpTest.call(yamlIndicators, str); +} diff --git a/package.json b/package.json index d999085a..80e10d36 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,11 @@ "through": "~2.3.4" }, "devDependencies": { - "tap": "~0.7.1", + "concat-stream": "~1.4.1", "falafel": "~1.0.1", - "concat-stream": "~1.4.1" + "js-yaml": "^3.3.1", + "tap": "~0.7.1", + "tap-parser": "^1.1.6" }, "scripts": { "test": "tap test/*.js" diff --git a/test/circular-things.js b/test/circular-things.js index 1a0368d6..590ae430 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -1,43 +1,36 @@ var tape = require('../'); var tap = require('tap'); +var concat = require('concat-stream'); tap.test('circular test', function (assert) { var test = tape.createHarness({ exit : false }); - var tc = tap.createConsumer(); + assert.plan(1); - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - // console.log("rs", rows) - - // console.log("deepEqual?") - - assert.same(rows, [ - "TAP version 13" - , "circular" - , { id: 1 - , ok: false - , name: " should be equal" - , operator: "equal" - , expected: "{}" - , actual: '{ circular: [Circular] }' - } - , "tests 1" - , "pass 0" - , "fail 1" - ]) - assert.end() - }) - - // tt.equal(10, 10) - // tt.end() - - test.createStream().pipe(tc); + test.createStream().pipe(concat(function (body) { + assert.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# circular\n' + + 'not ok 1 should be equal\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: |-\n' + + ' {}\n' + + ' actual: |-\n' + + ' { circular: [Circular] }\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + })); test("circular", function (t) { - t.plan(1) - var circular = {} - circular.circular = circular - t.equal(circular, {}) + t.plan(1); + var circular = {}; + circular.circular = circular; + t.equal(circular, {}); }) }) diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js new file mode 100644 index 00000000..2467f763 --- /dev/null +++ b/test/deep-equal-failure.js @@ -0,0 +1,68 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); +var tapParser = require('tap-parser'); +var yaml = require('js-yaml'); + +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.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# deep equal\n' + + 'not ok 1 should be equal\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: |-\n' + + ' { b: 2 }\n' + + ' actual: |-\n' + + ' { a: 1 }\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + 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 equal', + diag: { + operator: 'equal', + expected: '{ b: 2 }', + actual: '{ a: 1 }' + } + }); + }); + + test("deep equal", function (t) { + t.plan(1); + t.equal({a: 1}, {b: 2}); + }); +}) + +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'); + + return yaml.safeLoad(diag); +} diff --git a/test/stackTrace.js b/test/stackTrace.js new file mode 100644 index 00000000..bde1bc50 --- /dev/null +++ b/test/stackTrace.js @@ -0,0 +1,77 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); +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', + expected: 'undefined', + actual: '[Error: Preserve stack]' + } + }); + }); + + stream.pipe(concat(function (body) { + var body = body.toString('utf8') + tt.equal( + body, + 'TAP version 13\n' + + '# multiline stack trace\n' + + 'not ok 1 Error: Preserve stack\n' + + ' ---\n' + + ' operator: error\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + ' [Error: Preserve stack]\n' + + ' stack: |-\n' + + ' foo\n' + + ' bar\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + tt.deepEqual(getDiag(body), { + stack: stackTrace, + operator: 'error', + expected: 'undefined', + actual: '[Error: Preserve stack]' + }); + })); + + test('multiline stack trace', function (t) { + t.plan(1); + var err = new Error('Preserve stack'); + err.stack = stackTrace; + t.error(err); + }); +}); + +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'); + + return yaml.safeLoad(diag); +} diff --git a/test/undef.js b/test/undef.js index e856a54b..d3ae8d40 100644 --- a/test/undef.js +++ b/test/undef.js @@ -14,8 +14,10 @@ tap.test('array test', function (tt) { + 'not ok 1 should be equivalent\n' + ' ---\n' + ' operator: deepEqual\n' - + ' expected: { beep: undefined }\n' - + ' actual: {}\n' + + ' expected: |-\n' + + ' { beep: undefined }\n' + + ' actual: |-\n' + + ' {}\n' + ' ...\n' + '\n' + '1..1\n' From e416a8e2ca479c973e43f4186dddb8817fcc88d9 Mon Sep 17 00:00:00 2001 From: Raynos Date: Wed, 12 Aug 2015 13:09:03 -0700 Subject: [PATCH 186/373] 4.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80e10d36..730c20ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.0.3", + "version": "4.1.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From e82c1e8e7a5d5ad420fc9efc8accfaa11b7dd12c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 14 Aug 2015 16:58:51 -0700 Subject: [PATCH 187/373] Use `has` instead of a homegrown version of the same. --- lib/results.js | 6 +----- lib/test.js | 6 +----- package.json | 1 + 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/results.js b/lib/results.js index b9f6ac4d..bbaadfec 100644 --- a/lib/results.js +++ b/lib/results.js @@ -3,7 +3,7 @@ var inherits = require('inherits'); var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); -var hasOwn = Object.prototype.hasOwnProperty; +var has = require('has'); var regexpTest = RegExp.prototype.test; var yamlIndicators = /\:|\-|\?/; var nextTick = typeof setImmediate !== 'undefined' @@ -186,10 +186,6 @@ function getNextTest (results) { } while (results.tests.length !== 0) } -function has (obj, prop) { - return hasOwn.call(obj, prop); -} - function invalidYaml (str) { return regexpTest.call(yamlIndicators, str); } diff --git a/lib/test.js b/lib/test.js index efb081b6..bfd1bb14 100644 --- a/lib/test.js +++ b/lib/test.js @@ -3,6 +3,7 @@ var defined = require('defined'); var path = require('path'); var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; +var has = require('has'); module.exports = Test; @@ -482,11 +483,6 @@ Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { }); }; -var hasOwn = Object.prototype.hasOwnProperty; -function has (obj, prop) { - return hasOwn.call(obj, prop); -} - Test.skip = function (name_, _opts, _cb) { var args = getTestArgs.apply(null, arguments); args.opts.skip = true; diff --git a/package.json b/package.json index 730c20ef..7a4ca267 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "deep-equal": "~1.0.0", "defined": "~0.0.0", "glob": "~5.0.3", + "has": "~1.0.1", "inherits": "~2.0.1", "object-inspect": "~1.0.0", "resumer": "~0.0.0", From 88d567cdd9fcc0f7016029b8aa97e8439edb85c4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 14 Aug 2015 17:01:28 -0700 Subject: [PATCH 188/373] Use `function-bind` to ensure we're robust against modification of `Function#call` --- lib/results.js | 5 +++-- package.json | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/results.js b/lib/results.js index bbaadfec..9a494094 100644 --- a/lib/results.js +++ b/lib/results.js @@ -3,8 +3,9 @@ var inherits = require('inherits'); var through = require('through'); var resumer = require('resumer'); var inspect = require('object-inspect'); +var bind = require('function-bind'); var has = require('has'); -var regexpTest = RegExp.prototype.test; +var regexpTest = bind.call(Function.call, RegExp.prototype.test); var yamlIndicators = /\:|\-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate @@ -187,5 +188,5 @@ function getNextTest (results) { } function invalidYaml (str) { - return regexpTest.call(yamlIndicators, str); + return regexpTest(yamlIndicators, str); } diff --git a/package.json b/package.json index 7a4ca267..5b121060 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "deep-equal": "~1.0.0", "defined": "~0.0.0", + "function-bind": "~1.0.2", "glob": "~5.0.3", "has": "~1.0.1", "inherits": "~2.0.1", From aadcf4a95ed6810fa404dbe01f3b745252d4f12e Mon Sep 17 00:00:00 2001 From: James Halliday Date: Fri, 14 Aug 2015 19:24:55 -0700 Subject: [PATCH 189/373] 4.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5b121060..96bcc4d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.1.0", + "version": "4.2.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From c22ad7857655b779fdab6002a0b4902e4e130d9b Mon Sep 17 00:00:00 2001 From: Victor Grishchenko Date: Wed, 16 Sep 2015 09:40:57 +0300 Subject: [PATCH 190/373] add tape-dom link to the readme --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index f4e82f06..c5751ce8 100644 --- a/readme.markdown +++ b/readme.markdown @@ -88,6 +88,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/shuhei/colortape - https://github.com/aghassemi/tap-xunit - https://github.com/namuol/tap-difflet + - https://github.com/gritzko/tape-dom To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From 0e407f05d66c6e29ef26989d659db99b86b40a64 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 22 Sep 2015 08:22:31 -0700 Subject: [PATCH 191/373] Bumping `defined` to v1.0.0 - no implementation change, just follows semver now. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96bcc4d2..ddc48d46 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "deep-equal": "~1.0.0", - "defined": "~0.0.0", + "defined": "~1.0.0", "function-bind": "~1.0.2", "glob": "~5.0.3", "has": "~1.0.1", From df624584d8420848bfcb340a62701dcd717867af Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Sun, 27 Sep 2015 22:07:15 -0700 Subject: [PATCH 192/373] Add Node v4 I imagine the entry "4" will continue to be the latest stable release of the 4.x line on travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6064ca09..8c17ea84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ node_js: - "0.10" - "0.12" - "iojs" + - "4" From 77e184843f955722e261f81e50c5cc10f06784fd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 2 Oct 2015 01:37:21 -0700 Subject: [PATCH 193/373] Use `string.prototype.trim` instead of relying on `String#trim`, for ES3. --- lib/test.js | 3 ++- package.json | 1 + test/array.js | 3 ++- test/end-as-callback.js | 3 ++- test/exit.js | 9 +++++---- test/fail.js | 3 ++- test/nested-sync-noplan-noend.js | 3 ++- test/nested.js | 3 ++- test/only.js | 3 ++- test/timeoutAfter.js | 3 ++- test/too_many.js | 3 ++- 11 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/test.js b/lib/test.js index bfd1bb14..6c91b0e2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -4,6 +4,7 @@ var path = require('path'); var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; var has = require('has'); +var trim = require('string.prototype.trim'); module.exports = Test; @@ -101,7 +102,7 @@ Test.prototype.test = function (name, opts, cb) { }; Test.prototype.comment = function (msg) { - this.emit('result', msg.trim().replace(/^#\s*/, '')); + this.emit('result', trim(msg).replace(/^#\s*/, '')); }; Test.prototype.plan = function (n) { diff --git a/package.json b/package.json index ddc48d46..cd703a96 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "inherits": "~2.0.1", "object-inspect": "~1.0.0", "resumer": "~0.0.0", + "string.prototype.trim": "^1.1.1", "through": "~2.3.4" }, "devDependencies": { diff --git a/test/array.js b/test/array.js index 2d498632..fbbff16e 100644 --- a/test/array.js +++ b/test/array.js @@ -1,6 +1,7 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('array test', function (tt) { tt.plan(1); @@ -13,7 +14,7 @@ tap.test('array test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/end-as-callback.js b/test/end-as-callback.js index 678ddf68..df0bcbc3 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -1,5 +1,6 @@ var tap = require("tap"); var tape = require("../"); +var trim = require('string.prototype.trim'); tap.test("tape assert.end as callback", function (tt) { var test = tape.createHarness({ exit: false }) @@ -10,7 +11,7 @@ tap.test("tape assert.end as callback", function (tt) { tc.on("end", function () { var rs = rows.map(function (r) { return r && typeof r === "object" ? - { id: r.id, ok: r.ok, name: r.name.trim() } : + { id: r.id, ok: r.ok, name: trim(r.name) } : r }) diff --git a/test/exit.js b/test/exit.js index 8055e5e6..02d2488b 100644 --- a/test/exit.js +++ b/test/exit.js @@ -1,5 +1,6 @@ var tap = require('tap'); var spawn = require('child_process').spawn; +var trim = require('string.prototype.trim'); tap.test('exit ok', function (t) { t.plan(2); @@ -11,7 +12,7 @@ tap.test('exit ok', function (t) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); @@ -47,7 +48,7 @@ tap.test('exit fail', function (t) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); @@ -82,7 +83,7 @@ tap.test('too few exit', function (t) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); @@ -118,7 +119,7 @@ tap.test('more planned in a second test', function (t) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/fail.js b/test/fail.js index d56045ad..c39666ae 100644 --- a/test/fail.js +++ b/test/fail.js @@ -1,6 +1,7 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('array test', function (tt) { tt.plan(1); @@ -13,7 +14,7 @@ tap.test('array test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index a206c501..874f27b1 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -1,5 +1,6 @@ var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('nested sync test without plan or end', function (tt) { tt.plan(1); @@ -12,7 +13,7 @@ tap.test('nested sync test without plan or end', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/nested.js b/test/nested.js index 673465d4..3b376385 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,6 +1,7 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('array test', function (tt) { tt.plan(1); @@ -13,7 +14,7 @@ tap.test('array test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/only.js b/test/only.js index 9e6bc26f..2decdc9c 100644 --- a/test/only.js +++ b/test/only.js @@ -1,5 +1,6 @@ var tap = require('tap'); var tape = require('../'); +var trim = require('string.prototype.trim'); tap.test('tape only test', function (tt) { var test = tape.createHarness({ exit: false }); @@ -11,7 +12,7 @@ tap.test('tape only test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id: r.id, ok: r.ok, name: r.name.trim() }; + return { id: r.id, ok: r.ok, name: trim(r.name) }; } else { return r; diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index bd2a4f1b..48b1c0f1 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -1,5 +1,6 @@ var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('timeoutAfter test', function (tt) { tt.plan(1); @@ -12,7 +13,7 @@ tap.test('timeoutAfter test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); diff --git a/test/too_many.js b/test/too_many.js index b5c38819..56c2225a 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -1,6 +1,7 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); +var trim = require('string.prototype.trim'); tap.test('array test', function (tt) { tt.plan(1); @@ -13,7 +14,7 @@ tap.test('array test', function (tt) { tc.on('end', function () { var rs = rows.map(function (r) { if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; + return { id : r.id, ok : r.ok, name : trim(r.name) }; } else return r; }); From 0dc93136f0e6e1ae83a9cb5e1117b72028fd9d47 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 2 Oct 2015 01:38:51 -0700 Subject: [PATCH 194/373] v4.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd703a96..c3c0e22b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.2.0", + "version": "4.2.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From c652069d519a760630fb8d94672acc35819e9d32 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Tue, 20 Oct 2015 16:46:02 -0700 Subject: [PATCH 195/373] Move timeout option to run time, not load time --- lib/test.js | 8 ++++---- test/timeout.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/timeout.js diff --git a/lib/test.js b/lib/test.js index 6c91b0e2..61ddace7 100644 --- a/lib/test.js +++ b/lib/test.js @@ -48,15 +48,12 @@ function Test (name_, opts_, cb_) { this.assertCount = 0; this.pendingCount = 0; this._skip = args.opts.skip || false; + this._timeout = args.opts.timeout; this._plan = undefined; this._cb = args.cb; this._progeny = []; this._ok = true; - if (args.opts.timeout !== undefined) { - this.timeoutAfter(args.opts.timeout); - } - for (var prop in this) { this[prop] = (function bind(self, val) { if (typeof val === 'function') { @@ -73,6 +70,9 @@ Test.prototype.run = function () { if (!this._cb || this._skip) { return this._end(); } + if (this._timeout != null) { + this.timeoutAfter(this._timeout); + } this.emit('prerun'); this._cb(this); this.emit('run'); diff --git a/test/timeout.js b/test/timeout.js new file mode 100644 index 00000000..9f4cd825 --- /dev/null +++ b/test/timeout.js @@ -0,0 +1,15 @@ +var test = require('../'); +var ran = 0; + +test('timeout', function(t) { + 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(); +}); From 7aac086eaf0c85ad14d91c4e6e28b9c9bb6f4d3c Mon Sep 17 00:00:00 2001 From: Raynos Date: Tue, 20 Oct 2015 18:12:05 -0700 Subject: [PATCH 196/373] 4.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3c0e22b..0be3595b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.2.1", + "version": "4.2.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 5be37fad35c2a861875da9362f52726d0bb60b69 Mon Sep 17 00:00:00 2001 From: Ethan Cohen Date: Sun, 25 Oct 2015 08:35:41 -0700 Subject: [PATCH 197/373] Add ES6 support link to documentation. Running tests as mentioned in https://github.com/substack/tape/issues/102 does not cover some of the important es6 features that transpilation does. This is a great tool by @wavded and I think should be included in the docs! --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index c5751ce8..85082cb7 100644 --- a/readme.markdown +++ b/readme.markdown @@ -101,6 +101,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - CoffeeScript support with https://www.npmjs.com/package/coffeetape - Promise support with https://www.npmjs.com/package/blue-tape +- ES6 support with https://www.npmjs.com/package/babel-tape-runner # methods From b09c92e266f4a65310e596ab017dab7c3db467b2 Mon Sep 17 00:00:00 2001 From: Roald de Vries Date: Fri, 13 Nov 2015 11:45:01 +0100 Subject: [PATCH 198/373] add tape.tearDown handler Fixes #175 --- index.js | 8 ++++++++ test/tearDown.js | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/tearDown.js diff --git a/index.js b/index.js index 2bf2d328..f3f70f98 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,10 @@ exports = module.exports = (function () { } return harness.createStream(opts); }; + + lazyLoad.tearDown = function () { + return getHarness().tearDown.apply(this, arguments); + }; lazyLoad.getHarness = getHarness @@ -126,6 +130,10 @@ function createHarness (conf_) { test.createStream = function (opts) { return results.createStream(opts); }; + + test.tearDown = function (cb) { + results.on('done', cb); + }; var only = false; test.only = function (name) { diff --git a/test/tearDown.js b/test/tearDown.js new file mode 100644 index 00000000..13fe7ea5 --- /dev/null +++ b/test/tearDown.js @@ -0,0 +1,12 @@ +var tap = require("tap"); +var tape = require("../"); + +tap.test("tear down", {timeout: 1000}, function (tt) { + tt.plan(1); + tape.tearDown(function() { + tt.pass('tape ended'); + }); + tape('dummy test', function(t) { + t.end(); + }); +}); From b01c08bd852a5385eb62ffa994c960b8d505a466 Mon Sep 17 00:00:00 2001 From: Roald de Vries Date: Sat, 14 Nov 2015 00:19:03 +0100 Subject: [PATCH 199/373] rename tearDown to onFinish Fixes #175 --- index.js | 6 +++--- test/{tearDown.js => onFinish.js} | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename test/{tearDown.js => onFinish.js} (67%) diff --git a/index.js b/index.js index f3f70f98..2f067ae3 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,8 @@ exports = module.exports = (function () { return harness.createStream(opts); }; - lazyLoad.tearDown = function () { - return getHarness().tearDown.apply(this, arguments); + lazyLoad.onFinish = function () { + return getHarness().onFinish.apply(this, arguments); }; lazyLoad.getHarness = getHarness @@ -131,7 +131,7 @@ function createHarness (conf_) { return results.createStream(opts); }; - test.tearDown = function (cb) { + test.onFinish = function (cb) { results.on('done', cb); }; diff --git a/test/tearDown.js b/test/onFinish.js similarity index 67% rename from test/tearDown.js rename to test/onFinish.js index 13fe7ea5..5b77fae2 100644 --- a/test/tearDown.js +++ b/test/onFinish.js @@ -1,9 +1,9 @@ var tap = require("tap"); var tape = require("../"); -tap.test("tear down", {timeout: 1000}, function (tt) { +tap.test("on finish", {timeout: 1000}, function (tt) { tt.plan(1); - tape.tearDown(function() { + tape.onFinish(function() { tt.pass('tape ended'); }); tape('dummy test', function(t) { From 3ed9b91616426ac0ab5dc16274019ce70a5b3e2c Mon Sep 17 00:00:00 2001 From: axross Date: Sun, 15 Nov 2015 14:05:07 +0900 Subject: [PATCH 200/373] Remove unneeded whitespaces in README --- readme.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.markdown b/readme.markdown index 85082cb7..47603a2c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -15,10 +15,10 @@ var test = require('tape'); test('timing test', function (t) { t.plan(2); - + t.equal(typeof Date.now, 'function'); var start = Date.now(); - + setTimeout(function () { t.equal(Date.now() - start, 100); }, 100); @@ -114,13 +114,13 @@ var test = require('tape') ## test([name], [opts], cb) -Create a new test with an optional `name` string and optional `opts` object. +Create a new test with an optional `name` string and optional `opts` object. `cb(t)` fires with the new test object `t` once all preceeding tests have finished. Tests execute serially. Available `opts` options are: - opts.skip = true/false. See test.skip. -- opts.timeout = 500. Set a timeout for the test, after which it will fail. +- opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. If you forget to `t.plan()` out how many assertions you are going to run and you @@ -154,7 +154,7 @@ Generate a passing assertion with a message `msg`. Automatically timeout the test after X ms. ## t.skip(msg) - + Generate an assertion that will be skipped over. ## t.ok(value, msg) From 77a2bbb40397d66557bf1c7aa3cdee8b30adbd5c Mon Sep 17 00:00:00 2001 From: axross Date: Sun, 15 Nov 2015 14:05:44 +0900 Subject: [PATCH 201/373] Add "tap-diff" and "tap-notify" to README --- readme.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.markdown b/readme.markdown index 47603a2c..f23b8361 100644 --- a/readme.markdown +++ b/readme.markdown @@ -89,6 +89,8 @@ that will output something pretty if you pipe TAP into them: - https://github.com/aghassemi/tap-xunit - https://github.com/namuol/tap-difflet - https://github.com/gritzko/tape-dom + - https://github.com/axross/tap-diff + - https://github.com/axross/tap-notify To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From 35c6c089034add8ea6f47ef9f0d3a58e6c94dce7 Mon Sep 17 00:00:00 2001 From: axross Date: Mon, 16 Nov 2015 15:49:53 +0900 Subject: [PATCH 202/373] Revert "Remove unneeded whitespaces in README" This reverts commit 3ed9b91616426ac0ab5dc16274019ce70a5b3e2c. --- readme.markdown | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.markdown b/readme.markdown index f23b8361..ca774862 100644 --- a/readme.markdown +++ b/readme.markdown @@ -15,10 +15,10 @@ var test = require('tape'); test('timing test', function (t) { t.plan(2); - + t.equal(typeof Date.now, 'function'); var start = Date.now(); - + setTimeout(function () { t.equal(Date.now() - start, 100); }, 100); @@ -116,13 +116,13 @@ var test = require('tape') ## test([name], [opts], cb) -Create a new test with an optional `name` string and optional `opts` object. +Create a new test with an optional `name` string and optional `opts` object. `cb(t)` fires with the new test object `t` once all preceeding tests have finished. Tests execute serially. Available `opts` options are: - opts.skip = true/false. See test.skip. -- opts.timeout = 500. Set a timeout for the test, after which it will fail. +- opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. If you forget to `t.plan()` out how many assertions you are going to run and you @@ -156,7 +156,7 @@ Generate a passing assertion with a message `msg`. Automatically timeout the test after X ms. ## t.skip(msg) - + Generate an assertion that will be skipped over. ## t.ok(value, msg) From 367db82778bc2bf4e273cf9a8e6b5902c4b582fb Mon Sep 17 00:00:00 2001 From: taylorhakes Date: Sat, 21 Nov 2015 17:38:22 -0500 Subject: [PATCH 203/373] Removed unreachable Results.prototype.only code --- lib/results.js | 5 ----- test/only-twice.js | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/only-twice.js diff --git a/lib/results.js b/lib/results.js index 9a494094..7393128d 100644 --- a/lib/results.js +++ b/lib/results.js @@ -84,11 +84,6 @@ Results.prototype.push = function (t) { }; Results.prototype.only = function (name) { - if (this._only) { - self.count ++; - self.fail ++; - write('not ok ' + self.count + ' already called .only()\n'); - } this._only = name; }; diff --git a/test/only-twice.js b/test/only-twice.js new file mode 100644 index 00000000..ce6048ef --- /dev/null +++ b/test/only-twice.js @@ -0,0 +1,21 @@ +var tape = require('../'); +var tap = require('tap'); + +tap.test('only twice error', function (assert) { + var test = tape.createHarness({ exit : false }); + + 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(); +}); + From 737aa4273e43e5c5faa825729c4f5ecb2e3ab519 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Sat, 19 Dec 2015 21:43:29 +0100 Subject: [PATCH 204/373] Added rudimentary source map support The `source-map-support` module enables some rudimentary support for source maps in call stacks, which greatly enhances the developer experience of working with compiled code. --- bin/tape | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/tape b/bin/tape index 500f1b14..8101d1a2 100755 --- a/bin/tape +++ b/bin/tape @@ -1,4 +1,5 @@ #!/usr/bin/env node +require('source-map-support/register'); var path = require('path'); var glob = require('glob'); diff --git a/package.json b/package.json index 0be3595b..66dc0eb9 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "inherits": "~2.0.1", "object-inspect": "~1.0.0", "resumer": "~0.0.0", + "source-map-support": "~0.4.0", "string.prototype.trim": "^1.1.1", "through": "~2.3.4" }, From 3f02033f6024a526951ed6ad7606bdcb6d589f91 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 19:56:05 +0100 Subject: [PATCH 205/373] Revert "Added rudimentary source map support" This reverts commit 737aa4273e43e5c5faa825729c4f5ecb2e3ab519. --- bin/tape | 1 - package.json | 1 - 2 files changed, 2 deletions(-) diff --git a/bin/tape b/bin/tape index 8101d1a2..500f1b14 100755 --- a/bin/tape +++ b/bin/tape @@ -1,5 +1,4 @@ #!/usr/bin/env node -require('source-map-support/register'); var path = require('path'); var glob = require('glob'); diff --git a/package.json b/package.json index 66dc0eb9..0be3595b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "inherits": "~2.0.1", "object-inspect": "~1.0.0", "resumer": "~0.0.0", - "source-map-support": "~0.4.0", "string.prototype.trim": "^1.1.1", "through": "~2.3.4" }, From 7ae60f5ff63b6bfd9c7811eb8977ed60bfeaa5ac Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 21:53:03 +0100 Subject: [PATCH 206/373] This implements `-r` and `--require` as command line options @Raynos accurately pointed out that the source map support was a bit too specific, and felt outside of the purview of tape. As a more general solution, this implements the `-r` and `--require` CLI flags, which will allow a user to load node modules before any tests are run. For example, if someon wants to enable source map support in node, they might do: tape -r source-map-support/register test/*.js --- bin/tape | 26 +++++++++++-- package.json | 2 + test/require.js | 83 ++++++++++++++++++++++++++++++++++++++++++ test/require/a.js | 8 ++++ test/require/b.js | 8 ++++ test/require/test-a.js | 7 ++++ test/require/test-b.js | 7 ++++ 7 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 test/require.js create mode 100644 test/require/a.js create mode 100644 test/require/b.js create mode 100644 test/require/test-a.js create mode 100644 test/require/test-b.js diff --git a/bin/tape b/bin/tape index 500f1b14..df3f0c1f 100755 --- a/bin/tape +++ b/bin/tape @@ -1,12 +1,32 @@ #!/usr/bin/env node -var path = require('path'); +var resolveModule = require('resolve').sync; +var resolvePath = require('path').resolve; +var parseOpts = require('minimist'); var glob = require('glob'); -process.argv.slice(2).forEach(function (arg) { +var opts = parseOpts(process.argv.slice(2), { + alias: { 'r': 'require' }, + string: 'require', + default: {'r': [] } + }); + +var cwd = process.cwd(); + +/* If only one require is specified, the value of `opts.require` + * will be a string. This is why we concatenate. + */ +;[].concat(opts.require).forEach(function(module) { + /* The `module &&` ensures we ignore `-r ""`, trailing `-r` or other + * silly things the user might (inadvertedly) be doing. + */ + module && require(resolveModule(module, { basedir: cwd })); +}); + +opts._.forEach(function (arg) { glob(arg, function (err, files) { files.forEach(function (file) { - require(path.resolve(process.cwd(), file)); + require(resolvePath(cwd, file)); }); }); }); diff --git a/package.json b/package.json index 0be3595b..66a65290 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "glob": "~5.0.3", "has": "~1.0.1", "inherits": "~2.0.1", + "minimist": "1.2.0", "object-inspect": "~1.0.0", + "resolve": "1.1.6", "resumer": "~0.0.0", "string.prototype.trim": "^1.1.1", "through": "~2.3.4" diff --git a/test/require.js b/test/require.js new file mode 100644 index 00000000..0385ea45 --- /dev/null +++ b/test/require.js @@ -0,0 +1,83 @@ +var tap = require('tap'); +var spawn = require('child_process').spawn; +var trim = require('string.prototype.trim'); + +tap.test('requiring a single module', function (t) { + t.plan(2); + + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : trim(r.name) }; + } + else return r; + }); + t.same(rs, [ + 'TAP version 13', + 'module-a', + { id: 1, ok: true, name: 'loaded module a' }, + 'test-a', + { id: 2, ok: true, name: 'module-a loaded in same context'}, + { id: 3, ok: true, name: 'test ran after module-a was loaded'}, + 'tests 3', + 'pass 3', + 'ok' + ]); + }); + + var ps = tape('-r ./require/a require/test-a.js'); + ps.stdout.pipe(tc); + ps.on('exit', function (code) { + t.equal(code, 0); + }); +}); + +tap.test('requiring multiple modules', function (t) { + t.plan(2); + + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : trim(r.name) }; + } + else return r; + }); + t.same(rs, [ + 'TAP version 13', + 'module-a', + { id: 1, ok: true, name: 'loaded module a' }, + 'module-b', + { id: 2, ok: true, name: 'loaded module b' }, + 'test-a', + { id: 3, ok: true, name: 'module-a loaded in same context'}, + { id: 4, ok: true, name: 'test ran after module-a was loaded'}, + 'test-b', + { id: 5, ok: true, name: 'module-b loaded in same context'}, + { id: 6, ok: true, name: 'test ran after module-b was loaded'}, + 'tests 6', + 'pass 6', + 'ok' + ]); + }); + + var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js'); + ps.stdout.pipe(tc); + ps.on('exit', function (code) { + t.equal(code, 0); + }); +}); + +function tape(args) { + var proc = require('child_process') + var bin = __dirname + '/../bin/tape' + + return proc.spawn(bin, args.split(' '), { cwd: __dirname }) +} \ No newline at end of file diff --git a/test/require/a.js b/test/require/a.js new file mode 100644 index 00000000..0947b7b9 --- /dev/null +++ b/test/require/a.js @@ -0,0 +1,8 @@ +var tape = require('../..'); + +tape.test('module-a', function(t) { + t.pass('loaded module a') + t.end() +}) + +global.module_a = true \ No newline at end of file diff --git a/test/require/b.js b/test/require/b.js new file mode 100644 index 00000000..18942e0c --- /dev/null +++ b/test/require/b.js @@ -0,0 +1,8 @@ +var tape = require('../..'); + +tape.test('module-b', function(t) { + t.pass('loaded module b') + t.end() +}) + +global.module_b = true \ No newline at end of file diff --git a/test/require/test-a.js b/test/require/test-a.js new file mode 100644 index 00000000..822ef540 --- /dev/null +++ b/test/require/test-a.js @@ -0,0 +1,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() +}) \ No newline at end of file diff --git a/test/require/test-b.js b/test/require/test-b.js new file mode 100644 index 00000000..8efcba1c --- /dev/null +++ b/test/require/test-b.js @@ -0,0 +1,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() +}) \ No newline at end of file From 4f81dbc5f9344b3dc9d56943d96249577d39f852 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 22:59:44 +0100 Subject: [PATCH 207/373] Use ~ for minimist and resolve dependency versions. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 66a65290..892dfca5 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ "glob": "~5.0.3", "has": "~1.0.1", "inherits": "~2.0.1", - "minimist": "1.2.0", + "minimist": "~1.2.0", "object-inspect": "~1.0.0", - "resolve": "1.1.6", + "resolve": "~1.1.6", "resumer": "~0.0.0", "string.prototype.trim": "^1.1.1", "through": "~2.3.4" From d0ca885a1f1e646a886aaae243c40ae03b3cc94f Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:00:21 +0100 Subject: [PATCH 208/373] Make single require check more readable --- bin/tape | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/tape b/bin/tape index df3f0c1f..a910b8f9 100755 --- a/bin/tape +++ b/bin/tape @@ -13,10 +13,11 @@ var opts = parseOpts(process.argv.slice(2), { var cwd = process.cwd(); -/* If only one require is specified, the value of `opts.require` - * will be a string. This is why we concatenate. - */ -;[].concat(opts.require).forEach(function(module) { +if (typeof opts.require === 'string') { + opts.require = [opts.require]; +} + +opts.require.forEach(function(module) { /* The `module &&` ensures we ignore `-r ""`, trailing `-r` or other * silly things the user might (inadvertedly) be doing. */ From 096d2e70bf7c73123156f6ffe3044e81adce7e1b Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:20:11 +0100 Subject: [PATCH 209/373] Add `-r,--require` documentation to README.md This can probably be done better, but I think it covers all aspects of this feature. --- readme.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/readme.markdown b/readme.markdown index ca774862..04368de0 100644 --- a/readme.markdown +++ b/readme.markdown @@ -64,6 +64,26 @@ $ tape 'tests/**/*.js' $ tape "tests/**/*.js" ``` +## Preloading modules + +Additionally, it is possible to make `tape` load one or more modules before running any tests, by using the `-r` or `--require` flag. Here's an example that loads [babel-register](http://babeljs.io/docs/usage/require/) before running any tests, to allow for JIT compilation: + +```sh +$ tape -r babel-register tests/**/*.js +``` + +Depending on the module you're loading, you may be able to paramaterize it using environment variables or auxiliary files. Babel, for instance, will load options from [`.babelrc`](http://babeljs.io/docs/usage/babelrc/) at runtime. + +The `-r` flag behaves exactly like node's `require`, and uses the same module resolution algorithm. This means that if you need to load local modules, you have to prepend their path with `./` or `../` accordingly. + +For example: + +```sh +$ tape -r ./my/local/module tests/**/*.js +``` + +Please note that modules that all modules loaded using the `-r` flag will run *before* any tests, regardless of when they are specified. For example, `tape -r a b -r c` will actually load `a` and `c` *before` loading `b`, since they are flagged as required modules. + # things that go well with tape tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape. From 2e57f22b9690e828c42f6d3c28e22c3f01948ea7 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:33:58 +0100 Subject: [PATCH 210/373] Fix indent mistake --- bin/tape | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tape b/bin/tape index a910b8f9..cfa90a91 100755 --- a/bin/tape +++ b/bin/tape @@ -14,7 +14,7 @@ var opts = parseOpts(process.argv.slice(2), { var cwd = process.cwd(); if (typeof opts.require === 'string') { - opts.require = [opts.require]; + opts.require = [opts.require]; } opts.require.forEach(function(module) { From ffa503ad8acb22fe3108748189c0e1888511d8ba Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:35:10 +0100 Subject: [PATCH 211/373] Use regular ol' `if` instead of boolean operator in sanity check --- bin/tape | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/tape b/bin/tape index cfa90a91..215b9572 100755 --- a/bin/tape +++ b/bin/tape @@ -18,10 +18,11 @@ if (typeof opts.require === 'string') { } opts.require.forEach(function(module) { - /* The `module &&` ensures we ignore `-r ""`, trailing `-r` or other - * silly things the user might (inadvertedly) be doing. - */ - module && require(resolveModule(module, { basedir: cwd })); + if (module) { + /* This check ensures we ignore `-r ""`, trailing `-r`, or + * other silly things the user might (inadvertedly) be doing. */ + require(resolveModule(module, { basedir: cwd })); + } }); opts._.forEach(function (arg) { From 4077efe19fe914a4b344ce3da1710478bed5f734 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:36:57 +0100 Subject: [PATCH 212/373] Fix spelling mistake in comment --- bin/tape | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tape b/bin/tape index 215b9572..d5674d33 100755 --- a/bin/tape +++ b/bin/tape @@ -20,7 +20,7 @@ if (typeof opts.require === 'string') { opts.require.forEach(function(module) { if (module) { /* This check ensures we ignore `-r ""`, trailing `-r`, or - * other silly things the user might (inadvertedly) be doing. */ + * other silly things the user might (inadvertently) be doing. */ require(resolveModule(module, { basedir: cwd })); } }); From 9f02249f1e99f88eae26d39527768820f9b58c89 Mon Sep 17 00:00:00 2001 From: Marcus Stade Date: Mon, 21 Dec 2015 23:38:28 +0100 Subject: [PATCH 213/373] Unquote keys in object literals --- bin/tape | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/tape b/bin/tape index d5674d33..498910cd 100755 --- a/bin/tape +++ b/bin/tape @@ -6,9 +6,9 @@ var parseOpts = require('minimist'); var glob = require('glob'); var opts = parseOpts(process.argv.slice(2), { - alias: { 'r': 'require' }, + alias: { r: 'require' }, string: 'require', - default: {'r': [] } + default: { r: [] } }); var cwd = process.cwd(); From e00e9463b54ecc8ef25460af3c36f436a6a85cbc Mon Sep 17 00:00:00 2001 From: Raynos Date: Tue, 22 Dec 2015 16:20:07 -0800 Subject: [PATCH 214/373] 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 892dfca5..e09ad4af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.2.2", + "version": "4.3.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 279576302ab34ed93190eddbe7778fc712adca4f Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 25 Dec 2015 17:49:17 -0800 Subject: [PATCH 215/373] document onFinish hook --- readme.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.markdown b/readme.markdown index 04368de0..0d537d0c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -152,6 +152,11 @@ don't call `t.end()` explicitly, your test will hang. Generate a new test that will be skipped over. +## test.onFinish(fn) + +The onFinish hook will get invoked when ALL tape tests have finished +right before tape is about to print the test summary. + ## t.plan(n) Declare that `n` assertions should be run. `t.end()` will be called From 1b61c0bc0d5bdb8cea32b0064e3d8b701bbfab22 Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 25 Dec 2015 17:49:26 -0800 Subject: [PATCH 216/373] 4.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e09ad4af..924bc765 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.3.0", + "version": "4.4.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From cc3b58e632f9f5344bcc3e9637ab1c019e5d2d37 Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Sun, 27 Dec 2015 14:06:55 +0100 Subject: [PATCH 217/373] Exploratory comments to ascertain current behavior Since there were no tests for t.comment(), which I'm going to modify, I want to make sure of what the current behaviour is, to ensure I don't change more than I need to. --- test/comment.js | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/comment.js diff --git a/test/comment.js b/test/comment.js new file mode 100644 index 00000000..7cfcf02b --- /dev/null +++ b/test/comment.js @@ -0,0 +1,141 @@ +var concat = require('concat-stream'); +var tap = require('tap'); +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.equal(output.toString('utf8'), [ + 'TAP version 13', + '# no comment', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' + ].join('\n')); + }; + + 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(2); + var test = tape.createHarness(); + test.createStream(); + test('missing argument', function (t) { + try { + t.comment(); + t.end(); + } catch (err) { + assert.equal(err.constructor, TypeError); + assert.equal(err.message, 'Cannot call method on undefined'); + } finally { + assert.end(); + } + }); +}); + +// Exploratory test, can we call t.comment() passing nothing? +tap.test('null argument', function (assert) { + assert.plan(2); + var test = tape.createHarness(); + test.createStream(); + test('null argument', function (t) { + try { + t.comment(null); + t.end(); + } catch (err) { + assert.equal(err.constructor, TypeError); + assert.equal(err.message, 'Cannot call method on null'); + } 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(); + }); +}); + +// 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(); + }); +}); From 0132b1db156fae25bb40dc09ec178217a1be4d0a Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Sun, 27 Dec 2015 14:11:23 +0100 Subject: [PATCH 218/373] Failing test for new functionality --- test/comment.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/comment.js b/test/comment.js index 7cfcf02b..f88a669f 100644 --- a/test/comment.js +++ b/test/comment.js @@ -139,3 +139,33 @@ tap.test('non-string types', function (assert) { 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', + '', + '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.end(); + }); +}); From 9c00faf07331c6e4a14f5cb3df58cb0252f74b51 Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Sun, 27 Dec 2015 14:16:10 +0100 Subject: [PATCH 219/373] Multiline comments --- lib/test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 61ddace7..7c288bb6 100644 --- a/lib/test.js +++ b/lib/test.js @@ -102,7 +102,10 @@ Test.prototype.test = function (name, opts, cb) { }; Test.prototype.comment = function (msg) { - this.emit('result', trim(msg).replace(/^#\s*/, '')); + var that = this; + String(trim(msg)).split('\n').forEach(function (aMsg) { + that.emit('result', trim(aMsg).replace(/^#\s*/, '')); + }); }; Test.prototype.plan = function (n) { From b8e4002d18559542af4117432d91a38e8f9ba63d Mon Sep 17 00:00:00 2001 From: Ben Lowery Date: Sun, 27 Dec 2015 17:53:11 -0500 Subject: [PATCH 220/373] Fix a typo in the README "all modules" was doubled up --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 0d537d0c..f07f2724 100644 --- a/readme.markdown +++ b/readme.markdown @@ -82,7 +82,7 @@ For example: $ tape -r ./my/local/module tests/**/*.js ``` -Please note that modules that all modules loaded using the `-r` flag will run *before* any tests, regardless of when they are specified. For example, `tape -r a b -r c` will actually load `a` and `c` *before` loading `b`, since they are flagged as required modules. +Please note that all modules loaded using the `-r` flag will run *before* any tests, regardless of when they are specified. For example, `tape -r a b -r c` will actually load `a` and `c` *before` loading `b`, since they are flagged as required modules. # things that go well with tape From 3a5417a1032287d35dad65d40c896b0bc625060f Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Tue, 29 Dec 2015 13:39:07 +0100 Subject: [PATCH 221/373] Removed unnecessary cast --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 7c288bb6..94a42a81 100644 --- a/lib/test.js +++ b/lib/test.js @@ -103,7 +103,7 @@ Test.prototype.test = function (name, opts, cb) { Test.prototype.comment = function (msg) { var that = this; - String(trim(msg)).split('\n').forEach(function (aMsg) { + trim(msg).split('\n').forEach(function (aMsg) { that.emit('result', trim(aMsg).replace(/^#\s*/, '')); }); }; From c66f25e32696df21a7f59153ea3e7db3480fcc4e Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Tue, 29 Dec 2015 13:44:49 +0100 Subject: [PATCH 222/373] Added test case for Windows line endings --- test/comment.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/comment.js b/test/comment.js index f88a669f..621ad970 100644 --- a/test/comment.js +++ b/test/comment.js @@ -149,6 +149,8 @@ tap.test('multiline string', function (assert) { '# multiline strings', '# a', '# b', + '# c', + '# d', '', '1..0', '# tests 0', @@ -166,6 +168,10 @@ tap.test('multiline string', function (assert) { 'a', 'b', ].join('\n')); + t.comment([ + 'c', + 'd', + ].join('\r\n')); t.end(); }); }); From 0dd9036c974fc9cfc39829b46c7534461a968fb5 Mon Sep 17 00:00:00 2001 From: Raynos Date: Wed, 30 Dec 2015 18:12:09 -0800 Subject: [PATCH 223/373] 4.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 924bc765..04b02ccc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.4.0", + "version": "4.4.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 69dada15d940f9925e4e9a4ff6c71039d497c2cd Mon Sep 17 00:00:00 2001 From: Josh Gillies Date: Wed, 6 Jan 2016 21:18:22 +1100 Subject: [PATCH 224/373] Fix readme formatting --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index f07f2724..56503537 100644 --- a/readme.markdown +++ b/readme.markdown @@ -82,7 +82,7 @@ For example: $ tape -r ./my/local/module tests/**/*.js ``` -Please note that all modules loaded using the `-r` flag will run *before* any tests, regardless of when they are specified. For example, `tape -r a b -r c` will actually load `a` and `c` *before` loading `b`, since they are flagged as required modules. +Please note that all modules loaded using the `-r` flag will run *before* any tests, regardless of when they are specified. For example, `tape -r a b -r c` will actually load `a` and `c` *before* loading `b`, since they are flagged as required modules. # things that go well with tape From 40b50d2ff27925aa03e1e858fcab91ed3798f241 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Tue, 19 Jan 2016 16:18:40 +1100 Subject: [PATCH 225/373] Test on Node.js v0.10.x, v0.12.x, v4.x, and v5.x --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c17ea84..91b317ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,5 @@ language: node_js node_js: - "0.10" - "0.12" - - "iojs" - "4" + - "5" From 0f5144995a3bdd4eff81f294b7b8537116856a8a Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Wed, 20 Jan 2016 11:06:29 +1100 Subject: [PATCH 226/373] Add back iojs --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 91b317ca..54be8e39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,6 @@ language: node_js node_js: - "0.10" - "0.12" + - "iojs" - "4" - "5" From 95848f4a361168a429c1b16dc6988f90f8a413a0 Mon Sep 17 00:00:00 2001 From: Alexander Kurakin Date: Sat, 30 Jan 2016 12:16:58 +0300 Subject: [PATCH 227/373] Travis: Get rid of sudo --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 54be8e39..c415b239 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js +sudo: false node_js: - "0.10" - "0.12" From ba44de69977f243118076215674dbb309ad6ac6c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 13 Feb 2016 22:49:59 -0800 Subject: [PATCH 228/373] [Tests] remove unnecessary + failing Error message assertion Fixes #255 --- test/comment.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/comment.js b/test/comment.js index 621ad970..ab00690c 100644 --- a/test/comment.js +++ b/test/comment.js @@ -30,7 +30,7 @@ tap.test('no comment', function (assert) { // Exploratory test, can we call t.comment() passing nothing? tap.test('missing argument', function (assert) { - assert.plan(2); + assert.plan(1); var test = tape.createHarness(); test.createStream(); test('missing argument', function (t) { @@ -39,7 +39,6 @@ tap.test('missing argument', function (assert) { t.end(); } catch (err) { assert.equal(err.constructor, TypeError); - assert.equal(err.message, 'Cannot call method on undefined'); } finally { assert.end(); } @@ -48,7 +47,7 @@ tap.test('missing argument', function (assert) { // Exploratory test, can we call t.comment() passing nothing? tap.test('null argument', function (assert) { - assert.plan(2); + assert.plan(1); var test = tape.createHarness(); test.createStream(); test('null argument', function (t) { @@ -57,7 +56,6 @@ tap.test('null argument', function (assert) { t.end(); } catch (err) { assert.equal(err.constructor, TypeError); - assert.equal(err.message, 'Cannot call method on null'); } finally { assert.end(); } From 545db260ee27e7121eed42e963973038013b4bd4 Mon Sep 17 00:00:00 2001 From: ronkorving Date: Sun, 14 Feb 2016 16:01:02 +0900 Subject: [PATCH 229/373] doc: Explain opts in t.test --- readme.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 56503537..18b87d24 100644 --- a/readme.markdown +++ b/readme.markdown @@ -261,12 +261,14 @@ Assert that the function call `fn()` throws an exception. `expected`, if present Assert that the function call `fn()` does not throw an exception. -## t.test(name, cb) +## t.test(name, [opts], cb) Create a subtest with a new test handle `st` from `cb(st)` inside the current test `t`. `cb(st)` will only fire when `t` finishes. Additional tests queued up after `t` will not be run until all subtests finish. +You may pass the same options that [`test()`](#testname-opts-cb) accepts. + ## t.comment(message) Print a message without breaking the tap output. (Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.) From 13654addc410056b6dd48a35352deaa167b5bb98 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 14 Feb 2016 00:29:51 -0800 Subject: [PATCH 230/373] [Deps] update `deep-equal`, `function-bind`, `glob`, `object-inspect`, `resolve`, `string.prototype.trim`, `through` --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 04b02ccc..41c839c3 100644 --- a/package.json +++ b/package.json @@ -9,18 +9,18 @@ "test": "test" }, "dependencies": { - "deep-equal": "~1.0.0", + "deep-equal": "~1.0.1", "defined": "~1.0.0", - "function-bind": "~1.0.2", - "glob": "~5.0.3", + "function-bind": "~1.1.0", + "glob": "~7.0.0", "has": "~1.0.1", "inherits": "~2.0.1", "minimist": "~1.2.0", - "object-inspect": "~1.0.0", - "resolve": "~1.1.6", + "object-inspect": "~1.1.0", + "resolve": "~1.1.7", "resumer": "~0.0.0", - "string.prototype.trim": "^1.1.1", - "through": "~2.3.4" + "string.prototype.trim": "~1.1.2", + "through": "~2.3.8" }, "devDependencies": { "concat-stream": "~1.4.1", From 9a6b6559013ee732472b5e81bd106994121a068d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 14 Feb 2016 00:30:07 -0800 Subject: [PATCH 231/373] [Dev Deps] update `concat-stream`, `falafel`, `js-yaml`, `tap-parser` --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 41c839c3..b97aeb87 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "through": "~2.3.8" }, "devDependencies": { - "concat-stream": "~1.4.1", - "falafel": "~1.0.1", - "js-yaml": "^3.3.1", + "concat-stream": "~1.5.1", + "falafel": "~1.2.0", + "js-yaml": "~3.5.3", "tap": "~0.7.1", - "tap-parser": "^1.1.6" + "tap-parser": "~1.2.2" }, "scripts": { "test": "tap test/*.js" From 40be68520fedee580462bfaa7e91651154a65bea Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 14 Feb 2016 09:27:58 -0800 Subject: [PATCH 232/373] =?UTF-8?q?[Tests]=20building=20C=20extensions=20o?= =?UTF-8?q?n=20iojs=203=20and=20greater=20doesn=E2=80=99t=20work=20on=20a?= =?UTF-8?q?=20stock=20sudoless=20travis-ci=20VM.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts #244. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c415b239..fc1270d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js -sudo: false +sudo: true node_js: - "0.10" - "0.12" From 1414948acaeb0a3b39e77b78a0ea94725756142c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 28 Feb 2016 23:49:32 -0800 Subject: [PATCH 233/373] =?UTF-8?q?[New]=20Skipped=20test=20blocks=20shoul?= =?UTF-8?q?d=20output=20a=20=E2=80=9CSKIP=E2=80=9D=20message.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/test.js | 3 +++ test/skip.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/test.js b/lib/test.js index 94a42a81..4dcc7f8b 100644 --- a/lib/test.js +++ b/lib/test.js @@ -67,6 +67,9 @@ function Test (name_, opts_, cb_) { } Test.prototype.run = function () { + if (this._skip) { + this.comment('SKIP ' + this.name); + } if (!this._cb || this._skip) { return this._end(); } diff --git a/test/skip.js b/test/skip.js index 7b23126c..73d97f20 100644 --- a/test/skip.js +++ b/test/skip.js @@ -1,6 +1,34 @@ var test = require('../'); var ran = 0; +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(); + }); +}); + + test('do not skip this', { skip: false }, function(t) { t.pass('this should run'); ran ++; From 3227068bdf49a7d4a42e3e151e009d17c83d90aa Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 2 Mar 2016 14:36:34 -0800 Subject: [PATCH 234/373] v4.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b97aeb87..50637915 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.4.1", + "version": "4.5.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 472b517f00d98f94d03c0c6741ef8f1de322e0ec Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Mar 2016 01:03:23 -0800 Subject: [PATCH 235/373] Ensure that non-functions passed to `throws` fail the test, just like `assert` Fixes #267 --- lib/test.js | 2 +- test/throws.js | 123 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 5 deletions(-) diff --git a/lib/test.js b/lib/test.js index 4dcc7f8b..78b9763d 100644 --- a/lib/test.js +++ b/lib/test.js @@ -458,7 +458,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { caught.error = caught.error.constructor; } - this._assert(passed, { + this._assert(typeof fn === 'function' && passed, { message : defined(msg, 'should throw'), operator : 'throws', actual : caught && caught.error, diff --git a/test/throws.js b/test/throws.js index ec91fb8d..b8cf056f 100644 --- a/test/throws.js +++ b/test/throws.js @@ -1,20 +1,135 @@ -var test = require('../'); +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); function fn() { throw new TypeError('RegExp'); } -test('throws', function (t) { +function getNonFunctionMessage(fn) { + try { + fn(); + } catch (e) { + return e.message; + } +} + +tape('throws', function (t) { t.throws(fn); t.end(); }); -test('throws (RegExp match)', function (t) { +tape('throws (RegExp match)', function (t) { t.throws(fn, /RegExp/); t.end(); }); -test('throws (Function match)', function (t) { +tape('throws (Function match)', function (t) { t.throws(fn, TypeError); t.end(); }); + +tap.test('failures', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# non functions\n' + + 'not ok 1 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' ...\n' + + 'not ok 2 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' ...\n' + + 'not ok 3 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' ...\n' + + 'not ok 4 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' ...\n' + + 'not ok 5 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' ...\n' + + 'not ok 6 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' ...\n' + + 'not ok 7 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' ...\n' + + 'not ok 8 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' ...\n' + + '# function\n' + + 'not ok 9 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: undefined\n' + + ' actual: undefined\n' + + ' ...\n\n' + + '1..9\n' + + '# tests 9\n' + + '# pass 0\n' + + '# fail 9\n' + ); + })); + + 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 () {}); + }); +}); From ed40dc8d890ada1a529370d706a03e1e87cc1f19 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:18:59 -0800 Subject: [PATCH 236/373] v4.5.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 50637915..48072960 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.5.0", + "version": "4.5.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 772875274843740e183bebbea0d9db61a6be8285 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 15:43:24 -0800 Subject: [PATCH 237/373] [Tests] add some tests with `throws` and RegExp matching. Closes #269. --- test/throws.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/throws.js b/test/throws.js index b8cf056f..44ce1382 100644 --- a/test/throws.js +++ b/test/throws.js @@ -20,7 +20,10 @@ tape('throws', function (t) { }); tape('throws (RegExp match)', function (t) { - t.throws(fn, /RegExp/); + t.throws(fn, /RegExp/, 'regex with no anchors'); + t.throws(fn, /^TypeError: Reg/, 'regex with starting anchor'); + t.throws(fn, /RegExp$/, 'regex with ending anchor'); + t.throws(fn, /^TypeError: RegExp$/, 'regex with both anchors'); t.end(); }); From 5060034b6ceae1f08bc552029bab5bbc5199f7b9 Mon Sep 17 00:00:00 2001 From: Brendan Long Date: Thu, 24 Mar 2016 10:17:12 -0600 Subject: [PATCH 238/373] Add test for deep loose equal. --- test/deep.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/deep.js b/test/deep.js index 02f3681e..909ebe10 100644 --- a/test/deep.js +++ b/test/deep.js @@ -7,3 +7,11 @@ test('deep strict equal', function (t) { ); t.end(); }); + +test('deep loose equal', function (t) { + t.deepLooseEqual( + [ { a: '3' } ], + [ { a: 3 } ] + ); + t.end(); +}); From 91b639c360eef0c31a7b25e788311c7bfeb981a1 Mon Sep 17 00:00:00 2001 From: Paul C Pederson Date: Wed, 17 Feb 2016 10:53:47 -0800 Subject: [PATCH 239/373] add message defaults to .ok() and .notOk() --- lib/test.js | 4 ++-- test/default-messages.js | 37 ++++++++++++++++++++++++++++++++ test/exit.js | 4 ++-- test/messages/defaults.js | 12 +++++++++++ test/nested-sync-noplan-noend.js | 4 ++-- test/nested.js | 6 +++--- 6 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 test/default-messages.js create mode 100644 test/messages/defaults.js diff --git a/lib/test.js b/lib/test.js index 78b9763d..02237b79 100644 --- a/lib/test.js +++ b/lib/test.js @@ -302,7 +302,7 @@ Test.prototype.ok = Test.prototype.assert = function (value, msg, extra) { this._assert(value, { - message : msg, + message : defined(msg, 'should be truthy'), operator : 'ok', expected : true, actual : value, @@ -315,7 +315,7 @@ Test.prototype.notOk = Test.prototype.notok = function (value, msg, extra) { this._assert(!value, { - message : msg, + message : defined(msg, 'should be falsy'), operator : 'notOk', expected : false, actual : value, diff --git a/test/default-messages.js b/test/default-messages.js new file mode 100644 index 00000000..75ebc4c4 --- /dev/null +++ b/test/default-messages.js @@ -0,0 +1,37 @@ +var tap = require('tap'); +var spawn = require('child_process').spawn; +var trim = require('string.prototype.trim'); + +tap.test('default messages', function (t) { + t.plan(1); + + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : trim(r.name) }; + } + else return r; + }); + t.same(rs, [ + 'TAP version 13', + 'default messages', + { id: 1, ok: true, name: 'should be truthy' }, + { id: 2, ok: true, name: 'should be falsy' }, + { id: 3, ok: true, name: 'should be equal' }, + { id: 4, ok: true, name: 'should not be equal' }, + { id: 5, ok: true, name: 'should be equivalent' }, + { id: 6, ok: true, name: 'should be equivalent' }, + { id: 7, ok: true, name: 'should be equivalent' }, + 'tests 7', + 'pass 7', + 'ok' + ]); + }); + + var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]); + ps.stdout.pipe(tc); +}); diff --git a/test/exit.js b/test/exit.js index 02d2488b..b398ca12 100644 --- a/test/exit.js +++ b/test/exit.js @@ -126,9 +126,9 @@ tap.test('more planned in a second test', function (t) { t.same(rs, [ 'TAP version 13', 'first', - { id: 1, ok: true, name: '(unnamed assert)' }, + { id: 1, ok: true, name: 'should be truthy' }, 'second', - { id: 2, ok: true, name: '(unnamed assert)' }, + { id: 2, ok: true, name: 'should be truthy' }, { id: 3, ok: false, name: 'plan != count' }, 'tests 3', 'pass 2', diff --git a/test/messages/defaults.js b/test/messages/defaults.js new file mode 100644 index 00000000..8d842eb9 --- /dev/null +++ b/test/messages/defaults.js @@ -0,0 +1,12 @@ +var test = require('../../'); + +test('default messages', function (t) { + t.plan(7); + t.ok(true); + t.notOk(false); + t.equal(true, true); + t.notEqual(true, false); + t.deepEqual(true, true); + t.deepLooseEqual(true, true); + t.notDeepLooseEqual(true, false); +}); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 874f27b1..15b6883a 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -21,9 +21,9 @@ tap.test('nested sync test without plan or end', function (tt) { 'TAP version 13', 'nested without plan or end', 'first', - { id: 1, ok: true, name: '(unnamed assert)' }, + { id: 1, ok: true, name: 'should be truthy' }, 'second', - { id: 2, ok: true, name: '(unnamed assert)' }, + { id: 2, ok: true, name: 'should be truthy' }, 'tests 2', 'pass 2', 'ok' diff --git a/test/nested.js b/test/nested.js index 3b376385..5ac8a9d9 100644 --- a/test/nested.js +++ b/test/nested.js @@ -27,10 +27,10 @@ tap.test('array test', function (tt) { { id: 4, ok: true, name: 'should be equivalent' }, { id: 5, ok: true, name: 'should be equivalent' }, 'inside test', - { id: 6, ok: true, name: '(unnamed assert)' }, - { id: 7, ok: true, name: '(unnamed assert)' }, + { id: 6, ok: true, name: 'should be truthy' }, + { id: 7, ok: true, name: 'should be truthy' }, 'another', - { id: 8, ok: true, name: '(unnamed assert)' }, + { id: 8, ok: true, name: 'should be truthy' }, 'tests 8', 'pass 8', 'ok' From 5492dee269ee4af5bd19fd558a41badaa986641e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 9 Apr 2016 08:58:15 -0700 Subject: [PATCH 240/373] [Deps] update `glob`, `object-inspect` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 48072960..85dab908 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "function-bind": "~1.1.0", - "glob": "~7.0.0", + "glob": "~7.0.3", "has": "~1.0.1", "inherits": "~2.0.1", "minimist": "~1.2.0", - "object-inspect": "~1.1.0", + "object-inspect": "~1.2.1", "resolve": "~1.1.7", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", From b194ab17670a1dfbb3f9c99a638a46dd7e9b84e7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 9 Apr 2016 08:58:34 -0700 Subject: [PATCH 241/373] [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85dab908..36dbd8d5 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "devDependencies": { "concat-stream": "~1.5.1", "falafel": "~1.2.0", - "js-yaml": "~3.5.3", + "js-yaml": "~3.5.5", "tap": "~0.7.1", "tap-parser": "~1.2.2" }, From a2c0f2eff3b00c9057c243e2b57b673209d9aaf0 Mon Sep 17 00:00:00 2001 From: Alejandro Oviedo Date: Tue, 17 May 2016 11:14:26 -0300 Subject: [PATCH 242/373] link build badge to master branch and change it to svg --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 18b87d24..11585f5a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -4,7 +4,7 @@ tap-producing test harness for node and browsers [![browser support](https://ci.testling.com/substack/tape.png)](http://ci.testling.com/substack/tape) -[![build status](https://secure.travis-ci.org/substack/tape.png)](http://travis-ci.org/substack/tape) +[![build status](https://secure.travis-ci.org/substack/tape.svg?branch=master)](http://travis-ci.org/substack/tape) ![tape](http://substack.net/images/tape_drive.png) From 7ea6373848e37efb3acc3f4898f084d96d7994ee Mon Sep 17 00:00:00 2001 From: Jayson Harshbarger Date: Fri, 3 Jun 2016 00:08:10 +0900 Subject: [PATCH 243/373] Update readme.markdown Added tap-summary and tap-markdown to list of "pretty reporters" --- readme.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.markdown b/readme.markdown index 11585f5a..a3493bc5 100644 --- a/readme.markdown +++ b/readme.markdown @@ -111,6 +111,8 @@ that will output something pretty if you pipe TAP into them: - https://github.com/gritzko/tape-dom - https://github.com/axross/tap-diff - https://github.com/axross/tap-notify + - https://github.com/zoubin/tap-summary + - https://github.com/Hypercubed/tap-markdown To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From f2351cadbe98c4c01c3b45c42e704bcd01b1cd6d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 8 Jun 2016 14:03:50 -0700 Subject: [PATCH 244/373] [Robustness] be robust against the global `setTimeout` changing. Fixes #292. --- lib/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 02237b79..620c40f5 100644 --- a/lib/test.js +++ b/lib/test.js @@ -12,6 +12,7 @@ var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; +var safeSetTimeout = setTimeout; inherits(Test, EventEmitter); @@ -119,7 +120,7 @@ Test.prototype.plan = function (n) { Test.prototype.timeoutAfter = function(ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; - var timeout = setTimeout(function() { + var timeout = safeSetTimeout(function() { self.fail('test timed out after ' + ms + 'ms'); self.end(); }, ms); From a1969156ca4ed81ffc2cc338f8d905fb65ae1604 Mon Sep 17 00:00:00 2001 From: Scott Bessler Date: Mon, 13 Jun 2016 10:38:16 -0700 Subject: [PATCH 245/373] [results] make object-inspect depth configurable for expected/actual Allow to configure objectPrintDepth to avoid confusing output that shows expected/actual to be identical when the difference is >5 deep. --- lib/results.js | 4 +- lib/test.js | 4 +- readme.markdown | 8 +-- test/deep-equal-failure.js | 106 +++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 6 deletions(-) diff --git a/lib/results.js b/lib/results.js index 7393128d..e47c7d53 100644 --- a/lib/results.js +++ b/lib/results.js @@ -141,8 +141,8 @@ function encodeResult (res, count) { output += inner + 'operator: ' + res.operator + '\n'; if (has(res, 'expected') || has(res, 'actual')) { - var ex = inspect(res.expected); - var ac = inspect(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'; diff --git a/lib/test.js b/lib/test.js index 620c40f5..497c58a4 100644 --- a/lib/test.js +++ b/lib/test.js @@ -50,6 +50,7 @@ function Test (name_, opts_, cb_) { this.pendingCount = 0; this._skip = args.opts.skip || false; this._timeout = args.opts.timeout; + this._objectPrintDepth = args.opts.objectPrintDepth || 5; this._plan = undefined; this._cb = args.cb; this._progeny = []; @@ -198,7 +199,8 @@ Test.prototype._assert = function assert (ok, opts) { ok : Boolean(ok), skip : defined(extra.skip, opts.skip), name : defined(extra.message, opts.message, '(unnamed assert)'), - operator : defined(extra.operator, opts.operator) + operator : defined(extra.operator, opts.operator), + objectPrintDepth : self._objectPrintDepth }; if (has(opts, 'actual') || has(extra, 'actual')) { res.actual = defined(extra.actual, opts.actual); diff --git a/readme.markdown b/readme.markdown index a3493bc5..a5d41242 100644 --- a/readme.markdown +++ b/readme.markdown @@ -138,15 +138,17 @@ var test = require('tape') ## test([name], [opts], cb) -Create a new test with an optional `name` string and optional `opts` object. +Create a new test with an optional `name` string and optional `opts` object. `cb(t)` fires with the new test object `t` once all preceeding tests have finished. Tests execute serially. Available `opts` options are: - opts.skip = true/false. See test.skip. -- opts.timeout = 500. Set a timeout for the test, after which it will fail. +- opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. - +- opts.objectPrintDepth = 5. Configure max depth of expected / actual object + printing. + If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 2467f763..3f12b30e 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -57,6 +57,112 @@ tap.test('deep equal failure', function (assert) { }); }) +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.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# deep equal\n' + + 'not ok 1 should be equal\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: |-\n' + + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n' + + ' actual: |-\n' + + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + 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 equal', + diag: { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + } + }); + }); + + 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.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# deep equal\n' + + 'not ok 1 should be equal\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: |-\n' + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' actual: |-\n' + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + 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 equal', + diag: { + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + } + }); + }); + + test("deep equal", function (t) { + t.plan(1); + t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); + }); +}) + function getDiag (body) { var yamlStart = body.indexOf(' ---'); var yamlEnd = body.indexOf(' ...\n'); From 1f829546b7cfbc167d150c1594de19f6aaabca5c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 19 Jun 2016 22:55:25 -0700 Subject: [PATCH 246/373] [Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36dbd8d5..bceb8f7c 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "function-bind": "~1.1.0", - "glob": "~7.0.3", + "glob": "~7.0.4", "has": "~1.0.1", "inherits": "~2.0.1", "minimist": "~1.2.0", From 03bf9b63948df5e4733559f9db091543869bbe09 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 19 Jun 2016 22:55:35 -0700 Subject: [PATCH 247/373] [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bceb8f7c..9df4ade5 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "devDependencies": { "concat-stream": "~1.5.1", "falafel": "~1.2.0", - "js-yaml": "~3.5.5", + "js-yaml": "~3.6.1", "tap": "~0.7.1", "tap-parser": "~1.2.2" }, From 3c41af57070f9a6cedfb62e2a6d543b0b15e69ba Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 19 Jun 2016 22:57:49 -0700 Subject: [PATCH 248/373] v4.6.0 - [New] make object-inspect depth configurable for expected/actual (#293) - [New] add message defaults to .ok() and .notOk() (#261) - [Robustness] be robust against the global `setTimeout` changing (#292) - [Deps] update `glob`, `object-inspect` - [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9df4ade5..702b3901 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.5.1", + "version": "4.6.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From fb600eed777a8b4c712005eeda49b2edc0449a70 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 29 Jun 2016 13:26:14 -0800 Subject: [PATCH 249/373] [Dev Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 702b3901..011457b1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "function-bind": "~1.1.0", - "glob": "~7.0.4", + "glob": "~7.0.5", "has": "~1.0.1", "inherits": "~2.0.1", "minimist": "~1.2.0", From e532790dd690ac8936d642b1392b14cba91e2569 Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Sun, 17 Jul 2016 11:13:00 -0500 Subject: [PATCH 250/373] In docs, clarified when 'msg' describes the assertion. Also clarified 'expected' in throws(). --- readme.markdown | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/readme.markdown b/readme.markdown index a5d41242..a45db947 100644 --- a/readme.markdown +++ b/readme.markdown @@ -190,13 +190,13 @@ Generate an assertion that will be skipped over. ## t.ok(value, msg) -Assert that `value` is truthy with an optional description message `msg`. +Assert that `value` is truthy with an optional description of the assertion `msg`. Aliases: `t.true()`, `t.assert()` ## t.notOk(value, msg) -Assert that `value` is falsy with an optional description message `msg`. +Assert that `value` is falsy with an optional description of the assertion `msg`. Aliases: `t.false()`, `t.notok()` @@ -209,14 +209,14 @@ Aliases: `t.ifError()`, `t.ifErr()`, `t.iferror()` ## t.equal(actual, expected, msg) -Assert that `actual === expected` with an optional description `msg`. +Assert that `actual === expected` with an optional description of the assertion `msg`. Aliases: `t.equals()`, `t.isEqual()`, `t.is()`, `t.strictEqual()`, `t.strictEquals()` ## t.notEqual(actual, expected, msg) -Assert that `actual !== expected` with an optional description `msg`. +Assert that `actual !== expected` with an optional description of the assertion `msg`. Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNotEqual()`, `t.isNot()`, `t.not()`, `t.doesNotEqual()`, `t.isInequal()` @@ -225,8 +225,7 @@ Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, Assert that `actual` and `expected` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with strict comparisons (`===`) on leaf nodes and an optional description -`msg`. +with strict comparisons (`===`) on leaf nodes and an optional description of the assertion `msg`. Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.same()` @@ -234,8 +233,7 @@ Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.same()` Assert that `actual` and `expected` do not have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with strict comparisons (`===`) on leaf nodes and an optional description -`msg`. +with strict comparisons (`===`) on leaf nodes and an optional description of the assertion `msg`. Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, `t.isNotDeepEqual()`, `t.isNotDeeply()`, `t.isNotEquivalent()`, @@ -245,7 +243,7 @@ Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, Assert that `actual` and `expected` have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with loose comparisons (`==`) on leaf nodes and an optional description `msg`. +with loose comparisons (`==`) on leaf nodes and an optional description of the assertion `msg`. Aliases: `t.looseEqual()`, `t.looseEquals()` @@ -253,17 +251,17 @@ Aliases: `t.looseEqual()`, `t.looseEquals()` Assert that `actual` and `expected` do not have the same structure and nested values using [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) -with loose comparisons (`==`) on leaf nodes and an optional description `msg`. +with loose comparisons (`==`) on leaf nodes and an optional description of the assertion `msg`. Aliases: `t.notLooseEqual()`, `t.notLooseEquals()` ## t.throws(fn, expected, msg) -Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp` or `Function`. +Assert that the function call `fn()` throws an exception. `expected`, if present, must be a `RegExp` or `Function`. The `RegExp` matches the string representation of the exception, as generated by `err.toString()`. The `Function` is the exception thrown (e.g. `Error`). `msg` is an optional description of the assertion. ## t.doesNotThrow(fn, expected, msg) -Assert that the function call `fn()` does not throw an exception. +Assert that the function call `fn()` does not throw an exception. `msg` is an optional description of the assertion. ## t.test(name, [opts], cb) From 289b59005706dbedf572c9d209681656664c7bde Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Mon, 1 Aug 2016 17:16:45 -0500 Subject: [PATCH 251/373] .only now identifies tests by reference instead of by test name, fixing #299 --- index.js | 9 +++++---- lib/results.js | 7 ++++--- test/only4.js | 10 ++++++++++ test/only5.js | 10 ++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 test/only4.js create mode 100644 test/only5.js diff --git a/index.js b/index.js index 2f067ae3..8250d02b 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ function createExitHarness (conf) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; - if (only && t.name !== only) continue; + if (only && t !== only) continue; t._exit(); } } @@ -136,11 +136,12 @@ function createHarness (conf_) { }; var only = false; - test.only = function (name) { + test.only = function () { if (only) throw new Error('there can only be one only test'); - results.only(name); only = true; - return test.apply(null, arguments); + t = test.apply(null, arguments); + results.only(t); + return t; }; test._exitCode = 0; diff --git a/lib/results.js b/lib/results.js index e47c7d53..ec23bf2a 100644 --- a/lib/results.js +++ b/lib/results.js @@ -22,6 +22,7 @@ function Results () { this.pass = 0; this._stream = through(); this.tests = []; + this._only = 0; } Results.prototype.createStream = function (opts) { @@ -83,8 +84,8 @@ Results.prototype.push = function (t) { self.emit('_push', t); }; -Results.prototype.only = function (name) { - this._only = name; +Results.prototype.only = function (t) { + this._only = t; }; Results.prototype._watch = function (t) { @@ -176,7 +177,7 @@ function getNextTest (results) { do { var t = results.tests.shift(); if (!t) continue; - if (results._only === t.name) { + if (results._only === t) { return t; } } while (results.tests.length !== 0) diff --git a/test/only4.js b/test/only4.js new file mode 100644 index 00000000..d570b5bc --- /dev/null +++ b/test/only4.js @@ -0,0 +1,10 @@ +var test = require('../'); + +test('only4 duplicate test name', function (t) { + t.fail('not 1'); + t.end(); +}); + +test.only('only4 duplicate test name', function (t) { + t.end(); +}); diff --git a/test/only5.js b/test/only5.js new file mode 100644 index 00000000..0e158872 --- /dev/null +++ b/test/only5.js @@ -0,0 +1,10 @@ +var test = require('../'); + +test.only('only5 duplicate test name', function (t) { + t.end(); +}); + +test('only5 duplicate test name', function (t) { + t.fail('not 2'); + t.end(); +}); From 07da71b3e08d4f8c07e8c6e5796c1859a4f116ce Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Mon, 1 Aug 2016 18:44:13 -0500 Subject: [PATCH 252/373] initialized _only to null --- lib/results.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/results.js b/lib/results.js index ec23bf2a..efc60ce3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -22,7 +22,7 @@ function Results () { this.pass = 0; this._stream = through(); this.tests = []; - this._only = 0; + this._only = null; } Results.prototype.createStream = function (opts) { From d5e1a5ef42ae838951bdc41a9d494c6278576d75 Mon Sep 17 00:00:00 2001 From: Amila Welihinda Date: Wed, 3 Aug 2016 00:19:35 -0700 Subject: [PATCH 253/373] Added travis ci support for node 6 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index fc1270d1..a699c635 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,4 @@ node_js: - "iojs" - "4" - "5" + - "6" From 092344b906cd3774ba1812d2db431e77916c9f19 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 4 Aug 2016 22:10:58 -0700 Subject: [PATCH 254/373] Fix bug from #303 / 289b59005706dbedf572c9d209681656664c7bde --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8250d02b..f3ffcaee 100644 --- a/index.js +++ b/index.js @@ -139,7 +139,7 @@ function createHarness (conf_) { test.only = function () { if (only) throw new Error('there can only be one only test'); only = true; - t = test.apply(null, arguments); + var t = test.apply(null, arguments); results.only(t); return t; }; From 6978df4fde57d2cbab517f479794cf3f4a84f482 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Thu, 1 Sep 2016 14:13:18 -0400 Subject: [PATCH 255/373] Separate tap extensions by category Previously, we grouped most extensions (even tap-bail) into 'pretty reporters'. This groups extensions into human-friendly reporters, machine readable reporters, error handling, and other. This helps users discover extensions. --- readme.markdown | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/readme.markdown b/readme.markdown index a45db947..8b46c36b 100644 --- a/readme.markdown +++ b/readme.markdown @@ -88,7 +88,7 @@ Please note that all modules loaded using the `-r` flag will run *before* any te tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape. -## pretty reporters +## reporters for humans The default TAP output is good for machines and humans that are robots. @@ -98,26 +98,30 @@ that will output something pretty if you pipe TAP into them: - https://github.com/scottcorgan/tap-spec - https://github.com/scottcorgan/tap-dot - https://github.com/substack/faucet - - https://github.com/juliangruber/tap-bail - https://github.com/kirbysayshi/tap-browser-color - - https://github.com/gummesson/tap-json - https://github.com/gummesson/tap-min - https://github.com/calvinmetcalf/tap-nyan - - https://www.npmjs.org/package/tap-pessimist + - https://github.com/clux/tap-pessimist - https://github.com/toolness/tap-prettify - https://github.com/shuhei/colortape - - https://github.com/aghassemi/tap-xunit - https://github.com/namuol/tap-difflet - - https://github.com/gritzko/tape-dom - https://github.com/axross/tap-diff - https://github.com/axross/tap-notify - https://github.com/zoubin/tap-summary + +You use these reporters by piping the tape output into them. For example, +try `node test/index.js | tap-spec`. + +## reporters for other file formats + + - https://github.com/gummesson/tap-json + - https://github.com/aghassemi/tap-xunit + - https://github.com/gritzko/tape-dom - https://github.com/Hypercubed/tap-markdown -To use them, try `node test/index.js | tap-spec` or pipe it into one -of the modules of your choice! +## failing assertions -## uncaught exceptions +If any assertions fail, tape will continue. To terminate on the first failure, see [tap-bail](https://github.com/juliangruber/tap-bail). By default, uncaught exceptions in your tests will not be intercepted, and will cause tape to crash. If you find this behavior undesirable, use [tape-catch](https://github.com/michaelrhodes/tape-catch) to report any exceptions as TAP errors. @@ -126,6 +130,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - CoffeeScript support with https://www.npmjs.com/package/coffeetape - Promise support with https://www.npmjs.com/package/blue-tape - ES6 support with https://www.npmjs.com/package/babel-tape-runner +- Inclue time information with https://github.com/diasdavid/timed-tape # methods From 28a129987777560a1ae0a0e0832513d10f00dfc8 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:35:17 +0100 Subject: [PATCH 256/373] update tap & tap-parser to latest versions fixes #312 (update devDependencies) --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 011457b1..2450e446 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "concat-stream": "~1.5.1", "falafel": "~1.2.0", "js-yaml": "~3.6.1", - "tap": "~0.7.1", - "tap-parser": "~1.2.2" + "tap": "~7.0.0", + "tap-parser": "~2.0.0" }, "scripts": { "test": "tap test/*.js" From 00e595a511d0c15b7cf191c6e46ee3ea464d39ed Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:36:41 +0100 Subject: [PATCH 257/373] update test/array.js to use concat-stream instead of tap.createConsumer() (no longer available in tap v7) --- test/array.js | 56 ++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/test/array.js b/test/array.js index fbbff16e..dc4a4a40 100644 --- a/test/array.js +++ b/test/array.js @@ -1,61 +1,53 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - tt.same(rs, [ + + test.createStream().pipe(concat(function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: true, name: 'should be equivalent' }, - 'tests 5', - 'pass 5', - 'ok' - ]); - }); - - test.createStream().pipe(tc); - + '# array', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'ok 5 should be equivalent', + '', + '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); From eb30f50930eecfe49ca64a1ec41305bdca84358a Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:38:21 +0100 Subject: [PATCH 258/373] update test/default-messages.js to use concat-stream instead of tap.createConsumer() (no longer available in tap v7) #312 --- test/default-messages.js | 50 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/test/default-messages.js b/test/default-messages.js index 75ebc4c4..dcfdbffc 100644 --- a/test/default-messages.js +++ b/test/default-messages.js @@ -1,37 +1,31 @@ var tap = require('tap'); +var path = require('path'); var spawn = require('child_process').spawn; -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('default messages', function (t) { t.plan(1); - var tc = tap.createConsumer(); + var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ - 'TAP version 13', - 'default messages', - { id: 1, ok: true, name: 'should be truthy' }, - { id: 2, ok: true, name: 'should be falsy' }, - { id: 3, ok: true, name: 'should be equal' }, - { id: 4, ok: true, name: 'should not be equal' }, - { id: 5, ok: true, name: 'should be equivalent' }, - { id: 6, ok: true, name: 'should be equivalent' }, - { id: 7, ok: true, name: 'should be equivalent' }, - 'tests 7', - 'pass 7', - 'ok' - ]); - }); + ps.stdout.pipe(concat(function (rows) { - var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]); - ps.stdout.pipe(tc); + t.same(rows.toString('utf8'), [ + 'TAP version 13', + '# default messages', + 'ok 1 should be truthy', + 'ok 2 should be falsy', + 'ok 3 should be equal', + 'ok 4 should not be equal', + 'ok 5 should be equivalent', + 'ok 6 should be equivalent', + 'ok 7 should be equivalent', + '', + '1..7', + '# tests 7', + '# pass 7', + '', + '# ok' + ].join('\n') + '\n\n'); + })); }); From e3115ff6c23398c3a9486a51bebd41656e3d6f2e Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:40:38 +0100 Subject: [PATCH 259/373] update test/double_end.js to use path.join for cross-platform compatibility see: https://github.com/substack/tape/pull/314#discussion_r76651627 --- test/double_end.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/double_end.js b/test/double_end.js index c405d45e..624ce3ac 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -1,10 +1,11 @@ var test = require('tap').test; +var path = require('path'); var concat = require('concat-stream'); var spawn = require('child_process').spawn; test(function (t) { t.plan(2); - var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]); + var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]); ps.on('exit', function (code) { t.equal(code, 1); }); From 78e4ffd6e5108907ed1389546e78414d88e42cc4 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:46:04 +0100 Subject: [PATCH 260/373] update test/exit.js to use concat-stream instead of tap.createConsumer (method unvailable in tap v7) for #312 --- test/exit.js | 207 ++++++++++++++++++++++++--------------------------- 1 file changed, 97 insertions(+), 110 deletions(-) diff --git a/test/exit.js b/test/exit.js index b398ca12..963e6b08 100644 --- a/test/exit.js +++ b/test/exit.js @@ -1,38 +1,34 @@ var tap = require('tap'); +var path = require('path'); var spawn = require('child_process').spawn; -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('exit ok', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - 'hi', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: true, name: 'should be equivalent' }, - 'tests 5', - 'pass 5', - 'ok' - ]); - }); - - var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]); - ps.stdout.pipe(tc); + '# array', + '# hi', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'ok 5 should be equivalent', + '', + '1..5', + '# tests 5', + '# pass 5', + '', + '# ok', + '', // yes, these double-blank-lines at the end are required. + '' // if you can figure out how to remove them, please do! + ].join('\n')); + } + + var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'ok.js')]); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.equal(code, 0); }); @@ -40,34 +36,31 @@ tap.test('exit ok', function (t) { tap.test('exit fail', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: false, name: 'should be equivalent' }, - 'tests 5', - 'pass 4', - 'fail 1' - ]); - }); - - var ps = spawn(process.execPath, [ __dirname + '/exit/fail.js' ]); - ps.stdout.pipe(tc); + '# array', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'not ok 5 should be equivalent', + ' ---', + ' operator: deepEqual', + ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', + ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' ...', + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1' + ].join('\n') + '\n\n'); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.notEqual(code, 0); }); @@ -75,35 +68,32 @@ tap.test('exit fail', function (t) { tap.test('too few exit', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: true, name: 'should be equivalent' }, - { id: 6, ok: false, name: 'plan != count' }, - 'tests 6', - 'pass 5', - 'fail 1' - ]); - }); - - var ps = spawn(process.execPath, [ __dirname + '/exit/too_few.js' ]); - ps.stdout.pipe(tc); + '# array', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'ok 5 should be equivalent', + 'not ok 6 plan != count', + ' ---', + ' operator: fail', + ' expected: 6', + ' actual: 5', + ' ...', + '', + '1..6', + '# tests 6', + '# pass 5', + '# fail 1' + ].join('\n') + '\n\n'); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.notEqual(code, 0); }); @@ -111,33 +101,30 @@ tap.test('too few exit', function (t) { tap.test('more planned in a second test', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'first', - { id: 1, ok: true, name: 'should be truthy' }, - 'second', - { id: 2, ok: true, name: 'should be truthy' }, - { id: 3, ok: false, name: 'plan != count' }, - 'tests 3', - 'pass 2', - 'fail 1' - ]); - }); - - var ps = spawn(process.execPath, [ __dirname + '/exit/second.js' ]); - ps.stdout.pipe(tc); + '# first', + 'ok 1 should be truthy', + '# second', + 'ok 2 should be truthy', + 'not ok 3 plan != count', + ' ---', + ' operator: fail', + ' expected: 2', + ' actual: 1', + ' ...', + '', + '1..3', + '# tests 3', + '# pass 2', + '# fail 1' + ].join('\n') + '\n\n'); + }; + + var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.notEqual(code, 0); }); From be1088077b09d511eba5ce3704541801aa894028 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:49:25 +0100 Subject: [PATCH 261/373] update test/end-as-callback.js to use concat-stream instead of tap.createCosumer (method unavailable in tap v7) for #312 --- test/end-as-callback.js | 77 ++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/test/end-as-callback.js b/test/end-as-callback.js index df0bcbc3..09338c87 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -1,38 +1,29 @@ var tap = require("tap"); var tape = require("../"); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test("tape assert.end as callback", function (tt) { var test = tape.createHarness({ exit: false }) - var tc = tap.createConsumer() - - var rows = [] - tc.on("data", function (r) { rows.push(r) }) - tc.on("end", function () { - var rs = rows.map(function (r) { - return r && typeof r === "object" ? - { id: r.id, ok: r.ok, name: trim(r.name) } : - r - }) - - tt.deepEqual(rs, [ - "TAP version 13", - "do a task and write", - { id: 1, ok: true, name: "null" }, - { id: 2, ok: true, name: "should be equal" }, - "do a task and write fail", - { id: 3, ok: true, name: "null" }, - { id: 4, ok: true, name: "should be equal" }, - { id: 5, ok: false, name: "Error: fail" }, - "tests 5", - "pass 4", - "fail 1" - ]) + 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 equal', + '# do a task and write fail', + 'ok 3 null', + 'ok 4 should be 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(tc) + })); test("do a task and write", function (assert) { fakeAsyncTask("foo", function (err, value) { @@ -64,3 +55,33 @@ function fakeAsyncWrite(name, cb) { function fakeAsyncWriteFail(name, cb) { cb(new Error("fail")) } + +/** + * extract the stack trace for the failed test. + * this will change dependent on the environment + * so no point hard-coding it in the test assertion + * see: https://git.io/v6hGG for example + * @param String rows - the tap output lines + * @returns String stacktrace - just the error stack part + */ +function getStackTrace(rows) { + var stacktrace = ' ---\n'; + var extract = false; + rows.toString('utf8').split('\n').forEach(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; +} From b9ab50ea47a72d61331d9fc55d684b3aa919d393 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:50:40 +0100 Subject: [PATCH 262/373] update test/fail.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) see #312 --- test/fail.js | 62 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/test/fail.js b/test/fail.js index c39666ae..40710a64 100644 --- a/test/fail.js +++ b/test/fail.js @@ -1,61 +1,59 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - tt.same(rs, [ + var tc = function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: false, name: 'should be equivalent' }, - 'tests 5', - 'pass 4', - 'fail 1' - ]); - }); - - test.createStream().pipe(tc); - + '# array', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'not ok 5 should be equivalent', + ' ---', + ' operator: deepEqual', + ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', + ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' ...', + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1', + '' + ].join('\n')); + }; + + test.createStream().pipe(concat(tc)); + 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); From 1bac623d0df9250aede8ba091e87688fa4b31b02 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:51:39 +0100 Subject: [PATCH 263/373] update test/max_listeners.js to use path.join for cross-platform compatibility see: https://github.com/substack/tape/pull/314#discussion_r76651627 --- test/max_listeners.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/max_listeners.js b/test/max_listeners.js index 5edfb153..e807cdbf 100644 --- a/test/max_listeners.js +++ b/test/max_listeners.js @@ -1,5 +1,8 @@ var spawn = require('child_process').spawn; -var ps = spawn(process.execPath, [ __dirname + '/max_listeners/source.js' ]); +var path = require('path'); + +var ps = spawn(process.execPath, [path.join(__dirname, 'max_listeners', 'source.js')]); + ps.stdout.pipe(process.stdout, { end : false }); ps.stderr.on('data', function (buf) { From 45ae6c106e7fa729ec9e5e475c12c9672c5a1324 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:53:08 +0100 Subject: [PATCH 264/373] update test/nested-sync-noplan-noend.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) for #312 --- test/nested-sync-noplan-noend.js | 50 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 15b6883a..335eef88 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -1,49 +1,41 @@ var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('nested sync test without plan or end', function (tt) { tt.plan(1); var test = tape.createHarness(); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - var expected = [ + var tc = function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'nested without plan or end', - 'first', - { id: 1, ok: true, name: 'should be truthy' }, - 'second', - { id: 2, ok: true, name: 'should be truthy' }, - 'tests 2', - 'pass 2', - 'ok' - ] - tt.same(rs, expected); - }); + '# nested without plan or end', + '# first', + 'ok 1 should be truthy', + '# second', + 'ok 2 should be truthy', + '', + '1..2', + '# tests 2', + '# pass 2', + '', + '# ok' + ].join('\n') + '\n'); + }; - test.createStream().pipe(tc); + test.createStream().pipe(concat(tc)); test('nested without plan or end', function(t) { t.test('first', function(q) { - setTimeout(function first() { + setTimeout(function first() { q.ok(true); - q.end() + q.end() }, 10); }); t.test('second', function(q) { - setTimeout(function second() { + setTimeout(function second() { q.ok(true); - q.end() + q.end() }, 10); }); }); From 1211a3afba139f91ae43939680565f499301dfe3 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:54:44 +0100 Subject: [PATCH 265/373] udpate test/nested.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) #312 --- test/nested.js | 71 +++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/test/nested.js b/test/nested.js index 5ac8a9d9..46822594 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,75 +1,68 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - tt.same(rs, [ + var tc = function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'nested array test', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: true, name: 'should be equivalent' }, - 'inside test', - { id: 6, ok: true, name: 'should be truthy' }, - { id: 7, ok: true, name: 'should be truthy' }, - 'another', - { id: 8, ok: true, name: 'should be truthy' }, - 'tests 8', - 'pass 8', - 'ok' - ]); - }); - - test.createStream().pipe(tc); - + '# nested array test', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'ok 5 should be equivalent', + '# 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' + ].join('\n') + '\n'); + }; + + test.createStream().pipe(concat(tc)); + 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); - + setTimeout(function () { q.ok(true); }, 100); }); - + 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); From c1807c26efc475fa8838e72891e47efcc45b1374 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:56:03 +0100 Subject: [PATCH 266/373] update test/only.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) for #312 --- test/only.js | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/test/only.js b/test/only.js index 2decdc9c..f68c450b 100644 --- a/test/only.js +++ b/test/only.js @@ -1,38 +1,29 @@ var tap = require('tap'); var tape = require('../'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('tape only test', function (tt) { var test = tape.createHarness({ exit: false }); - var tc = tap.createConsumer(); var ran = []; - var rows = [] - tc.on('data', function (r) { rows.push(r) }) - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id: r.id, ok: r.ok, name: trim(r.name) }; - } - else { - return r; - } - }) - - tt.deepEqual(rs, [ + var tc = function (rows) { + tt.deepEqual(rows.toString('utf8'), [ 'TAP version 13', - 'run success', - { id: 1, ok: true, name: 'assert name'}, - 'tests 1', - 'pass 1', - 'ok' - ]) + '# run success', + 'ok 1 assert name', + '', + '1..1', + '# tests 1', + '# pass 1', + '', + '# ok' + ].join('\n') + '\n'); tt.deepEqual(ran, [ 3 ]); tt.end() - }) + }; - test.createStream().pipe(tc) + test.createStream().pipe(concat(tc)); test("never run fail", function (t) { ran.push(1); From 882609917f2a9739198e5f09c4262ab990e2964e Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:57:53 +0100 Subject: [PATCH 267/373] update test/require.js to use concat-stream instead of tap.createConsumer (method method unavailable in tap v7) see: https://github.com/substack/tape/issues/312#issuecomment-242740448 --- test/require.js | 100 +++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/test/require.js b/test/require.js index 0385ea45..ef3bd96c 100644 --- a/test/require.js +++ b/test/require.js @@ -1,36 +1,29 @@ var tap = require('tap'); var spawn = require('child_process').spawn; -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('requiring a single module', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'module-a', - { id: 1, ok: true, name: 'loaded module a' }, - 'test-a', - { id: 2, ok: true, name: 'module-a loaded in same context'}, - { id: 3, ok: true, name: 'test ran after module-a was loaded'}, - 'tests 3', - 'pass 3', - 'ok' - ]); - }); - + '# 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' + ].join('\n') + '\n\n'); + }; + var ps = tape('-r ./require/a require/test-a.js'); - ps.stdout.pipe(tc); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.equal(code, 0); }); @@ -38,38 +31,31 @@ tap.test('requiring a single module', function (t) { tap.test('requiring multiple modules', function (t) { t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - t.same(rs, [ + + var tc = function (rows) { + t.same(rows.toString('utf8'), [ 'TAP version 13', - 'module-a', - { id: 1, ok: true, name: 'loaded module a' }, - 'module-b', - { id: 2, ok: true, name: 'loaded module b' }, - 'test-a', - { id: 3, ok: true, name: 'module-a loaded in same context'}, - { id: 4, ok: true, name: 'test ran after module-a was loaded'}, - 'test-b', - { id: 5, ok: true, name: 'module-b loaded in same context'}, - { id: 6, ok: true, name: 'test ran after module-b was loaded'}, - 'tests 6', - 'pass 6', - 'ok' - ]); - }); - + '# 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(tc); + ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.equal(code, 0); }); @@ -80,4 +66,4 @@ function tape(args) { var bin = __dirname + '/../bin/tape' return proc.spawn(bin, args.split(' '), { cwd: __dirname }) -} \ No newline at end of file +} From aa021eb616cde1a547995ac0ffef02b73895ba04 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 19:59:25 +0100 Subject: [PATCH 268/373] remove redundant tests from test/skip.js - still testing the documented API adequately --- test/skip.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/test/skip.js b/test/skip.js index 73d97f20..54c53f90 100644 --- a/test/skip.js +++ b/test/skip.js @@ -28,13 +28,6 @@ tap.test('test SKIP comment', function (assert) { }); }); - -test('do not skip this', { skip: false }, function(t) { - t.pass('this should run'); - ran ++; - t.end(); -}); - test('skip this', { skip: true }, function(t) { t.fail('this should not even run'); ran++; @@ -43,17 +36,12 @@ test('skip this', { skip: true }, function(t) { test.skip('skip this too', function(t) { t.fail('this should not even run'); - ran++; + ran++; t.end(); }); test('skip subtest', function(t) { - ran ++; - t.test('do not skip this', { skip: false }, function(t) { - ran ++; - t.pass('this should run'); - t.end(); - }); + ran++; t.test('skip this', { skip: true }, function(t) { t.fail('this should not even run'); t.end(); @@ -61,9 +49,4 @@ test('skip subtest', function(t) { t.end(); }); -test('right number of tests ran', function(t) { - t.equal(ran, 3, 'ran the right number of tests'); - t.end(); -}); - // vim: set softtabstop=4 shiftwidth=4: From fd7eb30bea4328cebeaa38d9bea4c21c47f12e5e Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 20:02:09 +0100 Subject: [PATCH 269/373] remove redundant tests in test/throws.js (assertion unchanged! tests pass) for #312 --- test/throws.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/throws.js b/test/throws.js index 44ce1382..1867aa84 100644 --- a/test/throws.js +++ b/test/throws.js @@ -14,24 +14,6 @@ function getNonFunctionMessage(fn) { } } -tape('throws', function (t) { - t.throws(fn); - t.end(); -}); - -tape('throws (RegExp match)', function (t) { - t.throws(fn, /RegExp/, 'regex with no anchors'); - t.throws(fn, /^TypeError: Reg/, 'regex with starting anchor'); - t.throws(fn, /RegExp$/, 'regex with ending anchor'); - t.throws(fn, /^TypeError: RegExp$/, 'regex with both anchors'); - t.end(); -}); - -tape('throws (Function match)', function (t) { - t.throws(fn, TypeError); - t.end(); -}); - tap.test('failures', function (tt) { tt.plan(1); From db3a45eda8a855a87478e7533602fd1d8c787d17 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 20:03:32 +0100 Subject: [PATCH 270/373] update test/timeoutAfter.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) see: https://github.com/substack/tape/issues/312#issuecomment-242740448 --- test/timeoutAfter.js | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 48b1c0f1..adb65c20 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -1,34 +1,29 @@ var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('timeoutAfter test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - tt.same(rs, [ + var tc = function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'timeoutAfter', - { id: 1, ok: false, name: 'test timed out after 1ms' }, - 'tests 1', - 'pass 0', - 'fail 1' - ]); - }); - - test.createStream().pipe(tc); - + '# timeoutAfter', + 'not ok 1 test timed out after 1ms', + ' ---', + ' operator: fail', + ' ...', + '', + '1..1', + '# tests 1', + '# pass 0', + '# fail 1' + ].join('\n') + '\n'); + }; + + test.createStream().pipe(concat(tc)); + test('timeoutAfter', function (t) { t.plan(1); t.timeoutAfter(1); From 5f89509559176ee49db3b5ae812324a292614425 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 20:04:50 +0100 Subject: [PATCH 271/373] update test/too_many.js to use concat-stream instead of tap.createConsumer (method unavailable in tap v7) see: https://github.com/substack/tape/issues/312#issuecomment-242740448 --- test/too_many.js | 63 +++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/test/too_many.js b/test/too_many.js index 56c2225a..05b9f84a 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -1,62 +1,59 @@ var falafel = require('falafel'); var tape = require('../'); var tap = require('tap'); -var trim = require('string.prototype.trim'); +var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : trim(r.name) }; - } - else return r; - }); - tt.same(rs, [ + var tc = function (rows) { + tt.same(rows.toString('utf8'), [ 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: false, name: 'plan != count' }, - { id: 6, ok: true, name: 'should be equivalent' }, - 'tests 6', - 'pass 5', - 'fail 1' - ]); - }); - - test.createStream().pipe(tc); - + '# array', + 'ok 1 should be equivalent', + 'ok 2 should be equivalent', + 'ok 3 should be equivalent', + 'ok 4 should be equivalent', + 'not ok 5 plan != count', + ' ---', + ' operator: fail', + ' expected: 3', + ' actual: 4', + ' ...', + 'ok 6 should be equivalent', + '', + '1..6', + '# tests 6', + '# pass 5', + '# fail 1' + ].join('\n') + '\n'); + }; + + test.createStream().pipe(concat(tc)); + test('array', function (t) { t.plan(3); - + 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); From 44d1f6ffe468d71e9469d6dad1cf5fbab6c9168d Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 2 Sep 2016 20:18:25 +0100 Subject: [PATCH 272/373] update devDpendencies to latest: tap (v7) and tap-parser (v2) fixes #312 --- readme.markdown | 23 +++++++++-------------- test/array.js | 14 +++++++------- test/default-messages.js | 2 +- test/end-as-callback.js | 2 +- test/fail.js | 14 +++++++------- test/nested-sync-noplan-noend.js | 8 ++++---- test/nested.js | 18 +++++++++--------- test/require.js | 10 +++++----- test/timeoutAfter.js | 6 +++--- test/too_many.js | 14 +++++++------- 10 files changed, 53 insertions(+), 58 deletions(-) diff --git a/readme.markdown b/readme.markdown index 8b46c36b..a45db947 100644 --- a/readme.markdown +++ b/readme.markdown @@ -88,7 +88,7 @@ Please note that all modules loaded using the `-r` flag will run *before* any te tape maintains a fairly minimal core. Additional features are usually added by using another module alongside tape. -## reporters for humans +## pretty reporters The default TAP output is good for machines and humans that are robots. @@ -98,30 +98,26 @@ that will output something pretty if you pipe TAP into them: - https://github.com/scottcorgan/tap-spec - https://github.com/scottcorgan/tap-dot - https://github.com/substack/faucet + - https://github.com/juliangruber/tap-bail - https://github.com/kirbysayshi/tap-browser-color + - https://github.com/gummesson/tap-json - https://github.com/gummesson/tap-min - https://github.com/calvinmetcalf/tap-nyan - - https://github.com/clux/tap-pessimist + - https://www.npmjs.org/package/tap-pessimist - https://github.com/toolness/tap-prettify - https://github.com/shuhei/colortape + - https://github.com/aghassemi/tap-xunit - https://github.com/namuol/tap-difflet + - https://github.com/gritzko/tape-dom - https://github.com/axross/tap-diff - https://github.com/axross/tap-notify - https://github.com/zoubin/tap-summary - -You use these reporters by piping the tape output into them. For example, -try `node test/index.js | tap-spec`. - -## reporters for other file formats - - - https://github.com/gummesson/tap-json - - https://github.com/aghassemi/tap-xunit - - https://github.com/gritzko/tape-dom - https://github.com/Hypercubed/tap-markdown -## failing assertions +To use them, try `node test/index.js | tap-spec` or pipe it into one +of the modules of your choice! -If any assertions fail, tape will continue. To terminate on the first failure, see [tap-bail](https://github.com/juliangruber/tap-bail). +## uncaught exceptions By default, uncaught exceptions in your tests will not be intercepted, and will cause tape to crash. If you find this behavior undesirable, use [tape-catch](https://github.com/michaelrhodes/tape-catch) to report any exceptions as TAP errors. @@ -130,7 +126,6 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - CoffeeScript support with https://www.npmjs.com/package/coffeetape - Promise support with https://www.npmjs.com/package/blue-tape - ES6 support with https://www.npmjs.com/package/babel-tape-runner -- Inclue time information with https://github.com/diasdavid/timed-tape # methods diff --git a/test/array.js b/test/array.js index dc4a4a40..d206be58 100644 --- a/test/array.js +++ b/test/array.js @@ -5,9 +5,9 @@ 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', @@ -25,29 +25,29 @@ tap.test('array test', function (tt) { '# 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); diff --git a/test/default-messages.js b/test/default-messages.js index dcfdbffc..46c055fd 100644 --- a/test/default-messages.js +++ b/test/default-messages.js @@ -7,7 +7,7 @@ tap.test('default messages', function (t) { t.plan(1); var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); - + ps.stdout.pipe(concat(function (rows) { t.same(rows.toString('utf8'), [ diff --git a/test/end-as-callback.js b/test/end-as-callback.js index 09338c87..a9478cb3 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -4,7 +4,7 @@ var concat = require('concat-stream'); tap.test("tape assert.end as callback", function (tt) { var test = tape.createHarness({ exit: false }) - + test.createStream().pipe(concat(function (rows) { tt.equal(rows.toString('utf8'), [ 'TAP version 13', diff --git a/test/fail.js b/test/fail.js index 40710a64..54c544cc 100644 --- a/test/fail.js +++ b/test/fail.js @@ -5,7 +5,7 @@ var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); var tc = function (rows) { tt.same(rows.toString('utf8'), [ @@ -29,31 +29,31 @@ tap.test('array test', function (tt) { '' ].join('\n')); }; - + test.createStream().pipe(concat(tc)); - + 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); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 335eef88..6039093d 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -27,15 +27,15 @@ tap.test('nested sync test without plan or end', function (tt) { test('nested without plan or end', function(t) { t.test('first', function(q) { - setTimeout(function first() { + setTimeout(function first() { q.ok(true); - q.end() + q.end() }, 10); }); t.test('second', function(q) { - setTimeout(function second() { + setTimeout(function second() { q.ok(true); - q.end() + q.end() }, 10); }); }); diff --git a/test/nested.js b/test/nested.js index 46822594..f444f95f 100644 --- a/test/nested.js +++ b/test/nested.js @@ -5,7 +5,7 @@ var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); var tc = function (rows) { tt.same(rows.toString('utf8'), [ @@ -29,40 +29,40 @@ tap.test('array test', function (tt) { '# ok' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + 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); - + setTimeout(function () { q.ok(true); }, 100); }); - + 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); diff --git a/test/require.js b/test/require.js index ef3bd96c..bad5d648 100644 --- a/test/require.js +++ b/test/require.js @@ -4,7 +4,7 @@ var concat = require('concat-stream'); tap.test('requiring a single module', function (t) { t.plan(2); - + var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', @@ -21,7 +21,7 @@ tap.test('requiring a single module', function (t) { '# ok' ].join('\n') + '\n\n'); }; - + var ps = tape('-r ./require/a require/test-a.js'); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { @@ -31,7 +31,7 @@ tap.test('requiring a single module', function (t) { tap.test('requiring multiple modules', function (t) { t.plan(2); - + var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', @@ -53,7 +53,7 @@ tap.test('requiring multiple modules', function (t) { '# 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) { @@ -66,4 +66,4 @@ function tape(args) { var bin = __dirname + '/../bin/tape' return proc.spawn(bin, args.split(' '), { cwd: __dirname }) -} +} \ No newline at end of file diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index adb65c20..e44e3c78 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -4,7 +4,7 @@ var concat = require('concat-stream'); tap.test('timeoutAfter test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); var tc = function (rows) { tt.same(rows.toString('utf8'), [ @@ -21,9 +21,9 @@ tap.test('timeoutAfter test', function (tt) { '# fail 1' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + test('timeoutAfter', function (t) { t.plan(1); t.timeoutAfter(1); diff --git a/test/too_many.js b/test/too_many.js index 05b9f84a..233a7abc 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -5,7 +5,7 @@ var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); var tc = function (rows) { tt.same(rows.toString('utf8'), [ @@ -29,31 +29,31 @@ tap.test('array test', function (tt) { '# fail 1' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + test('array', function (t) { t.plan(3); - + 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); From 7536fba89930b349b17a89a7bc98f898299088d5 Mon Sep 17 00:00:00 2001 From: mkls Date: Wed, 31 Aug 2016 23:31:22 +0200 Subject: [PATCH 273/373] Fix for not showing path for error messages on windows This bug has been around for a while now. Tried to keep changes to the bare minimum. --- lib/test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/test.js b/lib/test.js index 497c58a4..9611dd25 100644 --- a/lib/test.js +++ b/lib/test.js @@ -217,7 +217,7 @@ Test.prototype._assert = function assert (ok, opts) { if (!ok) { var e = new Error('exception'); var err = (e.stack || '').split('\n'); - var dir = path.dirname(__dirname) + '/'; + var dir = path.dirname(__dirname) + path.sep; for (var i = 0; i < err.length; i++) { var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]); @@ -226,12 +226,12 @@ Test.prototype._assert = function assert (ok, opts) { } var s = m[1].split(/\s+/); - var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]); + var filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]); if (!filem) { - filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]); + filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]); if (!filem) { - filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]); + filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]); if (!filem) { continue; From baca83c59361a6fb3baf5f5e0ef967c9eb80e124 Mon Sep 17 00:00:00 2001 From: mkls Date: Wed, 7 Sep 2016 00:20:03 +0200 Subject: [PATCH 274/373] Fix for unit tests on windows --- test/require.js | 2 +- test/require/a.js | 2 +- test/require/b.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/require.js b/test/require.js index bad5d648..6b05a000 100644 --- a/test/require.js +++ b/test/require.js @@ -65,5 +65,5 @@ function tape(args) { var proc = require('child_process') var bin = __dirname + '/../bin/tape' - return proc.spawn(bin, args.split(' '), { cwd: __dirname }) + return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }) } \ No newline at end of file diff --git a/test/require/a.js b/test/require/a.js index 0947b7b9..b2dd811b 100644 --- a/test/require/a.js +++ b/test/require/a.js @@ -1,8 +1,8 @@ var tape = require('../..'); tape.test('module-a', function(t) { + t.plan(1) t.pass('loaded module a') - t.end() }) global.module_a = true \ No newline at end of file diff --git a/test/require/b.js b/test/require/b.js index 18942e0c..2206c17c 100644 --- a/test/require/b.js +++ b/test/require/b.js @@ -1,8 +1,8 @@ var tape = require('../..'); tape.test('module-b', function(t) { + t.plan(1) t.pass('loaded module b') - t.end() }) global.module_b = true \ No newline at end of file From 8608d598cbcf14f575494bb1e0eeed2dd22a7f5a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 7 Sep 2016 23:39:14 -0800 Subject: [PATCH 275/373] [Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2450e446..3dc3caec 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "function-bind": "~1.1.0", - "glob": "~7.0.5", + "glob": "~7.0.6", "has": "~1.0.1", "inherits": "~2.0.1", "minimist": "~1.2.0", From 47507a065e7e905180a0c9883b59d87a4b4d4154 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 7 Sep 2016 23:44:14 -0800 Subject: [PATCH 276/373] [Dev Deps] update `concat-stream` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3dc3caec..e4ca656a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "through": "~2.3.8" }, "devDependencies": { - "concat-stream": "~1.5.1", + "concat-stream": "~1.5.2", "falafel": "~1.2.0", "js-yaml": "~3.6.1", "tap": "~7.0.0", From 96552cff15ab5a5072b9343cf476c8d3e1e95452 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 8 Sep 2016 22:11:57 -0700 Subject: [PATCH 277/373] [Deps] update `inherits` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4ca656a..d53be94a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "function-bind": "~1.1.0", "glob": "~7.0.6", "has": "~1.0.1", - "inherits": "~2.0.1", + "inherits": "~2.0.3", "minimist": "~1.2.0", "object-inspect": "~1.2.1", "resolve": "~1.1.7", From ea9dcb78c91c6905c2bce0bf804475d2a9d3b4df Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 8 Sep 2016 22:12:34 -0700 Subject: [PATCH 278/373] [Dev Deps] update `tap`, `tap-parser` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d53be94a..7bdbd2d9 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "concat-stream": "~1.5.2", "falafel": "~1.2.0", "js-yaml": "~3.6.1", - "tap": "~7.0.0", - "tap-parser": "~2.0.0" + "tap": "~7.1.1", + "tap-parser": "~2.2.2" }, "scripts": { "test": "tap test/*.js" From 918e217c03febe3f8b7c12cc5d6a133745698cd0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 8 Sep 2016 22:18:55 -0700 Subject: [PATCH 279/373] [Tests] ensure the max_listeners test has passing output. --- test/max_listeners/source.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/max_listeners/source.js b/test/max_listeners/source.js index 839a3275..f78782fc 100644 --- a/test/max_listeners/source.js +++ b/test/max_listeners/source.js @@ -1,5 +1,5 @@ var test = require('../../'); for (var i = 0; i < 11; i ++) { - test(function (t) { t.end() }); + test(function (t) { t.ok(true, 'true is truthy'); t.end() }); } From c1b483c8c4d3f58677bacc106be13708dd73ef75 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 9 Sep 2016 23:05:46 -0700 Subject: [PATCH 280/373] =?UTF-8?q?[Fix]=20`throws`:=20only=20reassign=20?= =?UTF-8?q?=E2=80=9Cmessage=E2=80=9D=20when=20it=20is=20not=20already=20no?= =?UTF-8?q?n-enumerable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #320. --- lib/test.js | 10 +++++++--- test/throws.js | 25 +++++++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9611dd25..538cbcdd 100644 --- a/lib/test.js +++ b/lib/test.js @@ -5,6 +5,8 @@ var inherits = require('inherits'); var EventEmitter = require('events').EventEmitter; var has = require('has'); var trim = require('string.prototype.trim'); +var bind = require('function-bind'); +var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable); module.exports = Test; @@ -444,9 +446,11 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { fn(); } catch (err) { caught = { error : err }; - var message = err.message; - delete err.message; - err.message = message; + if (!isEnumerable(err, 'message') || !has(err, 'message')) { + var message = err.message; + delete err.message; + err.message = message; + } } var passed = caught; diff --git a/test/throws.js b/test/throws.js index 1867aa84..77273d43 100644 --- a/test/throws.js +++ b/test/throws.js @@ -93,10 +93,14 @@ tap.test('failures', function (tt) { + ' operator: throws\n' + ' expected: undefined\n' + ' actual: undefined\n' - + ' ...\n\n' - + '1..9\n' - + '# tests 9\n' - + '# pass 0\n' + + ' ...\n' + + '# custom error messages\n' + + 'ok 10 "message" is enumerable\n' + + "ok 11 { custom: 'error', message: 'message' }\n" + + 'ok 12 getter is still the same\n' + + '\n1..12\n' + + '# tests 12\n' + + '# pass 3\n' + '# fail 9\n' ); })); @@ -117,4 +121,17 @@ tap.test('failures', function (tt) { t.plan(1); t.throws(function () {}); }); + + test('custom error messages', function (t) { + t.plan(3); + var getter = function () { return 'message'; }; + var messageGetterError = Object.defineProperty( + { custom: 'error' }, + 'message', + { configurable: true, enumerable: true, get: getter } + ); + t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable'); + t.throws(function () { throw messageGetterError; }, "{ custom: 'error', message: 'message' }"); + t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); + }); }); From 6369b778c15f72c4d8954527d076b3d0ede0bf74 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 29 Sep 2016 21:41:37 -0700 Subject: [PATCH 281/373] [Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7bdbd2d9..48a74eb0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "function-bind": "~1.1.0", - "glob": "~7.0.6", + "glob": "~7.1.0", "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", From 50f462e7a8acd4c5cd9cdebd2a25d52ab16e49bd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 29 Sep 2016 21:45:19 -0700 Subject: [PATCH 282/373] [Dev Deps] update `falafel`, `tap-parser` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 48a74eb0..8642cbfd 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ }, "devDependencies": { "concat-stream": "~1.5.2", - "falafel": "~1.2.0", + "falafel": "~2.0.0", "js-yaml": "~3.6.1", "tap": "~7.1.1", - "tap-parser": "~2.2.2" + "tap-parser": "~3.0.3" }, "scripts": { "test": "tap test/*.js" From 407a0f682a559c676323a01969083f9354768948 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 29 Sep 2016 22:47:32 -0700 Subject: [PATCH 283/373] v4.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [Fix] `throws`: only reassign “message” when it is not already non-enumerable (#320) - [Fix] show path for error messages on windows (#316) - [Fix] `.only` should not run multiple tests with the same name (#299, #303) - [Deps] update `glob`, `inherits` - [Dev Deps] update `concat-stream`, `tap`, `tap-parser`, `falafel` - [Tests] [Dev Deps] Update to latest version of devDependencies tap (v7) and tap-parser (v2) (#318) - [Tests] ensure the max_listeners test has passing output - [Docs] improvements (#298, #317) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8642cbfd..6c220ca2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.6.0", + "version": "4.6.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From ae7fec6895284114069a599bce991f84757b395e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 30 Sep 2016 10:55:45 -0700 Subject: [PATCH 284/373] =?UTF-8?q?[Fix]=20if=20someone=20throws=20`null`/?= =?UTF-8?q?`undefined`,=20it=20shouldn=E2=80=99t=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #324. --- lib/test.js | 2 +- test/throws.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/test.js b/lib/test.js index 538cbcdd..d4b4b1cc 100644 --- a/lib/test.js +++ b/lib/test.js @@ -446,7 +446,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { fn(); } catch (err) { caught = { error : err }; - if (!isEnumerable(err, 'message') || !has(err, 'message')) { + if ((err != null) && (!isEnumerable(err, 'message') || !has(err, 'message'))) { var message = err.message; delete err.message; err.message = message; diff --git a/test/throws.js b/test/throws.js index 77273d43..31ab9a45 100644 --- a/test/throws.js +++ b/test/throws.js @@ -98,9 +98,11 @@ tap.test('failures', function (tt) { + 'ok 10 "message" is enumerable\n' + "ok 11 { custom: 'error', message: 'message' }\n" + 'ok 12 getter is still the same\n' - + '\n1..12\n' - + '# tests 12\n' - + '# pass 3\n' + + '# throws null\n' + + 'ok 13 throws null\n' + + '\n1..13\n' + + '# tests 13\n' + + '# pass 4\n' + '# fail 9\n' ); })); @@ -134,4 +136,10 @@ tap.test('failures', function (tt) { t.throws(function () { throw messageGetterError; }, "{ 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(); + }); }); From c9b8ce83e875f556acdb0cc46d6cec9a3c057bd3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 30 Sep 2016 11:08:08 -0700 Subject: [PATCH 285/373] v4.6.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [Fix] if someone throws `null`/`undefined`, it shouldn’t crash --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c220ca2..8dd7a89f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.6.1", + "version": "4.6.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From cc9cc304b60864d76e9a9efdd4e90003502cafff Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Nov 2016 11:04:48 -0600 Subject: [PATCH 286/373] =?UTF-8?q?[Fix]=20don=E2=80=99t=20assume=20`Array?= =?UTF-8?q?#forEach`,=20for=20ES3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/test.js | 3 ++- package.json | 1 + test/end-as-callback.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index d4b4b1cc..0b48ed6f 100644 --- a/lib/test.js +++ b/lib/test.js @@ -6,6 +6,7 @@ var EventEmitter = require('events').EventEmitter; var has = require('has'); var trim = require('string.prototype.trim'); var bind = require('function-bind'); +var forEach = require('for-each'); var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable); module.exports = Test; @@ -110,7 +111,7 @@ Test.prototype.test = function (name, opts, cb) { Test.prototype.comment = function (msg) { var that = this; - trim(msg).split('\n').forEach(function (aMsg) { + forEach(trim(msg).split('\n'), function (aMsg) { that.emit('result', trim(aMsg).replace(/^#\s*/, '')); }); }; diff --git a/package.json b/package.json index 8dd7a89f..398bac28 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "deep-equal": "~1.0.1", "defined": "~1.0.0", + "for-each": "~0.3.2", "function-bind": "~1.1.0", "glob": "~7.1.0", "has": "~1.0.1", diff --git a/test/end-as-callback.js b/test/end-as-callback.js index a9478cb3..98609f5d 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -1,4 +1,5 @@ var tap = require("tap"); +var forEach = require("for-each"); var tape = require("../"); var concat = require('concat-stream'); @@ -67,7 +68,7 @@ function fakeAsyncWriteFail(name, cb) { function getStackTrace(rows) { var stacktrace = ' ---\n'; var extract = false; - rows.toString('utf8').split('\n').forEach(function (row) { + forEach(rows.toString('utf8').split('\n'), function (row) { if (!extract) { if (row.indexOf('---') > -1) { // start of stack trace extract = true; From a4cc2fe3e67c3c07bfcdbf244d46c9c68b29e6aa Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Nov 2016 21:24:58 -0600 Subject: [PATCH 287/373] [Tests] on `node` `v7` --- .travis.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a699c635..e564088a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,18 @@ language: node_js sudo: true node_js: - - "0.10" - - "0.12" - - "iojs" - - "4" - - "5" + - "7" - "6" + - "5" + - "4" + - "iojs" + - "0.12" + - "0.10" + - "0.8" +before_install: + - 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' + - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' +matrix: + fast_finish: true + allow_failures: + - node_js: "0.8" From 9b27d19c7de6151af356ade4876841595276d211 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Nov 2016 23:07:24 -0600 Subject: [PATCH 288/373] [Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 398bac28..2827e52a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "defined": "~1.0.0", "for-each": "~0.3.2", "function-bind": "~1.1.0", - "glob": "~7.1.0", + "glob": "~7.1.1", "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", From a80e655d9f03c26f1bb454927cbc8ba1f5679f2a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Nov 2016 23:09:01 -0600 Subject: [PATCH 289/373] [Dev Deps] update `js-yaml`, `tap-parser` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2827e52a..47476387 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "devDependencies": { "concat-stream": "~1.5.2", "falafel": "~2.0.0", - "js-yaml": "~3.6.1", + "js-yaml": "~3.7.0", "tap": "~7.1.1", - "tap-parser": "~3.0.3" + "tap-parser": "~3.0.4" }, "scripts": { "test": "tap test/*.js" From 72213e119fb9c52e7620fdc58908b1227dd1c9f8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Nov 2016 23:09:35 -0600 Subject: [PATCH 290/373] v4.6.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [Fix] don’t assume `Array#forEach`, for ES3 - [Tests] on `node` `v7` - [Deps] update `glob` - [Dev Deps] update `js-yaml`, `tap-parser` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47476387..a48a44df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.6.2", + "version": "4.6.3", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 5ec88e736adbf85f05b7a3bb34caa452ed644e53 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 3 Dec 2016 23:42:07 -0800 Subject: [PATCH 291/373] [Dev Deps] update `tap` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a48a44df..b26975f2 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "concat-stream": "~1.5.2", "falafel": "~2.0.0", "js-yaml": "~3.7.0", - "tap": "~7.1.1", + "tap": "~8.0.1", "tap-parser": "~3.0.4" }, "scripts": { From 93026823b0606021adac0042ef2da6865607ee90 Mon Sep 17 00:00:00 2001 From: Tristan Davies Date: Tue, 17 May 2016 11:14:26 -0300 Subject: [PATCH 292/373] [New] show full error stack on failure --- lib/results.js | 9 ++++-- test/circular-things.js | 9 +++++- test/common.js | 56 ++++++++++++++++++++++++++++++++++ test/deep-equal-failure.js | 39 +++++++++++++++--------- test/double_end.js | 31 ++++++++++++++++++- test/double_end/double.js | 8 +++-- test/exit.js | 22 ++++++++++++-- test/fail.js | 12 +++++++- test/stackTrace.js | 61 ++++++++++++++++++++++++++++++++++++++ test/throws.js | 49 +++++++++++++++++++++++++++++- test/timeoutAfter.js | 7 ++++- test/too_many.js | 12 +++++++- test/undef.js | 9 +++++- 13 files changed, 295 insertions(+), 29 deletions(-) create mode 100644 test/common.js diff --git a/lib/results.js b/lib/results.js index efc60ce3..35bf09f3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -1,3 +1,4 @@ +var defined = require('defined'); var EventEmitter = require('events').EventEmitter; var inherits = require('inherits'); var through = require('through'); @@ -157,8 +158,12 @@ function encodeResult (res, count) { if (res.at) { output += inner + 'at: ' + res.at + '\n'; } - if (res.operator === 'error' && res.actual && res.actual.stack) { - var lines = String(res.actual.stack).split('\n'); + + var actualStack = res.actual && res.actual.stack; + var errorStack = res.error && res.error.stack; + var stack = defined(actualStack, errorStack); + if (stack) { + var lines = String(stack).split('\n'); output += inner + 'stack: |-\n'; for (var i = 0; i < lines.length; i++) { output += inner + ' ' + lines[i] + '\n'; diff --git a/test/circular-things.js b/test/circular-things.js index 590ae430..bbabc919 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -2,13 +2,15 @@ var tape = require('../'); var tap = require('tap'); 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); test.createStream().pipe(concat(function (body) { assert.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# circular\n' + 'not ok 1 should be equal\n' @@ -18,6 +20,11 @@ tap.test('circular test', function (assert) { + ' {}\n' + ' actual: |-\n' + ' { circular: [Circular] }\n' + + ' stack: |-\n' + + ' Error: should be equal\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/circular-things.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '\n' + '1..1\n' diff --git a/test/common.js b/test/common.js new file mode 100644 index 00000000..22d7854c --- /dev/null +++ b/test/common.js @@ -0,0 +1,56 @@ +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'); + + // The stack trace will vary depending on where the code is run, so just + // strip it out. + var withStack = yaml.safeLoad(diag); + delete withStack.stack; + return withStack; +} + +// There are three challenges associated with checking the stack traces included +// in errors: +// 1) The base checkout directory of tape might change. Because stack traces +// include absolute paths, the stack traces will change depending on the +// checkout path. We handle this by replacing the base test directory with a +// placeholder $TEST variable. +// 2) Line positions within the file might change. We handle this by replacing +// line and column markers with placeholder $LINE and $COL "variables" +// 3) Stacks themselves change frequently with refactoring. We've even run into +// issues with node library refactorings "breaking" stack traces. Most of +// these changes are irrelevant to the tests themselves. To counter this, we +// strip out all stack frames that aren't directly under our test directory, +// and replace them with placeholders. +module.exports.stripFullStack = function (output) { + var stripped = ' [... stack stripped ...]'; + var withDuplicates = output.split('\n').map(function (line) { + var m = line.match(/[ ]{8}at .*\((.*)\)/); + + var stripChangingData = function (line) { + var withoutDirectory = line.replace(__dirname, '$TEST'); + var withoutLineNumbers = withoutDirectory.replace(/:\d+:\d+/g, ':$LINE:$COL'); + return withoutLineNumbers; + } + + if (m) { + if (m[1].slice(0, __dirname.length) === __dirname) { + return stripChangingData(line); + } + return stripped; + } + return stripChangingData(line); + }) + + var deduped = withDuplicates.filter(function (line, ix) { + var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; + return !hasPrior; + }); + + return deduped.join('\n'); +} diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 3f12b30e..4836037b 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -2,7 +2,10 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); var tapParser = require('tap-parser'); -var yaml = require('js-yaml'); +var common = require('./common'); + +var getDiag = common.getDiag; +var stripFullStack = common.stripFullStack; tap.test('deep equal failure', function (assert) { var test = tape.createHarness({ exit : false }); @@ -13,7 +16,7 @@ tap.test('deep equal failure', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { assert.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# deep equal\n' + 'not ok 1 should be equal\n' @@ -23,6 +26,11 @@ tap.test('deep equal failure', function (assert) { + ' { b: 2 }\n' + ' actual: |-\n' + ' { a: 1 }\n' + + ' stack: |-\n' + + ' Error: should be equal\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '\n' + '1..1\n' @@ -39,6 +47,7 @@ tap.test('deep equal failure', function (assert) { })); parser.once('assert', function (data) { + delete data.diag.stack; assert.deepEqual(data, { ok: false, id: 1, @@ -66,7 +75,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { assert.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# deep equal\n' + 'not ok 1 should be equal\n' @@ -76,6 +85,11 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n' + ' actual: |-\n' + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' + + ' stack: |-\n' + + ' Error: should be equal\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '\n' + '1..1\n' @@ -92,6 +106,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { })); parser.once('assert', function (data) { + delete data.diag.stack; assert.deepEqual(data, { ok: false, id: 1, @@ -119,7 +134,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { stream.pipe(parser); stream.pipe(concat(function (body) { assert.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# deep equal\n' + 'not ok 1 should be equal\n' @@ -129,6 +144,11 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + ' actual: |-\n' + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' stack: |-\n' + + ' Error: should be equal\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '\n' + '1..1\n' @@ -145,6 +165,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { })); parser.once('assert', function (data) { + delete data.diag.stack; assert.deepEqual(data, { ok: false, id: 1, @@ -162,13 +183,3 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }); }); }) - -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'); - - return yaml.safeLoad(diag); -} diff --git a/test/double_end.js b/test/double_end.js index 624ce3ac..212606e9 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -3,6 +3,8 @@ var path = require('path'); var concat = require('concat-stream'); var spawn = require('child_process').spawn; +var stripFullStack = require('./common').stripFullStack; + test(function (t) { t.plan(2); var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]); @@ -10,13 +12,40 @@ test(function (t) { t.equal(code, 1); }); ps.stdout.pipe(concat(function (body) { - t.equal(body.toString('utf8'), [ + // 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; + + var stackExpected; + try { + to._onTimeout(); + } + catch (e) { + stackExpected = stripFullStack(e.stack).split('\n')[1]; + stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); + stackExpected = stackExpected.trim(); + } + + var stripped = stripFullStack(body.toString('utf8')); + t.equal(stripped, [ 'TAP version 13', '# double end', 'ok 1 should be equal', 'not ok 2 .end() called twice', ' ---', ' operator: fail', + ' stack: |-', + ' Error: .end() called twice', + ' [... stack stripped ...]', + ' ' + stackExpected, + ' [... stack stripped ...]', ' ...', '', '1..2', diff --git a/test/double_end/double.js b/test/double_end/double.js index 44734824..43929e51 100644 --- a/test/double_end/double.js +++ b/test/double_end/double.js @@ -1,9 +1,11 @@ var test = require('../../'); test('double end', function (t) { + function doEnd() { + t.end(); + } + t.equal(1 + 1, 2); t.end(); - setTimeout(function () { - t.end(); - }, 5); + setTimeout(doEnd, 5); }); diff --git a/test/exit.js b/test/exit.js index 963e6b08..5736895d 100644 --- a/test/exit.js +++ b/test/exit.js @@ -3,6 +3,8 @@ var path = require('path'); var spawn = require('child_process').spawn; var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + tap.test('exit ok', function (t) { t.plan(2); @@ -38,7 +40,7 @@ tap.test('exit fail', function (t) { t.plan(2); var tc = function (rows) { - t.same(rows.toString('utf8'), [ + t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# array', 'ok 1 should be equivalent', @@ -50,6 +52,14 @@ tap.test('exit fail', function (t) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' stack: |-', + ' Error: should be equivalent', + ' [... stack stripped ...]', + ' at $TEST/exit/fail.js:$LINE:$COL', + ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL), :$LINE:$COL)', + ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL), :$LINE:$COL)', + ' at Test. ($TEST/exit/fail.js:$LINE:$COL)', + ' [... stack stripped ...]', ' ...', '', '1..5', @@ -70,7 +80,7 @@ tap.test('too few exit', function (t) { t.plan(2); var tc = function (rows) { - t.same(rows.toString('utf8'), [ + t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# array', 'ok 1 should be equivalent', @@ -83,6 +93,9 @@ tap.test('too few exit', function (t) { ' operator: fail', ' expected: 6', ' actual: 5', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', ' ...', '', '1..6', @@ -103,7 +116,7 @@ tap.test('more planned in a second test', function (t) { t.plan(2); var tc = function (rows) { - t.same(rows.toString('utf8'), [ + t.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# first', 'ok 1 should be truthy', @@ -114,6 +127,9 @@ tap.test('more planned in a second test', function (t) { ' operator: fail', ' expected: 2', ' actual: 1', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', ' ...', '', '1..3', diff --git a/test/fail.js b/test/fail.js index 54c544cc..820cf27e 100644 --- a/test/fail.js +++ b/test/fail.js @@ -3,12 +3,14 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + tap.test('array test', function (tt) { tt.plan(1); var test = tape.createHarness({ exit : false }); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# array', 'ok 1 should be equivalent', @@ -20,6 +22,14 @@ tap.test('array test', function (tt) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' stack: |-', + ' Error: should be equivalent', + ' [... stack stripped ...]', + ' at $TEST/fail.js:$LINE:$COL', + ' at eval (eval at ($TEST/fail.js:$LINE:$COL), :$LINE:$COL)', + ' at eval (eval at ($TEST/fail.js:$LINE:$COL), :$LINE:$COL)', + ' at Test. ($TEST/fail.js:$LINE:$COL)', + ' [... stack stripped ...]', ' ...', '', '1..5', diff --git a/test/stackTrace.js b/test/stackTrace.js index bde1bc50..110da365 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -66,6 +66,67 @@ tap.test('preserves stack trace with newlines', function (tt) { }); }); +tap.test('preserves stack trace for failed assertions', function (tt) { + tt.plan(5); + + 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.stack, 'string') + stack = data.diag.stack || '' + tt.ok(/^Error: false should be true(\n at .+)+/.exec(stack), 'stack should be a stack') + tt.deepEqual(data, { + ok: false, + id: 1, + name: "false should be true", + diag: { + stack: stack, + operator: 'equal', + expected: false, + actual: true + } + }); + }); + + stream.pipe(concat(function (body) { + var body = body.toString('utf8') + tt.equal( + body, + 'TAP version 13\n' + + '# t.equal stack trace\n' + + 'not ok 1 false should be true\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: false\n' + + ' actual: true\n' + + ' stack: |-\n' + + ' ' + + stack.replace(/\n/g, '\n ') + '\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + tt.deepEqual(getDiag(body), { + stack: stack, + operator: 'equal', + expected: false, + actual: true + }); + })); + + test('t.equal stack trace', function (t) { + t.plan(1); + t.equal(true, false, 'false should be true'); + }); +}); + function getDiag (body) { var yamlStart = body.indexOf(' ---'); var yamlEnd = body.indexOf(' ...\n'); diff --git a/test/throws.js b/test/throws.js index 31ab9a45..bc602f0e 100644 --- a/test/throws.js +++ b/test/throws.js @@ -2,6 +2,8 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + function fn() { throw new TypeError('RegExp'); } @@ -20,7 +22,7 @@ tap.test('failures', function (tt) { var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { tt.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# non functions\n' + 'not ok 1 should throw\n' @@ -30,6 +32,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(undefined) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 2 should throw\n' + ' ---\n' @@ -38,6 +45,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(null) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 3 should throw\n' + ' ---\n' @@ -46,6 +58,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(true) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 4 should throw\n' + ' ---\n' @@ -54,6 +71,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(false) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 5 should throw\n' + ' ---\n' @@ -62,6 +84,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage('abc') + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 6 should throw\n' + ' ---\n' @@ -70,6 +97,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(/a/g) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 7 should throw\n' + ' ---\n' @@ -78,6 +110,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage([]) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + 'not ok 8 should throw\n' + ' ---\n' @@ -86,6 +123,11 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage({}) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '# function\n' + 'not ok 9 should throw\n' @@ -93,6 +135,11 @@ tap.test('failures', function (tt) { + ' operator: throws\n' + ' expected: undefined\n' + ' actual: undefined\n' + + ' stack: |-\n' + + ' Error: should throw\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '# custom error messages\n' + 'ok 10 "message" is enumerable\n' diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index e44e3c78..7b8bf647 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -2,17 +2,22 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + tap.test('timeoutAfter test', function (tt) { tt.plan(1); var test = tape.createHarness(); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# timeoutAfter', 'not ok 1 test timed out after 1ms', ' ---', ' operator: fail', + ' stack: |-', + ' Error: test timed out after 1ms', + ' [... stack stripped ...]', ' ...', '', '1..1', diff --git a/test/too_many.js b/test/too_many.js index 233a7abc..e06cb639 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -3,12 +3,14 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + tap.test('array test', function (tt) { tt.plan(1); var test = tape.createHarness({ exit : false }); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# array', 'ok 1 should be equivalent', @@ -20,6 +22,14 @@ tap.test('array test', function (tt) { ' operator: fail', ' expected: 3', ' actual: 4', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at $TEST/too_many.js:$LINE:$COL', + ' at eval (eval at ($TEST/too_many.js:$LINE:$COL), :$LINE:$COL)', + ' at eval (eval at ($TEST/too_many.js:$LINE:$COL), :$LINE:$COL)', + ' at Test. ($TEST/too_many.js:$LINE:$COL)', + ' [... stack stripped ...]', ' ...', 'ok 6 should be equivalent', '', diff --git a/test/undef.js b/test/undef.js index d3ae8d40..a3101a26 100644 --- a/test/undef.js +++ b/test/undef.js @@ -2,13 +2,15 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; + tap.test('array test', function (tt) { tt.plan(1); var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { tt.equal( - body.toString('utf8'), + stripFullStack(body.toString('utf8')), 'TAP version 13\n' + '# undef\n' + 'not ok 1 should be equivalent\n' @@ -18,6 +20,11 @@ tap.test('array test', function (tt) { + ' { beep: undefined }\n' + ' actual: |-\n' + ' {}\n' + + ' stack: |-\n' + + ' Error: should be equivalent\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/undef.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + ' ...\n' + '\n' + '1..1\n' From c7859a274b823823b4de1522959d2c06a1f3bd2b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 4 Dec 2016 00:12:41 -0800 Subject: [PATCH 293/373] [Tests] fix stack differences on node 0.8 --- test/common.js | 4 +++- test/exit.js | 4 ++-- test/fail.js | 4 ++-- test/too_many.js | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/common.js b/test/common.js index 22d7854c..c8f7db54 100644 --- a/test/common.js +++ b/test/common.js @@ -22,6 +22,7 @@ module.exports.getDiag = function (body) { // placeholder $TEST variable. // 2) Line positions within the file might change. We handle this by replacing // line and column markers with placeholder $LINE and $COL "variables" +// a) node 0.8 does not provide nested eval line numbers, so we remove them // 3) Stacks themselves change frequently with refactoring. We've even run into // issues with node library refactorings "breaking" stack traces. Most of // these changes are irrelevant to the tests themselves. To counter this, we @@ -35,7 +36,8 @@ module.exports.stripFullStack = function (output) { var stripChangingData = function (line) { var withoutDirectory = line.replace(__dirname, '$TEST'); var withoutLineNumbers = withoutDirectory.replace(/:\d+:\d+/g, ':$LINE:$COL'); - return withoutLineNumbers; + var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \:\$LINE:\$COL\)$/, ')'); + return withoutNestedLineNumbers; } if (m) { diff --git a/test/exit.js b/test/exit.js index 5736895d..2cf9a9b5 100644 --- a/test/exit.js +++ b/test/exit.js @@ -56,8 +56,8 @@ tap.test('exit fail', function (t) { ' Error: should be equivalent', ' [... stack stripped ...]', ' at $TEST/exit/fail.js:$LINE:$COL', - ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL), :$LINE:$COL)', - ' at eval (eval at ($TEST/exit/fail.js:$LINE:$COL), :$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 ...]', ' ...', diff --git a/test/fail.js b/test/fail.js index 820cf27e..9aeb914b 100644 --- a/test/fail.js +++ b/test/fail.js @@ -26,8 +26,8 @@ tap.test('array test', function (tt) { ' Error: should be equivalent', ' [... stack stripped ...]', ' at $TEST/fail.js:$LINE:$COL', - ' at eval (eval at ($TEST/fail.js:$LINE:$COL), :$LINE:$COL)', - ' at eval (eval at ($TEST/fail.js:$LINE:$COL), :$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 ...]', ' ...', diff --git a/test/too_many.js b/test/too_many.js index e06cb639..04cea91f 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -26,8 +26,8 @@ tap.test('array test', function (tt) { ' Error: plan != count', ' [... stack stripped ...]', ' at $TEST/too_many.js:$LINE:$COL', - ' at eval (eval at ($TEST/too_many.js:$LINE:$COL), :$LINE:$COL)', - ' at eval (eval at ($TEST/too_many.js:$LINE:$COL), :$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 ...]', ' ...', From 995ddb254ab5e6048b4d049b902601b597ff24e0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 4 Dec 2016 00:14:14 -0800 Subject: [PATCH 294/373] [Cleanup] elses need cuddles --- lib/default_stream.js | 3 +-- lib/results.js | 6 ++---- lib/test.js | 15 +++++---------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/default_stream.js b/lib/default_stream.js index c8e99180..12051773 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -21,8 +21,7 @@ module.exports = function () { if (fs.writeSync && /^win/.test(process.platform)) { try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e) } - } - else { + } else { try { console.log(line) } catch (e) { stream.emit('error', e) } } diff --git a/lib/results.js b/lib/results.js index 35bf09f3..36586530 100644 --- a/lib/results.js +++ b/lib/results.js @@ -59,8 +59,7 @@ Results.prototype.createStream = function (opts) { }); }); self.on('done', function () { output.queue(null) }); - } - else { + } else { output = resumer(); output.queue('TAP version 13\n'); self._stream.pipe(output); @@ -149,8 +148,7 @@ function encodeResult (res, count) { 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 { + } else { output += inner + 'expected: ' + ex + '\n'; output += inner + 'actual: ' + ac + '\n'; } diff --git a/lib/test.js b/lib/test.js index 0b48ed6f..d08ad99b 100644 --- a/lib/test.js +++ b/lib/test.js @@ -29,11 +29,9 @@ var getTestArgs = function (name_, opts_, cb_) { var t = typeof arg; if (t === 'string') { name = arg; - } - else if (t === 'object') { + } else if (t === 'object') { opts = arg || opts; - } - else if (t === 'function') { + } else if (t === 'function') { cb = arg; } } @@ -66,7 +64,7 @@ function Test (name_, opts_, cb_) { return val.apply(self, arguments); }; } - else return val; + return val; })(this, this[prop]); } } @@ -176,8 +174,7 @@ Test.prototype._exit = function () { actual : this.assertCount, exiting : true }); - } - else if (!this.ended) { + } else if (!this.ended) { this.fail('test exited without ending', { exiting: true }); @@ -188,9 +185,7 @@ Test.prototype._pendingAsserts = function () { if (this._plan === undefined) { return 1; } - else { - return this._plan - (this._progeny.length + this.assertCount); - } + return this._plan - (this._progeny.length + this.assertCount); }; Test.prototype._assert = function assert (ok, opts) { From 8b3a77e595b8ee328d016fa12c773e9e7299910a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 4 Dec 2016 00:57:44 -0800 Subject: [PATCH 295/373] [Tests] fix thrower stack in node 0.8 --- test/throws.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/throws.js b/test/throws.js index bc602f0e..197ce68d 100644 --- a/test/throws.js +++ b/test/throws.js @@ -16,6 +16,14 @@ function getNonFunctionMessage(fn) { } } +var getter = function () { return 'message'; }; +var messageGetterError = Object.defineProperty( + { custom: 'error' }, + 'message', + { configurable: true, enumerable: true, get: getter } +); +var thrower = function () { throw messageGetterError; }; + tap.test('failures', function (tt) { tt.plan(1); @@ -173,14 +181,8 @@ tap.test('failures', function (tt) { test('custom error messages', function (t) { t.plan(3); - var getter = function () { return 'message'; }; - var messageGetterError = Object.defineProperty( - { custom: 'error' }, - 'message', - { configurable: true, enumerable: true, get: getter } - ); t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable'); - t.throws(function () { throw messageGetterError; }, "{ custom: 'error', message: 'message' }"); + t.throws(thrower, "{ custom: 'error', message: 'message' }"); t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same'); }); From bdf2b04e8262eba2797acf7927b93f5b329ffe67 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 5 Feb 2017 23:45:48 +0100 Subject: [PATCH 296/373] tap-min moved to derhuerst/tap-min I took over the maintenance of tap-min. tap-min@1.2.0 has been published from derhuerst/tap-min. --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index a45db947..ba423460 100644 --- a/readme.markdown +++ b/readme.markdown @@ -101,7 +101,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/juliangruber/tap-bail - https://github.com/kirbysayshi/tap-browser-color - https://github.com/gummesson/tap-json - - https://github.com/gummesson/tap-min + - https://github.com/derhuerst/tap-min - https://github.com/calvinmetcalf/tap-nyan - https://www.npmjs.org/package/tap-pessimist - https://github.com/toolness/tap-prettify From e6d4625e175a42e3694a88a7061dc9e3f593cd37 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 11 Feb 2017 21:26:26 -0800 Subject: [PATCH 297/373] [Dev Deps] update `concat-stream`, `js-yaml` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b26975f2..b7fd2a8c 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ "through": "~2.3.8" }, "devDependencies": { - "concat-stream": "~1.5.2", + "concat-stream": "~1.6.0", "falafel": "~2.0.0", - "js-yaml": "~3.7.0", + "js-yaml": "~3.8.0", "tap": "~8.0.1", "tap-parser": "~3.0.4" }, From 66519cb1f018c50676b889ae8980fdd67a21de18 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 11 Feb 2017 21:26:35 -0800 Subject: [PATCH 298/373] [Deps] update `resolve` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b7fd2a8c..951dcbc2 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "inherits": "~2.0.3", "minimist": "~1.2.0", "object-inspect": "~1.2.1", - "resolve": "~1.1.7", + "resolve": "~1.2.0", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" From dc1ffa5c8e7486a15b785ff0f14b34ef879a8d57 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 May 2017 17:17:31 -0800 Subject: [PATCH 299/373] [Deps] update `object-inspect` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 951dcbc2..f280c64a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", - "object-inspect": "~1.2.1", + "object-inspect": "~1.2.2", "resolve": "~1.2.0", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", From 35e47e1652dca17af9abfbb9050753dfe9c91ea0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 23 May 2017 21:25:55 -0700 Subject: [PATCH 300/373] [Tests] npm v4.6+ breaks on node < v1 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e564088a..6dd82b52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,10 @@ node_js: - "0.10" - "0.8" before_install: - - 'if [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' + - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' + - 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ]; then npm install -g npm@4.5 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' +install: + - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' matrix: fast_finish: true allow_failures: From df48bfae19d8ba4b48055dacac8b81912b8887f2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 11 Jun 2017 12:57:37 -0700 Subject: [PATCH 301/373] Only apps should have lock files. --- .gitignore | 6 ++++++ .npmrc | 1 + 2 files changed, 7 insertions(+) create mode 100644 .npmrc diff --git a/.gitignore b/.gitignore index 07e6e472..77f05fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ +# gitignore + /node_modules + +# Only apps should have lockfiles +yarn.lock +package-lock.json diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..43c97e71 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From 4375661d4de9fb69da93e981c97f3d1eeda55871 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 11 Jun 2017 12:58:09 -0700 Subject: [PATCH 302/373] [Tests] npm v5+ breaks on node < v4 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6dd82b52..c29256bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ node_js: - "0.8" before_install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - - 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ]; then npm install -g npm@4.5 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' + - 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' matrix: From e030260c86e48afd3edf8bd77bb048975f348eff Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 11 Jun 2017 12:59:27 -0700 Subject: [PATCH 303/373] [Tests] on `node` `v8`; no need for sudo; `v0.8` passes now; allow v5/v7/iojs to fail. --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c29256bf..6ac7d396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js -sudo: true +sudo: false node_js: + - "8" - "7" - "6" - "5" @@ -17,4 +18,6 @@ install: matrix: fast_finish: true allow_failures: - - node_js: "0.8" + - node_js: "7" + - node_js: "5" + - node_js: "iojs" From 7eb9e3638743bd513bc69ae3f7db61401d68f7e5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 15 Jun 2017 21:48:00 -0700 Subject: [PATCH 304/373] [Dev Deps] update `falafel`, `js-yaml` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f280c64a..f818a30d 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ }, "devDependencies": { "concat-stream": "~1.6.0", - "falafel": "~2.0.0", - "js-yaml": "~3.8.0", + "falafel": "~2.1.0", + "js-yaml": "~3.8.4", "tap": "~8.0.1", "tap-parser": "~3.0.4" }, From 1a8e936235d8cf8269ce0683786761286a129bd8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 15 Jun 2017 21:51:26 -0700 Subject: [PATCH 305/373] [Deps] update `glob`, `resolve` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f818a30d..d8b2cd74 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,12 @@ "defined": "~1.0.0", "for-each": "~0.3.2", "function-bind": "~1.1.0", - "glob": "~7.1.1", + "glob": "~7.1.2", "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", "object-inspect": "~1.2.2", - "resolve": "~1.2.0", + "resolve": "~1.3.3", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" From dd93216954089f41d20a6a11ea7289978f8ebdbe Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 23 Jun 2017 18:28:33 -0700 Subject: [PATCH 306/373] [Fix] fix spurious "test exited without ending" Fixes #223. @Raynos identified this line as the issue: https://github.com/substack/tape/issues/223#issuecomment-167920577 Let's finally fix this :) --- bin/tape | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/tape b/bin/tape index 498910cd..8fdbbdd9 100755 --- a/bin/tape +++ b/bin/tape @@ -26,10 +26,12 @@ opts.require.forEach(function(module) { }); opts._.forEach(function (arg) { - glob(arg, function (err, files) { - files.forEach(function (file) { - require(resolvePath(cwd, file)); - }); + // If glob does not match, `files` will be an empty array. + // Note: `glob.sync` may throw an error and crash the node process. + var files = glob.sync(arg); + + files.forEach(function (file) { + require(resolvePath(cwd, file)); }); }); From b06f9140729e61fad95daf5b765d77809b304f96 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jun 2017 14:28:14 -0700 Subject: [PATCH 307/373] [Refactor] instead of throwing on `undefined.forEach`, throw explicitly. --- bin/tape | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/tape b/bin/tape index 8fdbbdd9..d0b3bec5 100755 --- a/bin/tape +++ b/bin/tape @@ -30,6 +30,10 @@ opts._.forEach(function (arg) { // Note: `glob.sync` may throw an error and crash the node process. var files = glob.sync(arg); + if (!Array.isArray(files)) { + throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.'); + } + files.forEach(function (file) { require(resolvePath(cwd, file)); }); From 1d0df26328d89b9ed1671260836ff8fb4079c265 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jun 2017 14:31:01 -0700 Subject: [PATCH 308/373] v4.7.0 - [Fix] fix spurious "test exited without ending" (#223) - [New] show full error stack on failure (#330) - [Deps] update `resolve`, `object-inspect`, `glob` - [Dev Deps] update `tap`, `concat-stream`, `js-yaml` - [Tests] fix stack differences on node 0.8 - [Tests] npm v4.6+ breaks on node < v1, npm v5+ breaks on node < v4 - [Tests] on `node` `v8`; no need for sudo; `v0.8` passes now; allow v5/v7/iojs to fail. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8b2cd74..7048c2da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.6.3", + "version": "4.7.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From bd6db7b123a3a7e7c12bd2816b1840ed418a9d2a Mon Sep 17 00:00:00 2001 From: Gabriel Csapo Date: Wed, 28 Jun 2017 06:10:51 -0400 Subject: [PATCH 309/373] updates README.md and adds tap-html --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index ba423460..92df8135 100644 --- a/readme.markdown +++ b/readme.markdown @@ -113,6 +113,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/axross/tap-notify - https://github.com/zoubin/tap-summary - https://github.com/Hypercubed/tap-markdown + - https://github.com/gabrielcsapo/tap-html To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From b50084ccb22c2de3c51bdbdc62ae788443b10483 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 31 Jul 2017 15:49:58 -0700 Subject: [PATCH 310/373] [Deps] update `resolve`, `object-inspect` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7048c2da..c759cec5 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", - "object-inspect": "~1.2.2", - "resolve": "~1.3.3", + "object-inspect": "~1.3.0", + "resolve": "~1.4.0", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" From c82c593d8cba15abfd7914f418e677ccfc23eaf6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 31 Jul 2017 15:50:06 -0700 Subject: [PATCH 311/373] [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c759cec5..220d74e9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "concat-stream": "~1.6.0", "falafel": "~2.1.0", - "js-yaml": "~3.8.4", + "js-yaml": "~3.9.1", "tap": "~8.0.1", "tap-parser": "~3.0.4" }, From 342c89ac8cc5a922eea40681908c69b37c10c39a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 31 Jul 2017 16:02:22 -0700 Subject: [PATCH 312/373] v4.8.0 - [New] update `object-inspect` to provide better output for arrays with extra properties added - [Deps] update `resolve` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 220d74e9..7ade60f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.7.0", + "version": "4.8.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From fde82161a9e53cb104f94a8b41c40af00cbcaee4 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 1 Sep 2017 20:15:24 +0100 Subject: [PATCH 313/373] correct spelling mistake --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 92df8135..1e4b5eb7 100644 --- a/readme.markdown +++ b/readme.markdown @@ -140,7 +140,7 @@ var test = require('tape') ## test([name], [opts], cb) Create a new test with an optional `name` string and optional `opts` object. -`cb(t)` fires with the new test object `t` once all preceeding tests have +`cb(t)` fires with the new test object `t` once all preceding tests have finished. Tests execute serially. Available `opts` options are: From 5565ef5c965dbd113408b79b30cb0329368e3127 Mon Sep 17 00:00:00 2001 From: Chris Nicola Date: Fri, 1 Sep 2017 14:56:55 -0700 Subject: [PATCH 314/373] Use local reference for clearTimeout global This ensures it is robust against stubbing in tests as is done with safeSetTimeout. --- lib/test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index d08ad99b..ca343b6f 100644 --- a/lib/test.js +++ b/lib/test.js @@ -16,6 +16,7 @@ var nextTick = typeof setImmediate !== 'undefined' : process.nextTick ; var safeSetTimeout = setTimeout; +var safeClearTimeout = clearTimeout; inherits(Test, EventEmitter); @@ -127,7 +128,7 @@ Test.prototype.timeoutAfter = function(ms) { self.end(); }, ms); this.once('end', function() { - clearTimeout(timeout); + safeClearTimeout(timeout); }); } From b6f5aaff16144520c182ab33bd915fe14159a913 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 14:33:41 -0700 Subject: [PATCH 315/373] Use lib directory instead of package root for stacktrace checking --- lib/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index ca343b6f..9cd9492e 100644 --- a/lib/test.js +++ b/lib/test.js @@ -216,7 +216,7 @@ Test.prototype._assert = function assert (ok, opts) { if (!ok) { var e = new Error('exception'); var err = (e.stack || '').split('\n'); - var dir = path.dirname(__dirname) + path.sep; + var dir = __dirname + path.sep; for (var i = 0; i < err.length; i++) { var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]); From d16514294623c710598a015fee233271e6bfee2c Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 15:35:32 -0700 Subject: [PATCH 316/373] Update tests to correctly reference (or ignore) at prop --- test/circular-things.js | 1 + test/common.js | 14 +++++++++----- test/deep-equal-failure.js | 6 ++++++ test/double_end.js | 1 + test/exit.js | 3 +++ test/fail.js | 1 + test/stackTrace.js | 26 ++++++++++++++++++++------ test/throws.js | 9 +++++++++ test/too_many.js | 1 + test/undef.js | 1 + 10 files changed, 52 insertions(+), 11 deletions(-) diff --git a/test/circular-things.js b/test/circular-things.js index bbabc919..4bda3e14 100644 --- a/test/circular-things.js +++ b/test/circular-things.js @@ -20,6 +20,7 @@ tap.test('circular test', function (assert) { + ' {}\n' + ' actual: |-\n' + ' { circular: [Circular] }\n' + + ' at: Test. ($TEST/circular-things.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should be equal\n' + ' [... stack stripped ...]\n' diff --git a/test/common.js b/test/common.js index c8f7db54..4ded4e5f 100644 --- a/test/common.js +++ b/test/common.js @@ -1,3 +1,4 @@ +var path = require('path'); var yaml = require('js-yaml'); module.exports.getDiag = function (body) { @@ -7,10 +8,11 @@ module.exports.getDiag = function (body) { return line.slice(2); }).join('\n'); - // The stack trace will vary depending on where the code is run, so just - // strip it out. + // 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; } @@ -19,7 +21,8 @@ module.exports.getDiag = function (body) { // 1) The base checkout directory of tape might change. Because stack traces // include absolute paths, the stack traces will change depending on the // checkout path. We handle this by replacing the base test directory with a -// placeholder $TEST variable. +// placeholder $TEST variable and the package root with a placehodler +// $TAPE variable. // 2) Line positions within the file might change. We handle this by replacing // line and column markers with placeholder $LINE and $COL "variables" // a) node 0.8 does not provide nested eval line numbers, so we remove them @@ -34,8 +37,9 @@ module.exports.stripFullStack = function (output) { var m = line.match(/[ ]{8}at .*\((.*)\)/); var stripChangingData = function (line) { - var withoutDirectory = line.replace(__dirname, '$TEST'); - var withoutLineNumbers = withoutDirectory.replace(/:\d+:\d+/g, ':$LINE:$COL'); + var withoutTestDir = line.replace(__dirname, '$TEST'); + var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); + var withoutLineNumbers = withoutPackageDir.replace(/:\d+:\d+/g, ':$LINE:$COL'); var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \:\$LINE:\$COL\)$/, ')'); return withoutNestedLineNumbers; } diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 4836037b..4c0d4eed 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -26,6 +26,7 @@ tap.test('deep equal failure', function (assert) { + ' { b: 2 }\n' + ' actual: |-\n' + ' { a: 1 }\n' + + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should be equal\n' + ' [... stack stripped ...]\n' @@ -48,6 +49,7 @@ tap.test('deep equal failure', function (assert) { parser.once('assert', function (data) { delete data.diag.stack; + delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -85,6 +87,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { + ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n' + ' actual: |-\n' + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' + + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should be equal\n' + ' [... stack stripped ...]\n' @@ -107,6 +110,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { parser.once('assert', function (data) { delete data.diag.stack; + delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, @@ -144,6 +148,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + ' actual: |-\n' + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' at: Test. ($TEST/deep-equal-failure.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should be equal\n' + ' [... stack stripped ...]\n' @@ -166,6 +171,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { parser.once('assert', function (data) { delete data.diag.stack; + delete data.diag.at; assert.deepEqual(data, { ok: false, id: 1, diff --git a/test/double_end.js b/test/double_end.js index 212606e9..b6d65817 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -41,6 +41,7 @@ test(function (t) { 'not ok 2 .end() called twice', ' ---', ' operator: fail', + ' at: Timeout.doEnd [as _onTimeout] ($TEST/double_end/double.js:$LINE:$COL)', ' stack: |-', ' Error: .end() called twice', ' [... stack stripped ...]', diff --git a/test/exit.js b/test/exit.js index 2cf9a9b5..2a9d2f0c 100644 --- a/test/exit.js +++ b/test/exit.js @@ -52,6 +52,7 @@ tap.test('exit fail', function (t) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' at: Test. ($TEST/exit/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', @@ -93,6 +94,7 @@ tap.test('too few exit', function (t) { ' operator: fail', ' expected: 6', ' actual: 5', + ' at: process. ($TAPE/index.js:$LINE:$COL)', ' stack: |-', ' Error: plan != count', ' [... stack stripped ...]', @@ -127,6 +129,7 @@ tap.test('more planned in a second test', function (t) { ' operator: fail', ' expected: 2', ' actual: 1', + ' at: process. ($TAPE/index.js:$LINE:$COL)', ' stack: |-', ' Error: plan != count', ' [... stack stripped ...]', diff --git a/test/fail.js b/test/fail.js index 9aeb914b..73029639 100644 --- a/test/fail.js +++ b/test/fail.js @@ -22,6 +22,7 @@ tap.test('array test', function (tt) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', + ' at: Test. ($TEST/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', diff --git a/test/stackTrace.js b/test/stackTrace.js index 110da365..90cc39f6 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -13,6 +13,7 @@ tap.test('preserves stack trace with newlines', function (tt) { var stackTrace = 'foo\n bar'; parser.once('assert', function (data) { + delete data.diag.at; tt.deepEqual(data, { ok: false, id: 1, @@ -27,7 +28,8 @@ tap.test('preserves stack trace with newlines', function (tt) { }); stream.pipe(concat(function (body) { - var body = body.toString('utf8') + var body = body.toString('utf8'); + body = stripAt(body); tt.equal( body, 'TAP version 13\n' @@ -67,7 +69,7 @@ tap.test('preserves stack trace with newlines', function (tt) { }); tap.test('preserves stack trace for failed assertions', function (tt) { - tt.plan(5); + tt.plan(6); var test = tape.createHarness(); var stream = test.createStream(); @@ -75,14 +77,17 @@ tap.test('preserves stack trace for failed assertions', function (tt) { var stack = '' parser.once('assert', function (data) { - tt.equal(typeof data.diag.stack, 'string') - stack = data.diag.stack || '' + tt.equal(typeof data.diag.at, 'string'); + tt.equal(typeof data.diag.stack, 'string'); + at = data.diag.at || ''; + stack = data.diag.stack || ''; tt.ok(/^Error: false should be true(\n 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: false, @@ -92,7 +97,8 @@ tap.test('preserves stack trace for failed assertions', function (tt) { }); stream.pipe(concat(function (body) { - var body = body.toString('utf8') + var body = body.toString('utf8'); + body = stripAt(body); tt.equal( body, 'TAP version 13\n' @@ -134,5 +140,13 @@ function getDiag (body) { return line.slice(2); }).join('\n'); - return yaml.safeLoad(diag); + // 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, ''); +} \ No newline at end of file diff --git a/test/throws.js b/test/throws.js index 197ce68d..5b576eb1 100644 --- a/test/throws.js +++ b/test/throws.js @@ -40,6 +40,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage(undefined) + '\n' + ' [... stack stripped ...]\n' @@ -53,6 +54,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage(null) + '\n' + ' [... stack stripped ...]\n' @@ -66,6 +68,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage(true) + '\n' + ' [... stack stripped ...]\n' @@ -79,6 +82,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage(false) + '\n' + ' [... stack stripped ...]\n' @@ -92,6 +96,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage('abc') + '\n' + ' [... stack stripped ...]\n' @@ -105,6 +110,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage(/a/g) + '\n' + ' [... stack stripped ...]\n' @@ -118,6 +124,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage([]) + '\n' + ' [... stack stripped ...]\n' @@ -131,6 +138,7 @@ tap.test('failures', function (tt) { + ' undefined\n' + ' actual: |-\n' + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' TypeError: ' + getNonFunctionMessage({}) + '\n' + ' [... stack stripped ...]\n' @@ -143,6 +151,7 @@ tap.test('failures', function (tt) { + ' operator: throws\n' + ' expected: undefined\n' + ' actual: undefined\n' + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should throw\n' + ' [... stack stripped ...]\n' diff --git a/test/too_many.js b/test/too_many.js index 04cea91f..b7d59e86 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -22,6 +22,7 @@ tap.test('array test', function (tt) { ' operator: fail', ' expected: 3', ' actual: 4', + ' at: Test. ($TEST/too_many.js:$LINE:$COL)', ' stack: |-', ' Error: plan != count', ' [... stack stripped ...]', diff --git a/test/undef.js b/test/undef.js index a3101a26..f809384b 100644 --- a/test/undef.js +++ b/test/undef.js @@ -20,6 +20,7 @@ tap.test('array test', function (tt) { + ' { beep: undefined }\n' + ' actual: |-\n' + ' {}\n' + + ' at: Test. ($TEST/undef.js:$LINE:$COL)\n' + ' stack: |-\n' + ' Error: should be equivalent\n' + ' [... stack stripped ...]\n' From 1eba217edbbdb84104ceac493062729fc3fe20fd Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 16:29:34 -0700 Subject: [PATCH 317/373] Reverse engineer error for at prop too --- test/double_end.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/double_end.js b/test/double_end.js index b6d65817..5457cb27 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -24,6 +24,7 @@ test(function (t) { to._onTimeout = doEnd; var stackExpected; + var atExpected; try { to._onTimeout(); } @@ -31,6 +32,7 @@ test(function (t) { stackExpected = stripFullStack(e.stack).split('\n')[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')); @@ -41,7 +43,7 @@ test(function (t) { 'not ok 2 .end() called twice', ' ---', ' operator: fail', - ' at: Timeout.doEnd [as _onTimeout] ($TEST/double_end/double.js:$LINE:$COL)', + ' ' + atExpected, ' stack: |-', ' Error: .end() called twice', ' [... stack stripped ...]', From 698f19735e2c3d99fa944bfb7bb320169792e615 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Fri, 8 Sep 2017 11:01:28 -0700 Subject: [PATCH 318/373] Check added stack trace parts for filename match --- lib/test.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9cd9492e..2d68fd1b 100644 --- a/lib/test.js +++ b/lib/test.js @@ -225,18 +225,14 @@ Test.prototype._assert = function assert (ok, opts) { } var s = m[1].split(/\s+/); - var filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]); - if (!filem) { - filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]); - - if (!filem) { - filem = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]); - - if (!filem) { - continue; - } - } + var filemRe = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/; + var filem; + var sIndex; + for (sIndex in s.slice(0, 4)) { + filem = filemRe.exec(s[sIndex]); + if (filem) break; } + if (! filem) continue; if (filem[1].slice(0, dir.length) === dir) { continue; From 32faf707e770f63071823f4a97122d7724d57aa9 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 16:07:15 -0700 Subject: [PATCH 319/373] Provide placeholder names for anonymous functions --- lib/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index 2d68fd1b..4dc90aa2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -237,13 +237,13 @@ Test.prototype._assert = function assert (ok, opts) { if (filem[1].slice(0, dir.length) === dir) { continue; } - - res.functionName = s[0]; + + res.functionName = s.length > 1 ? s[0] : ''; res.file = filem[1]; res.line = Number(filem[2]); if (filem[3]) res.column = filem[3]; - res.at = m[1]; + res.at = s.length > 1 ? m[1] : ' (' + m[1] + ')'; break; } } From f619f604af08075b7c758c77924fdda8f2967704 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 16:07:35 -0700 Subject: [PATCH 320/373] Update existing tests to properly reference anonymous names --- test/exit.js | 2 +- test/fail.js | 2 +- test/too_many.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/exit.js b/test/exit.js index 2a9d2f0c..283301fc 100644 --- a/test/exit.js +++ b/test/exit.js @@ -52,7 +52,7 @@ tap.test('exit fail', function (t) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: Test. ($TEST/exit/fail.js:$LINE:$COL)', + ' at: ($TEST/exit/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', diff --git a/test/fail.js b/test/fail.js index 73029639..2c975bb8 100644 --- a/test/fail.js +++ b/test/fail.js @@ -22,7 +22,7 @@ tap.test('array test', function (tt) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: Test. ($TEST/fail.js:$LINE:$COL)', + ' at: ($TEST/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', diff --git a/test/too_many.js b/test/too_many.js index b7d59e86..3bd0ca56 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -22,7 +22,7 @@ tap.test('array test', function (tt) { ' operator: fail', ' expected: 3', ' actual: 4', - ' at: Test. ($TEST/too_many.js:$LINE:$COL)', + ' at: ($TEST/too_many.js:$LINE:$COL)', ' stack: |-', ' Error: plan != count', ' [... stack stripped ...]', From 601559949295fa6479d877ec5a69ef3dac419f52 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 16:07:45 -0700 Subject: [PATCH 321/373] Test for anonymous function wrapper --- test/anonymous-fn.js | 41 +++++++++++++++++++++++++++++++ test/anonymous-fn/test-wrapper.js | 16 ++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/anonymous-fn.js create mode 100644 test/anonymous-fn/test-wrapper.js diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js new file mode 100644 index 00000000..38712d46 --- /dev/null +++ b/test/anonymous-fn.js @@ -0,0 +1,41 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; +var testWrapper = require('./anonymous-fn/test-wrapper'); + +tap.test('inside anonymous functions', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var tc = function (rows) { + tt.same(stripFullStack(rows.toString('utf8')), [ + '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' + ].join('\n') + '\n'); + }; + + test.createStream().pipe(concat(tc)); + + 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 new file mode 100644 index 00000000..acf66e30 --- /dev/null +++ b/test/anonymous-fn/test-wrapper.js @@ -0,0 +1,16 @@ +// Example of wrapper function that would invoke tape +module.exports = function (testCase) { + return function(t) { + setUp(); + testCase(t); + tearDown(); + }; +} + +function setUp() { + // ... example ... +} + +function tearDown() { + // ... example ... +} From a5fb7eda4cde3880bd07b23efb177bae11124768 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Sun, 10 Sep 2017 16:50:12 -0700 Subject: [PATCH 322/373] Handle stack variation in Node v0.8 --- test/anonymous-fn.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index 38712d46..2856ea82 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -10,7 +10,15 @@ tap.test('inside anonymous functions', function (tt) { var test = tape.createHarness(); var tc = function (rows) { - tt.same(stripFullStack(rows.toString('utf8')), [ + var body = stripFullStack(rows.toString('utf8')); + + // Handle stack trace variation in Node v0.8 + body = body.replace( + 'at Test.module.exports', + 'at Test.' + ); + + tt.same(body, [ 'TAP version 13', '# wrapped test failure', 'not ok 1 fail', From 3c2087a214cd9f0086bc12ec1ec24b1ab02293a0 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Mon, 11 Sep 2017 14:39:30 -0700 Subject: [PATCH 323/373] Test name with spaces --- test/has spaces.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/has spaces.js diff --git a/test/has spaces.js b/test/has spaces.js new file mode 100644 index 00000000..ae18e71d --- /dev/null +++ b/test/has spaces.js @@ -0,0 +1,40 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('array test', function (tt) { + 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', + '' + ].join('\n')); + }; + + test.createStream().pipe(concat(tc)); + + test('fail', function (t) { + t.fail('this should fail'); + t.end(); + }); +}); From bf5a750937df4920ab9e2e965be02ac69dd43f72 Mon Sep 17 00:00:00 2001 From: Andrew Fong Date: Mon, 11 Sep 2017 16:36:23 -0700 Subject: [PATCH 324/373] Handle spaces in path name for setting file, line no --- lib/test.js | 68 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/lib/test.js b/lib/test.js index 4dc90aa2..548ffbd2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -217,33 +217,65 @@ Test.prototype._assert = function assert (ok, opts) { var e = new Error('exception'); var err = (e.stack || '').split('\n'); var dir = __dirname + path.sep; - + for (var i = 0; i < err.length; i++) { - var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]); + /* + Stack trace lines may resemble one of the following. We need + to should correctly extract a function name (if any) and + path / line no. for each line. + + at myFunction (/path/to/file.js:123:45) + at myFunction (/path/to/file.other-ext:123:45) + at myFunction (/path to/file.js:123:45) + at myFunction (C:\path\to\file.js:123:45) + at myFunction (/path/to/file.js:123) + at Test. (/path/to/file.js:123:45) + at Test.bound [as run] (/path/to/file.js:123:45) + at /path/to/file.js:123:45 + + Regex has three parts. First is non-capturing group for 'at ' + (plus anything preceding it). + + /^(?:[^\s]*\s*\bat\s+)/ + + Second captures function call description (optional). This is + not necessarily a valid JS function name, but just what the + stack trace is using to represent a function call. It may look + like `` or 'Test.bound [as run]'. + + For our purposes, we assume that, if there is a function + name, it's everything leading up to the first open + parentheses (trimmed) before our pathname. + + /(?:(.*)\s+\()?/ + + Last part captures file path plus line no (and optional + column no). + + /((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ + */ + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ + var m = re.exec(err[i]); + if (!m) { continue; } + + var callDescription = m[1] || ''; + var filePath = m[2]; - var s = m[1].split(/\s+/); - var filemRe = /((?:\/|[A-Z]:\\)[^:\s]+:(\d+)(?::(\d+))?)/; - var filem; - var sIndex; - for (sIndex in s.slice(0, 4)) { - filem = filemRe.exec(s[sIndex]); - if (filem) break; - } - if (! filem) continue; - - if (filem[1].slice(0, dir.length) === dir) { + if (filePath.slice(0, dir.length) === dir) { continue; } - res.functionName = s.length > 1 ? s[0] : ''; - res.file = filem[1]; - res.line = Number(filem[2]); - if (filem[3]) res.column = filem[3]; + // Function call description may not (just) be a function name. + // Try to extract function name by looking at first "word" only. + res.functionName = callDescription.split(/s+/)[0] + res.file = filePath; + res.line = Number(m[3]); + if (m[4]) res.column = Number(m[4]); - res.at = s.length > 1 ? m[1] : ' (' + m[1] + ')'; + res.at = callDescription + ' (' + filePath + ')'; break; } } From b66f8f80928bb82f0817407880a139ad118daf01 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 24 Sep 2017 11:53:47 -0800 Subject: [PATCH 325/373] [Deps] update `function-bind` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ade60f2..3a10d05f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deep-equal": "~1.0.1", "defined": "~1.0.0", "for-each": "~0.3.2", - "function-bind": "~1.1.0", + "function-bind": "~1.1.1", "glob": "~7.1.2", "has": "~1.0.1", "inherits": "~2.0.3", From f90e487aad2d787b6d725186e37bf352110dd97d Mon Sep 17 00:00:00 2001 From: Norman Date: Sat, 14 Oct 2017 14:01:49 -0700 Subject: [PATCH 326/373] normalize path separators in stacks --- test/common.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index 4ded4e5f..9e4a0391 100644 --- a/test/common.js +++ b/test/common.js @@ -39,7 +39,8 @@ module.exports.stripFullStack = function (output) { var stripChangingData = function (line) { var withoutTestDir = line.replace(__dirname, '$TEST'); var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); - var withoutLineNumbers = withoutPackageDir.replace(/:\d+:\d+/g, ':$LINE:$COL'); + 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; } From 10b7dcd581a3b1f07e34cd63957926b9ce6e6bab Mon Sep 17 00:00:00 2001 From: Norman Date: Sat, 7 Oct 2017 13:44:36 -0700 Subject: [PATCH 327/373] [Fix] fix stack where actual is falsy Fixes #399. --- lib/results.js | 2 +- test/stackTrace.js | 73 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/lib/results.js b/lib/results.js index 36586530..76ee75de 100644 --- a/lib/results.js +++ b/lib/results.js @@ -157,7 +157,7 @@ function encodeResult (res, count) { output += inner + 'at: ' + res.at + '\n'; } - var actualStack = res.actual && res.actual.stack; + 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) { diff --git a/test/stackTrace.js b/test/stackTrace.js index 90cc39f6..14241ff6 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -81,11 +81,11 @@ tap.test('preserves stack trace for failed assertions', function (tt) { tt.equal(typeof data.diag.stack, 'string'); at = data.diag.at || ''; stack = data.diag.stack || ''; - tt.ok(/^Error: false should be true(\n at .+)+/.exec(stack), 'stack should be a stack') + tt.ok(/^Error: true should be false(\n at .+)+/.exec(stack), 'stack should be a stack') tt.deepEqual(data, { ok: false, id: 1, - name: "false should be true", + name: "true should be false", diag: { at: at, stack: stack, @@ -103,7 +103,7 @@ tap.test('preserves stack trace for failed assertions', function (tt) { body, 'TAP version 13\n' + '# t.equal stack trace\n' - + 'not ok 1 false should be true\n' + + 'not ok 1 true should be false\n' + ' ---\n' + ' operator: equal\n' + ' expected: false\n' @@ -129,7 +129,72 @@ tap.test('preserves stack trace for failed assertions', function (tt) { test('t.equal stack trace', function (t) { t.plan(1); - t.equal(true, false, 'false should be true'); + 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'); + at = data.diag.at || ''; + stack = data.diag.stack || ''; + tt.ok(/^Error: false should be true(\n 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 body = body.toString('utf8'); + body = stripAt(body); + tt.equal( + body, + 'TAP version 13\n' + + '# t.equal stack trace\n' + + 'not ok 1 false should be true\n' + + ' ---\n' + + ' operator: equal\n' + + ' expected: true\n' + + ' actual: false\n' + + ' stack: |-\n' + + ' ' + + stack.replace(/\n/g, '\n ') + '\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + tt.deepEqual(getDiag(body), { + 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'); }); }); From 0e68b2d1ff44929ea56c291fa24d9083e3151f84 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 17 Oct 2017 22:47:09 -0700 Subject: [PATCH 328/373] [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a10d05f..ff7ecf19 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "devDependencies": { "concat-stream": "~1.6.0", "falafel": "~2.1.0", - "js-yaml": "~3.9.1", + "js-yaml": "~3.10.0", "tap": "~8.0.1", "tap-parser": "~3.0.4" }, From 00aa1339b61eca78e2a4c52e22cbfdd08deef06a Mon Sep 17 00:00:00 2001 From: John Henry Date: Mon, 13 Nov 2017 13:48:20 -0800 Subject: [PATCH 329/373] Add "onFinish" listener to test harness. --- index.js | 8 ++++++++ lib/results.js | 5 ++++- readme.markdown | 4 ++++ test/onFailure.js | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/onFailure.js diff --git a/index.js b/index.js index f3ffcaee..64d2d0c9 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,10 @@ exports = module.exports = (function () { lazyLoad.onFinish = function () { return getHarness().onFinish.apply(this, arguments); }; + + lazyLoad.onFailure = function() { + return getHarness().onFailure.apply(this, arguments); + }; lazyLoad.getHarness = getHarness @@ -134,6 +138,10 @@ function createHarness (conf_) { test.onFinish = function (cb) { results.on('done', cb); }; + + test.onFailure = function (cb) { + results.on('fail', cb); + }; var only = false; test.only = function () { diff --git a/lib/results.js b/lib/results.js index 76ee75de..305ae6bc 100644 --- a/lib/results.js +++ b/lib/results.js @@ -104,7 +104,10 @@ Results.prototype._watch = function (t) { self.count ++; if (res.ok) self.pass ++ - else self.fail ++ + else { + self.fail ++; + self.emit('fail'); + } }); t.on('test', function (st) { self._watch(st) }); diff --git a/readme.markdown b/readme.markdown index 1e4b5eb7..feebabc4 100644 --- a/readme.markdown +++ b/readme.markdown @@ -162,6 +162,10 @@ Generate a new test that will be skipped over. The onFinish hook will get invoked when ALL tape tests have finished right before tape is about to print the test summary. +## test.onFailure(fn) + +The onFailure hook will get invoked whenever any tape tests has failed. + ## t.plan(n) Declare that `n` assertions should be run. `t.end()` will be called diff --git a/test/onFailure.js b/test/onFailure.js new file mode 100644 index 00000000..e8efdbdb --- /dev/null +++ b/test/onFailure.js @@ -0,0 +1,21 @@ +var tap = require("tap"); +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} +tape.createStream().pipe(mockSink); + +tap.test("on failure", { timeout: 1000 }, function(tt) { + tt.plan(1); + + tape("dummy test", function(t) { + t.fail(); + t.end(); + }); + + tape.onFailure(function() { + tt.pass("tape ended"); + }); +}); From 17276d7473f9d98e37bab47ebdddf74ca1931f43 Mon Sep 17 00:00:00 2001 From: Irakli N Date: Tue, 2 Jan 2018 17:33:41 -0500 Subject: [PATCH 330/373] [New] use `process.env.NODE_TAPE_OBJECT_PRINT_DEPTH` for the default object print depth. --- lib/test.js | 14 +++++++++++++- readme.markdown | 5 +++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index 548ffbd2..ad1cbfb2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -8,6 +8,7 @@ var trim = require('string.prototype.trim'); var bind = require('function-bind'); var forEach = require('for-each'); var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable); +var toLowerCase = bind.call(Function.call, String.prototype.toLowerCase); module.exports = Test; @@ -52,11 +53,22 @@ function Test (name_, opts_, cb_) { this.pendingCount = 0; this._skip = args.opts.skip || false; this._timeout = args.opts.timeout; - this._objectPrintDepth = args.opts.objectPrintDepth || 5; this._plan = undefined; this._cb = args.cb; this._progeny = []; 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) { diff --git a/readme.markdown b/readme.markdown index feebabc4..c27649ae 100644 --- a/readme.markdown +++ b/readme.markdown @@ -148,8 +148,9 @@ Available `opts` options are: - opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. - opts.objectPrintDepth = 5. Configure max depth of expected / actual object - printing. - + printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the + desired default depth for all tests; locally-set values will take precedence. + If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. From 4919e409e8a7c9d78a3abf0cea33a3549bb24fbc Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 15 Jan 2018 12:16:38 -0800 Subject: [PATCH 331/373] [Tests] on `node` `v9`; use `nvm install-latest-npm` --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ac7d396..b5d69d31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: node_js sudo: false node_js: + - "9" - "8" - "7" - "6" @@ -11,13 +12,13 @@ node_js: - "0.10" - "0.8" before_install: - - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - - 'if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi' + - 'nvm install-latest-npm' install: - - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' + - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' matrix: fast_finish: true allow_failures: + - node_js: "9" - node_js: "7" - node_js: "5" - node_js: "iojs" From 686784059075888fb6190fe790b2f873ef6b17fb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 18 Feb 2018 22:49:07 -0800 Subject: [PATCH 332/373] [Deps] update `object-inspect`, `resolve` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ff7ecf19..66c4391c 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", - "object-inspect": "~1.3.0", - "resolve": "~1.4.0", + "object-inspect": "~1.5.0", + "resolve": "~1.5.0", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" From ea6d91e9ec4a751a885d68664bb948a285562d5d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 18 Feb 2018 22:51:16 -0800 Subject: [PATCH 333/373] v4.9.0 - [New] use `process.env.NODE_TAPE_OBJECT_PRINT_DEPTH` for the default object print depth (#420) - [New] Add "onFailure" listener to test harness (#408) - [Fix] fix stack where actual is falsy (#400) - [Fix] normalize path separators in stacks (#402) - [Fix] fix line numbers in stack traces from inside anon functions (#387) - [Fix] Fix dirname in stack traces (#388) - [Robustness] Use local reference for clearTimeout global (#385) - [Deps] update `function-bind` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 66c4391c..980c0640 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.8.0", + "version": "4.9.0", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 24e0a8d079ce9f68daf2ec0c00010facc383cca5 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Mon, 12 Mar 2018 14:54:20 -0400 Subject: [PATCH 334/373] Fix spelling of "parameterize" --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index c27649ae..f16a2ef4 100644 --- a/readme.markdown +++ b/readme.markdown @@ -72,7 +72,7 @@ Additionally, it is possible to make `tape` load one or more modules before runn $ tape -r babel-register tests/**/*.js ``` -Depending on the module you're loading, you may be able to paramaterize it using environment variables or auxiliary files. Babel, for instance, will load options from [`.babelrc`](http://babeljs.io/docs/usage/babelrc/) at runtime. +Depending on the module you're loading, you may be able to parameterize it using environment variables or auxiliary files. Babel, for instance, will load options from [`.babelrc`](http://babeljs.io/docs/usage/babelrc/) at runtime. The `-r` flag behaves exactly like node's `require`, and uses the same module resolution algorithm. This means that if you need to load local modules, you have to prepend their path with `./` or `../` accordingly. From 9d501ff25b20f9318cda741c88cf50d469175da5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 14 Mar 2018 21:52:56 -0700 Subject: [PATCH 335/373] [Dev Deps] use ~ for dev deps; update to latest nonbreaking --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 980c0640..d0919861 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,11 @@ "through": "~2.3.8" }, "devDependencies": { - "concat-stream": "~1.6.0", - "falafel": "~2.1.0", - "js-yaml": "~3.10.0", - "tap": "~8.0.1", - "tap-parser": "~3.0.4" + "concat-stream": "^1.6.1", + "falafel": "^2.1.0", + "js-yaml": "^3.11.0", + "tap": "^8.0.1", + "tap-parser": "^3.0.5" }, "scripts": { "test": "tap test/*.js" From 6cbc53ee1599cf54489dc66291a126d764ea68cf Mon Sep 17 00:00:00 2001 From: Andrew McNutt Date: Tue, 27 Mar 2018 22:19:19 -0500 Subject: [PATCH 336/373] Add tap-react-browser --- readme.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/readme.markdown b/readme.markdown index f16a2ef4..5446235c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -15,10 +15,10 @@ var test = require('tape'); test('timing test', function (t) { t.plan(2); - + t.equal(typeof Date.now, 'function'); var start = Date.now(); - + setTimeout(function () { t.equal(Date.now() - start, 100); }, 100); @@ -114,6 +114,7 @@ that will output something pretty if you pipe TAP into them: - https://github.com/zoubin/tap-summary - https://github.com/Hypercubed/tap-markdown - https://github.com/gabrielcsapo/tap-html + - https://github.com/mcnuttandrew/tap-react-browser To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! @@ -191,7 +192,7 @@ Generate a passing assertion with a message `msg`. Automatically timeout the test after X ms. ## t.skip(msg) - + Generate an assertion that will be skipped over. ## t.ok(value, msg) From ec4a71d7c94a3692e5b42aa51d4a553d39fa8796 Mon Sep 17 00:00:00 2001 From: Marques Lee Date: Fri, 4 May 2018 10:39:57 -0700 Subject: [PATCH 337/373] [fix] Fix bug in functionName regex during stack parsing Previously, this line was splitting on the letter 's'; more likely, it was meant to split on spaces. --- lib/test.js | 2 +- test/stackTrace.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index ad1cbfb2..ab380310 100644 --- a/lib/test.js +++ b/lib/test.js @@ -282,7 +282,7 @@ Test.prototype._assert = function assert (ok, opts) { // Function call description may not (just) be a function name. // Try to extract function name by looking at first "word" only. - res.functionName = callDescription.split(/s+/)[0] + res.functionName = callDescription.split(/\s+/)[0] res.file = filePath; res.line = Number(m[3]); if (m[4]) res.column = Number(m[4]); diff --git a/test/stackTrace.js b/test/stackTrace.js index 14241ff6..1cab4ace 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -68,6 +68,42 @@ tap.test('preserves stack trace with newlines', function (tt) { }); }); +tap.test('parses function name from original stack', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('Test.testFunctionNameParsing', res.functionName) + }); + }; + + test('t.equal stack trace', function testFunctionNameParsing(t) { + t.equal(true, false, 'true should be false'); + t.end(); + }); +}); + +tap.test('parses function name from original stack for anonymous function', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream(); + + test._results._watch = function (t) { + t.on('result', function (res) { + tt.equal('Test.', res.functionName) + }); + }; + + test('t.equal stack trace', function (t) { + t.equal(true, false, 'true should be false'); + t.end(); + }); +}); + tap.test('preserves stack trace for failed assertions', function (tt) { tt.plan(6); @@ -214,4 +250,4 @@ function getDiag (body) { function stripAt (body) { return body.replace(/^\s*at:\s+Test.*$\n/m, ''); -} \ No newline at end of file +} From 45788a520f922397726958a37ab51dcaa6eb1b35 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 May 2018 23:04:35 -0700 Subject: [PATCH 338/373] [Dev Deps] update `concat-stream` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0919861..f371363e 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "through": "~2.3.8" }, "devDependencies": { - "concat-stream": "^1.6.1", + "concat-stream": "^1.6.2", "falafel": "^2.1.0", "js-yaml": "^3.11.0", "tap": "^8.0.1", From c6f5313217bc0b553ccab9a70a195b26881b63d8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 7 May 2018 23:53:20 -0700 Subject: [PATCH 339/373] [Tests] add eclint and eslint, to enforce a consistent style --- .editorconfig | 33 ++++ .eslintrc | 6 + .travis.yml | 16 +- bin/tape | 9 +- example/array.js | 8 +- example/fail.js | 8 +- example/nested.js | 12 +- example/nested_fail.js | 12 +- example/not_enough.js | 8 +- example/throw.js | 2 +- example/timing.js | 4 +- example/too_many.js | 8 +- index.js | 32 ++-- lib/default_stream.js | 4 +- lib/results.js | 24 +-- lib/test.js | 157 +++++++++-------- package.json | 134 +++++++------- readme.markdown | 47 +++-- test/add-subtest-async.js | 14 +- test/anonymous-fn.js | 6 +- test/anonymous-fn/test-wrapper.js | 14 +- test/array.js | 14 +- test/bound.js | 12 +- test/comment.js | 104 +++++------ test/common.js | 48 +++--- test/deep-equal-failure.js | 36 ++-- test/default-messages.js | 2 +- test/double_end.js | 10 +- test/end-as-callback.js | 30 ++-- test/exit/fail.js | 8 +- test/exit/ok.js | 8 +- test/exit/too_few.js | 8 +- test/exposed-harness.js | 7 +- test/fail.js | 14 +- test/has spaces.js | 6 +- test/messages/defaults.js | 16 +- test/nested-async-plan-noend.js | 54 +++--- test/nested-sync-noplan-noend.js | 10 +- test/nested.js | 18 +- test/only-twice.js | 25 ++- test/require.js | 16 +- test/require/a.js | 6 +- test/require/b.js | 6 +- test/require/test-a.js | 8 +- test/require/test-b.js | 8 +- test/skip.js | 2 +- test/stackTrace.js | 12 +- test/subtest_and_async.js | 30 ++-- test/throws.js | 278 +++++++++++++++--------------- test/timeoutAfter.js | 6 +- test/too_many.js | 14 +- test/undef.js | 4 +- 52 files changed, 720 insertions(+), 658 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..227b4a34 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 140 +block_comment_start = /* +block_comment = * +block_comment_end = */ + +[*.md] +indent_style = space +indent_size = 4 + +[readme.markdown] +indent_size = off +max_line_length = off + +[*.json] +max_line_length = off + +[*.yml] +max_line_length = off + +[Makefile] +max_line_length = off + +[.travis.yml] +indent_size = 2 diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..e93835c3 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,6 @@ +{ + "root": true, + "rules": { + "indent": ["error", 4], + }, +} diff --git a/.travis.yml b/.travis.yml index b5d69d31..1a8c8e67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js -sudo: false +os: + - linux node_js: + - "10" - "9" - "8" - "7" @@ -12,11 +14,23 @@ node_js: - "0.10" - "0.8" before_install: + - 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac' - 'nvm install-latest-npm' install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' +script: + - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' + - 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi' + - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi' + - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi' +sudo: false +env: + - TEST=true matrix: fast_finish: true + include: + - node_js: "lts/*" + env: PRETEST=true allow_failures: - node_js: "9" - node_js: "7" diff --git a/bin/tape b/bin/tape index d0b3bec5..c479c03b 100755 --- a/bin/tape +++ b/bin/tape @@ -19,9 +19,10 @@ if (typeof opts.require === 'string') { opts.require.forEach(function(module) { if (module) { - /* This check ensures we ignore `-r ""`, trailing `-r`, or - * other silly things the user might (inadvertently) be doing. */ - require(resolveModule(module, { basedir: cwd })); + /* This check ensures we ignore `-r ""`, trailing `-r`, or + * other silly things the user might (inadvertently) be doing. + */ + require(resolveModule(module, { basedir: cwd })); } }); @@ -31,7 +32,7 @@ opts._.forEach(function (arg) { var files = glob.sync(arg); if (!Array.isArray(files)) { - throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.'); + throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.'); } files.forEach(function (file) { diff --git a/example/array.js b/example/array.js index d36857d4..bec161f4 100644 --- a/example/array.js +++ b/example/array.js @@ -3,26 +3,26 @@ var test = require('../'); 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); diff --git a/example/fail.js b/example/fail.js index a7bf4444..a0db0b11 100644 --- a/example/fail.js +++ b/example/fail.js @@ -3,26 +3,26 @@ var test = require('../'); 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); diff --git a/example/nested.js b/example/nested.js index 0e233d3f..2a36f25e 100644 --- a/example/nested.js +++ b/example/nested.js @@ -3,35 +3,35 @@ 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, '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); diff --git a/example/nested_fail.js b/example/nested_fail.js index 3ab5cb3a..ba168c7e 100644 --- a/example/nested_fail.js +++ b/example/nested_fail.js @@ -3,35 +3,35 @@ 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); diff --git a/example/not_enough.js b/example/not_enough.js index 13b682be..fffc714f 100644 --- a/example/not_enough.js +++ b/example/not_enough.js @@ -3,26 +3,26 @@ var test = require('../'); test('array', function (t) { t.plan(8); - + 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); diff --git a/example/throw.js b/example/throw.js index 9a69ec0f..5fa8b94c 100644 --- a/example/throw.js +++ b/example/throw.js @@ -3,7 +3,7 @@ var test = require('../'); test('throw', function (t) { t.plan(2); - + setTimeout(function () { throw new Error('doom'); }, 100); diff --git a/example/timing.js b/example/timing.js index 0268dc78..614c1441 100644 --- a/example/timing.js +++ b/example/timing.js @@ -2,10 +2,10 @@ var test = require('../'); test('timing test', function (t) { t.plan(2); - + t.equal(typeof Date.now, 'function'); var start = new Date; - + setTimeout(function () { t.equal(new Date - start, 100); }, 100); diff --git a/example/too_many.js b/example/too_many.js index ee285fba..cdcb5ee9 100644 --- a/example/too_many.js +++ b/example/too_many.js @@ -3,26 +3,26 @@ var test = require('../'); test('array', function (t) { t.plan(3); - + 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); diff --git a/index.js b/index.js index 64d2d0c9..48528eb9 100644 --- a/index.js +++ b/index.js @@ -21,11 +21,11 @@ exports = module.exports = (function () { var lazyLoad = function () { return getHarness().apply(this, arguments); }; - + lazyLoad.only = function () { return getHarness().only.apply(this, arguments); }; - + lazyLoad.createStream = function (opts) { if (!opts) opts = {}; if (!harness) { @@ -35,11 +35,11 @@ exports = module.exports = (function () { } return harness.createStream(opts); }; - + lazyLoad.onFinish = function () { return getHarness().onFinish.apply(this, arguments); }; - + lazyLoad.onFailure = function() { return getHarness().onFailure.apply(this, arguments); }; @@ -61,16 +61,16 @@ function createExitHarness (conf) { var harness = createHarness({ autoclose: defined(conf.autoclose, false) }); - + var stream = harness.createStream({ objectMode: conf.objectMode }); var es = stream.pipe(conf.stream || createDefaultStream()); if (canEmitExit) { es.on('error', function (err) { harness._exitCode = 1 }); } - + var ended = false; stream.on('end', function () { ended = true }); - + if (conf.exit === false) return harness; if (!canEmitExit || !canExit) return harness; @@ -93,7 +93,7 @@ function createExitHarness (conf) { harness.close(); process.exit(code || harness._exitCode); }); - + return harness; } @@ -110,11 +110,11 @@ function createHarness (conf_) { if (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_); @@ -123,14 +123,14 @@ function createHarness (conf_) { if (!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); }; @@ -142,7 +142,7 @@ function createHarness (conf_) { 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'); @@ -152,8 +152,8 @@ function createHarness (conf_) { 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 12051773..8e9f4c76 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -5,7 +5,7 @@ module.exports = function () { 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' @@ -16,7 +16,7 @@ module.exports = function () { else line += c; } } - + function flush () { if (fs.writeSync && /^win/.test(process.platform)) { try { fs.writeSync(1, line + '\n'); } diff --git a/lib/results.js b/lib/results.js index 305ae6bc..56fdc4ba 100644 --- a/lib/results.js +++ b/lib/results.js @@ -64,7 +64,7 @@ Results.prototype.createStream = function (opts) { output.queue('TAP version 13\n'); self._stream.pipe(output); } - + nextTick(function next() { var t; while (t = getNextTest(self)) { @@ -73,7 +73,7 @@ Results.prototype.createStream = function (opts) { } self.emit('done'); }); - + return output; }; @@ -94,7 +94,7 @@ Results.prototype._watch = function (t) { t.once('prerun', function () { write('# ' + t.name + '\n'); }); - + t.on('result', function (res) { if (typeof res === 'string') { write('# ' + res + '\n'); @@ -109,7 +109,7 @@ Results.prototype._watch = function (t) { self.emit('fail'); } }); - + t.on('test', function (st) { self._watch(st) }); }; @@ -118,7 +118,7 @@ Results.prototype.close = function () { 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 + '\n'); @@ -132,22 +132,22 @@ function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; - + if (res.skip) output += ' # SKIP'; else if (res.todo) output += ' # 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'; @@ -170,7 +170,7 @@ function encodeResult (res, count) { output += inner + ' ' + lines[i] + '\n'; } } - + output += outer + '...\n'; return output; } @@ -179,7 +179,7 @@ function getNextTest (results) { if (!results._only) { return results.tests.shift(); } - + do { var t = results.tests.shift(); if (!t) continue; diff --git a/lib/test.js b/lib/test.js index ab380310..d31c2558 100644 --- a/lib/test.js +++ b/lib/test.js @@ -14,8 +14,7 @@ module.exports = Test; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate - : process.nextTick -; + : process.nextTick; var safeSetTimeout = setTimeout; var safeClearTimeout = clearTimeout; @@ -106,13 +105,13 @@ Test.prototype.test = function (name, opts, cb) { 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(); @@ -144,12 +143,12 @@ Test.prototype.timeoutAfter = function(ms) { }); } -Test.prototype.end = function (err) { +Test.prototype.end = function (err) { var self = this; if (arguments.length >= 1 && !!err) { this.ifError(err); } - + if (this.calledEnd) { this.fail('.end() called twice'); } @@ -165,7 +164,7 @@ Test.prototype._end = function (err) { t.run(); return; } - + if (!this.ended) this.emit('end'); var pendingAsserts = this._pendingAsserts(); if (!this._planError && this._plan !== undefined && pendingAsserts) { @@ -204,7 +203,7 @@ Test.prototype._pendingAsserts = function () { Test.prototype._assert = function assert (ok, opts) { var self = this; var extra = opts.extra || {}; - + var res = { id : self.assertCount ++, ok : Boolean(ok), @@ -220,11 +219,11 @@ Test.prototype._assert = function assert (ok, opts) { res.expected = defined(extra.expected, opts.expected); } this._ok = Boolean(this._ok && ok); - + if (!ok) { res.error = defined(extra.error, opts.error, new Error(res.name)); } - + if (!ok) { var e = new Error('exception'); var err = (e.stack || '').split('\n'); @@ -235,7 +234,7 @@ Test.prototype._assert = function assert (ok, opts) { Stack trace lines may resemble one of the following. We need to should correctly extract a function name (if any) and path / line no. for each line. - + at myFunction (/path/to/file.js:123:45) at myFunction (/path/to/file.other-ext:123:45) at myFunction (/path to/file.js:123:45) @@ -249,7 +248,7 @@ Test.prototype._assert = function assert (ok, opts) { (plus anything preceding it). /^(?:[^\s]*\s*\bat\s+)/ - + Second captures function call description (optional). This is not necessarily a valid JS function name, but just what the stack trace is using to represent a function call. It may look @@ -261,21 +260,21 @@ Test.prototype._assert = function assert (ok, opts) { /(?:(.*)\s+\()?/ - Last part captures file path plus line no (and optional + Last part captures file path plus line no (and optional column no). /((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ */ var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ var m = re.exec(err[i]); - + if (!m) { continue; } var callDescription = m[1] || ''; var filePath = m[2]; - + if (filePath.slice(0, dir.length) === dir) { continue; } @@ -286,14 +285,14 @@ Test.prototype._assert = function assert (ok, opts) { 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) { @@ -304,7 +303,7 @@ Test.prototype._assert = function assert (ok, opts) { }); } } - + if (!self._planError && pendingAsserts < 0) { self._planError = true; self.fail('plan != count', { @@ -339,10 +338,7 @@ Test.prototype.skip = function (msg, extra) { }); }; -Test.prototype.ok -= Test.prototype['true'] -= Test.prototype.assert -= function (value, msg, extra) { +function assert(value, msg, extra) { this._assert(value, { message : defined(msg, 'should be truthy'), operator : 'ok', @@ -350,12 +346,13 @@ Test.prototype.ok actual : value, extra : extra }); -}; +} +Test.prototype.ok += Test.prototype['true'] += Test.prototype.assert += assert; -Test.prototype.notOk -= Test.prototype['false'] -= Test.prototype.notok -= function (value, msg, extra) { +function notOK(value, msg, extra) { this._assert(!value, { message : defined(msg, 'should be falsy'), operator : 'notOk', @@ -363,37 +360,52 @@ Test.prototype.notOk actual : value, extra : extra }); -}; +} +Test.prototype.notOk += Test.prototype['false'] += Test.prototype.notok += notOK; -Test.prototype.error -= Test.prototype.ifError -= Test.prototype.ifErr -= Test.prototype.iferror -= function (err, msg, extra) { +function error(err, msg, extra) { this._assert(!err, { message : defined(msg, String(err)), operator : 'error', actual : err, extra : extra }); -}; +} +Test.prototype.error += Test.prototype.ifError += Test.prototype.ifErr += Test.prototype.iferror += error; +function equal(a, b, msg, extra) { + this._assert(a === b, { + message : defined(msg, 'should be equal'), + operator : 'equal', + actual : a, + expected : b, + extra : extra + }); +} Test.prototype.equal = Test.prototype.equals = Test.prototype.isEqual = Test.prototype.is = Test.prototype.strictEqual = Test.prototype.strictEquals -= function (a, b, msg, extra) { - this._assert(a === b, { - message : defined(msg, 'should be equal'), - operator : 'equal', += equal; + +function notEqual(a, b, msg, extra) { + this._assert(a !== b, { + message : defined(msg, 'should not be equal'), + operator : 'notEqual', actual : a, - expected : b, + notExpected : b, extra : extra }); -}; - +} Test.prototype.notEqual = Test.prototype.notEquals = Test.prototype.notStrictEqual @@ -403,43 +415,46 @@ Test.prototype.notEqual = Test.prototype.not = Test.prototype.doesNotEqual = Test.prototype.isInequal -= function (a, b, msg, extra) { - this._assert(a !== b, { - message : defined(msg, 'should not be equal'), - operator : 'notEqual', += notEqual; + +function tapeDeepEqual(a, b, msg, extra) { + this._assert(deepEqual(a, b, { strict: true }), { + message : defined(msg, 'should be equivalent'), + operator : 'deepEqual', actual : a, - notExpected : b, + expected : b, extra : extra }); -}; - +} Test.prototype.deepEqual = Test.prototype.deepEquals = Test.prototype.isEquivalent = Test.prototype.same -= function (a, b, msg, extra) { - this._assert(deepEqual(a, b, { strict: true }), { += tapeDeepEqual; + +function deepLooseEqual(a, b, msg, extra) { + this._assert(deepEqual(a, b), { message : defined(msg, 'should be equivalent'), - operator : 'deepEqual', + operator : 'deepLooseEqual', actual : a, expected : b, extra : extra }); -}; - +} Test.prototype.deepLooseEqual = Test.prototype.looseEqual = Test.prototype.looseEquals -= function (a, b, msg, extra) { - this._assert(deepEqual(a, b), { - message : defined(msg, 'should be equivalent'), - operator : 'deepLooseEqual', += deepLooseEqual; + +function notDeepEqual(a, b, msg, extra) { + this._assert(!deepEqual(a, b, { strict: true }), { + message : defined(msg, 'should not be equivalent'), + operator : 'notDeepEqual', actual : a, - expected : b, + notExpected : b, extra : extra }); -}; - +} Test.prototype.notDeepEqual = Test.prototype.notEquivalent = Test.prototype.notDeeply @@ -448,20 +463,9 @@ Test.prototype.notDeepEqual = Test.prototype.isNotDeeply = Test.prototype.isNotEquivalent = Test.prototype.isInequivalent -= function (a, b, msg, extra) { - this._assert(!deepEqual(a, b, { strict: true }), { - message : defined(msg, 'should not be equivalent'), - operator : 'notDeepEqual', - actual : a, - notExpected : b, - extra : extra - }); -}; += notDeepEqual; -Test.prototype.notDeepLooseEqual -= Test.prototype.notLooseEqual -= Test.prototype.notLooseEquals -= function (a, b, msg, extra) { +function notDeepLooseEqual(a, b, msg, extra) { this._assert(!deepEqual(a, b), { message : defined(msg, 'should be equivalent'), operator : 'notDeepLooseEqual', @@ -469,7 +473,11 @@ Test.prototype.notDeepLooseEqual expected : b, extra : extra }); -}; +} +Test.prototype.notDeepLooseEqual += Test.prototype.notLooseEqual += Test.prototype.notLooseEquals += notDeepLooseEqual; Test.prototype['throws'] = function (fn, expected, msg, extra) { if (typeof expected === 'string') { @@ -541,4 +549,3 @@ Test.skip = function (name_, _opts, _cb) { }; // vim: set softtabstop=4 shiftwidth=4: - diff --git a/package.json b/package.json index f371363e..1247ec8f 100644 --- a/package.json +++ b/package.json @@ -1,66 +1,72 @@ { - "name": "tape", - "version": "4.9.0", - "description": "tap-producing test harness for node and browsers", - "main": "index.js", - "bin": "./bin/tape", - "directories": { - "example": "example", - "test": "test" - }, - "dependencies": { - "deep-equal": "~1.0.1", - "defined": "~1.0.0", - "for-each": "~0.3.2", - "function-bind": "~1.1.1", - "glob": "~7.1.2", - "has": "~1.0.1", - "inherits": "~2.0.3", - "minimist": "~1.2.0", - "object-inspect": "~1.5.0", - "resolve": "~1.5.0", - "resumer": "~0.0.0", - "string.prototype.trim": "~1.1.2", - "through": "~2.3.8" - }, - "devDependencies": { - "concat-stream": "^1.6.2", - "falafel": "^2.1.0", - "js-yaml": "^3.11.0", - "tap": "^8.0.1", - "tap-parser": "^3.0.5" - }, - "scripts": { - "test": "tap test/*.js" - }, - "testling": { - "files": "test/browser/*.js", - "browsers": [ - "ie/6..latest", - "chrome/20..latest", - "firefox/10..latest", - "safari/latest", - "opera/11.0..latest", - "iphone/6", - "ipad/6" - ] - }, - "repository": { - "type": "git", - "url": "git://github.com/substack/tape.git" - }, - "homepage": "https://github.com/substack/tape", - "keywords": [ - "tap", - "test", - "harness", - "assert", - "browser" - ], - "author": { - "name": "James Halliday", - "email": "mail@substack.net", - "url": "http://substack.net" - }, - "license": "MIT" + "name": "tape", + "version": "4.9.0", + "description": "tap-producing test harness for node and browsers", + "main": "index.js", + "bin": "./bin/tape", + "directories": { + "example": "example", + "test": "test" + }, + "dependencies": { + "deep-equal": "~1.0.1", + "defined": "~1.0.0", + "for-each": "~0.3.2", + "function-bind": "~1.1.1", + "glob": "~7.1.2", + "has": "~1.0.1", + "inherits": "~2.0.3", + "minimist": "~1.2.0", + "object-inspect": "~1.5.0", + "resolve": "~1.5.0", + "resumer": "~0.0.0", + "string.prototype.trim": "~1.1.2", + "through": "~2.3.8" + }, + "devDependencies": { + "concat-stream": "^1.6.2", + "eclint": "^2.7.0", + "eslint": "^4.19.1", + "falafel": "^2.1.0", + "js-yaml": "^3.11.0", + "tap": "^8.0.1", + "tap-parser": "^3.0.5" + }, + "scripts": { + "prelint": "eclint check", + "lint": "eslint .", + "pretest": "npm run lint", + "test": "npm run tests-only", + "tests-only": "tap test/*.js" + }, + "testling": { + "files": "test/browser/*.js", + "browsers": [ + "ie/6..latest", + "chrome/20..latest", + "firefox/10..latest", + "safari/latest", + "opera/11.0..latest", + "iphone/6", + "ipad/6" + ] + }, + "repository": { + "type": "git", + "url": "git://github.com/substack/tape.git" + }, + "homepage": "https://github.com/substack/tape", + "keywords": [ + "tap", + "test", + "harness", + "assert", + "browser" + ], + "author": { + "name": "James Halliday", + "email": "mail@substack.net", + "url": "http://substack.net" + }, + "license": "MIT" } diff --git a/readme.markdown b/readme.markdown index 5446235c..7c53801a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -95,26 +95,26 @@ The default TAP output is good for machines and humans that are robots. If you want a more colorful / pretty output there are lots of modules on npm that will output something pretty if you pipe TAP into them: - - https://github.com/scottcorgan/tap-spec - - https://github.com/scottcorgan/tap-dot - - https://github.com/substack/faucet - - https://github.com/juliangruber/tap-bail - - https://github.com/kirbysayshi/tap-browser-color - - https://github.com/gummesson/tap-json - - https://github.com/derhuerst/tap-min - - https://github.com/calvinmetcalf/tap-nyan - - https://www.npmjs.org/package/tap-pessimist - - https://github.com/toolness/tap-prettify - - https://github.com/shuhei/colortape - - https://github.com/aghassemi/tap-xunit - - https://github.com/namuol/tap-difflet - - https://github.com/gritzko/tape-dom - - https://github.com/axross/tap-diff - - https://github.com/axross/tap-notify - - https://github.com/zoubin/tap-summary - - https://github.com/Hypercubed/tap-markdown - - https://github.com/gabrielcsapo/tap-html - - https://github.com/mcnuttandrew/tap-react-browser + - https://github.com/scottcorgan/tap-spec + - https://github.com/scottcorgan/tap-dot + - https://github.com/substack/faucet + - https://github.com/juliangruber/tap-bail + - https://github.com/kirbysayshi/tap-browser-color + - https://github.com/gummesson/tap-json + - https://github.com/derhuerst/tap-min + - https://github.com/calvinmetcalf/tap-nyan + - https://www.npmjs.org/package/tap-pessimist + - https://github.com/toolness/tap-prettify + - https://github.com/shuhei/colortape + - https://github.com/aghassemi/tap-xunit + - https://github.com/namuol/tap-difflet + - https://github.com/gritzko/tape-dom + - https://github.com/axross/tap-diff + - https://github.com/axross/tap-notify + - https://github.com/zoubin/tap-summary + - https://github.com/Hypercubed/tap-markdown + - https://github.com/gabrielcsapo/tap-html + - https://github.com/mcnuttandrew/tap-react-browser To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! @@ -146,11 +146,8 @@ finished. Tests execute serially. Available `opts` options are: - opts.skip = true/false. See test.skip. -- opts.timeout = 500. Set a timeout for the test, after which it will fail. - See test.timeoutAfter. -- opts.objectPrintDepth = 5. Configure max depth of expected / actual object - printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the - desired default depth for all tests; locally-set values will take precedence. +- opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. +- opts.objectPrintDepth = 5. Configure max depth of expected / actual object printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the desired default depth for all tests; locally-set values will take precedence. If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js index 74b4d8a0..ddc39f76 100644 --- a/test/add-subtest-async.js +++ b/test/add-subtest-async.js @@ -1,11 +1,11 @@ var test = require('../') test('parent', function (t) { - t.pass('parent'); - setTimeout(function () { - t.test('child', function (t) { - t.pass('child'); - t.end(); - }); - }, 100) + t.pass('parent'); + setTimeout(function () { + t.test('child', function (t) { + t.pass('child'); + t.end(); + }); + }, 100) }) diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index 2856ea82..e05b967c 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -7,7 +7,7 @@ var testWrapper = require('./anonymous-fn/test-wrapper'); tap.test('inside anonymous functions', function (tt) { tt.plan(1); - + var test = tape.createHarness(); var tc = function (rows) { var body = stripFullStack(rows.toString('utf8')); @@ -39,9 +39,9 @@ tap.test('inside anonymous functions', function (tt) { '# fail 1' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + 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 acf66e30..9702c9f1 100644 --- a/test/anonymous-fn/test-wrapper.js +++ b/test/anonymous-fn/test-wrapper.js @@ -1,16 +1,16 @@ // 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 d206be58..dc4a4a40 100644 --- a/test/array.js +++ b/test/array.js @@ -5,9 +5,9 @@ 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', @@ -25,29 +25,29 @@ tap.test('array test', function (tt) { '# 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); diff --git a/test/bound.js b/test/bound.js index d3981954..58f26920 100644 --- a/test/bound.js +++ b/test/bound.js @@ -1,10 +1,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/comment.js b/test/comment.js index ab00690c..b3f9bcc3 100644 --- a/test/comment.js +++ b/test/comment.js @@ -9,15 +9,15 @@ tap.test('no comment', function (assert) { var verify = function (output) { assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# no comment', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' + 'TAP version 13', + '# no comment', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' ].join('\n')); }; @@ -69,19 +69,19 @@ tap.test('whitespace', function (assert) { var verify = function (output) { assert.equal(output.toString('utf8'), [ - 'TAP version 13', - '# whitespace', - '# ', - '# a', - '# a', - '# a', - '', - '1..0', - '# tests 0', - '# pass 0', - '', - '# ok', - '' + 'TAP version 13', + '# whitespace', + '# ', + '# a', + '# a', + '# a', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' ].join('\n')); }; @@ -102,23 +102,23 @@ tap.test('non-string types', function (assert) { 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', - '' + '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')); }; @@ -143,19 +143,19 @@ tap.test('multiline string', function (assert) { 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', - '' + 'TAP version 13', + '# multiline strings', + '# a', + '# b', + '# c', + '# d', + '', + '1..0', + '# tests 0', + '# pass 0', + '', + '# ok', + '' ].join('\n')); }; diff --git a/test/common.js b/test/common.js index 9e4a0391..f156693a 100644 --- a/test/common.js +++ b/test/common.js @@ -32,32 +32,32 @@ module.exports.getDiag = function (body) { // strip out all stack frames that aren't directly under our test directory, // and replace them with placeholders. module.exports.stripFullStack = function (output) { - var stripped = ' [... stack stripped ...]'; - var withDuplicates = output.split('\n').map(function (line) { - var m = line.match(/[ ]{8}at .*\((.*)\)/); + var stripped = ' [... stack stripped ...]'; + var withDuplicates = output.split('\n').map(function (line) { + var m = line.match(/[ ]{8}at .*\((.*)\)/); - 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 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; + } - if (m) { - if (m[1].slice(0, __dirname.length) === __dirname) { - return stripChangingData(line); - } - return stripped; - } - return stripChangingData(line); - }) + if (m) { + if (m[1].slice(0, __dirname.length) === __dirname) { + return stripChangingData(line); + } + return stripped; + } + return stripChangingData(line); + }) - var deduped = withDuplicates.filter(function (line, ix) { - var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; - return !hasPrior; - }); + var deduped = withDuplicates.filter(function (line, ix) { + var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped; + return !hasPrior; + }); - return deduped.join('\n'); + return deduped.join('\n'); } diff --git a/test/deep-equal-failure.js b/test/deep-equal-failure.js index 4c0d4eed..48d0687c 100644 --- a/test/deep-equal-failure.js +++ b/test/deep-equal-failure.js @@ -41,9 +41,9 @@ tap.test('deep equal failure', function (assert) { ); assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ b: 2 }', - actual: '{ a: 1 }' + operator: 'equal', + expected: '{ b: 2 }', + actual: '{ a: 1 }' }); })); @@ -55,9 +55,9 @@ tap.test('deep equal failure', function (assert) { id: 1, name: 'should be equal', diag: { - operator: 'equal', - expected: '{ b: 2 }', - actual: '{ a: 1 }' + operator: 'equal', + expected: '{ b: 2 }', + actual: '{ a: 1 }' } }); }); @@ -102,9 +102,9 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { ); assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' }); })); @@ -116,9 +116,9 @@ tap.test('deep equal failure, depth 6, with option', function (assert) { id: 1, name: 'should be equal', diag: { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' } }); }); @@ -163,9 +163,9 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { ); assert.deepEqual(getDiag(body), { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' }); })); @@ -177,9 +177,9 @@ tap.test('deep equal failure, depth 6, without option', function (assert) { id: 1, name: 'should be equal', diag: { - operator: 'equal', - expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', - actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + operator: 'equal', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' } }); }); diff --git a/test/default-messages.js b/test/default-messages.js index 46c055fd..dcfdbffc 100644 --- a/test/default-messages.js +++ b/test/default-messages.js @@ -7,7 +7,7 @@ tap.test('default messages', function (t) { t.plan(1); var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]); - + ps.stdout.pipe(concat(function (rows) { t.same(rows.toString('utf8'), [ diff --git a/test/double_end.js b/test/double_end.js index 5457cb27..a24f4507 100644 --- a/test/double_end.js +++ b/test/double_end.js @@ -26,13 +26,13 @@ test(function (t) { var stackExpected; var atExpected; try { - to._onTimeout(); + to._onTimeout(); } catch (e) { - stackExpected = stripFullStack(e.stack).split('\n')[1]; - stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js'); - stackExpected = stackExpected.trim(); - atExpected = stackExpected.replace(/^at\s+/, 'at: '); + stackExpected = stripFullStack(e.stack).split('\n')[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')); diff --git a/test/end-as-callback.js b/test/end-as-callback.js index 98609f5d..f8791c0a 100644 --- a/test/end-as-callback.js +++ b/test/end-as-callback.js @@ -5,23 +5,23 @@ var concat = require('concat-stream'); tap.test("tape assert.end as callback", function (tt) { 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 equal', - '# do a task and write fail', - 'ok 3 null', - 'ok 4 should be equal', - 'not ok 5 Error: fail', - getStackTrace(rows), // tap error stack - '', - '1..5', - '# tests 5', - '# pass 4', - '# fail 1' + 'TAP version 13', + '# do a task and write', + 'ok 1 null', + 'ok 2 should be equal', + '# do a task and write fail', + 'ok 3 null', + 'ok 4 should be equal', + 'not ok 5 Error: fail', + getStackTrace(rows), // tap error stack + '', + '1..5', + '# tests 5', + '# pass 4', + '# fail 1' ].join('\n') + '\n'); tt.end() })); diff --git a/test/exit/fail.js b/test/exit/fail.js index d7fd3ce7..07a65ca3 100644 --- a/test/exit/fail.js +++ b/test/exit/fail.js @@ -3,26 +3,26 @@ var falafel = require('falafel'); 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); diff --git a/test/exit/ok.js b/test/exit/ok.js index f1068e57..6d405c7c 100644 --- a/test/exit/ok.js +++ b/test/exit/ok.js @@ -4,26 +4,26 @@ var test = require('../../'); test('array', function (t) { t.comment('hi'); 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); diff --git a/test/exit/too_few.js b/test/exit/too_few.js index 8e60ce5b..68ba71db 100644 --- a/test/exit/too_few.js +++ b/test/exit/too_few.js @@ -3,26 +3,26 @@ var test = require('../../'); test('array', 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() + ')'); } }); - + 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); diff --git a/test/exposed-harness.js b/test/exposed-harness.js index b790340c..e1795eb0 100644 --- a/test/exposed-harness.js +++ b/test/exposed-harness.js @@ -3,11 +3,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 2c975bb8..133359ca 100644 --- a/test/fail.js +++ b/test/fail.js @@ -7,7 +7,7 @@ var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); var tc = function (rows) { tt.same(stripFullStack(rows.toString('utf8')), [ @@ -40,31 +40,31 @@ tap.test('array test', function (tt) { '' ].join('\n')); }; - + test.createStream().pipe(concat(tc)); - + 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); diff --git a/test/has spaces.js b/test/has spaces.js index ae18e71d..19a2b9e3 100644 --- a/test/has spaces.js +++ b/test/has spaces.js @@ -6,7 +6,7 @@ var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); var tc = function (rows) { tt.same(stripFullStack(rows.toString('utf8')), [ @@ -30,9 +30,9 @@ tap.test('array test', function (tt) { '' ].join('\n')); }; - + test.createStream().pipe(concat(tc)); - + test('fail', function (t) { t.fail('this should fail'); t.end(); diff --git a/test/messages/defaults.js b/test/messages/defaults.js index 8d842eb9..836a34aa 100644 --- a/test/messages/defaults.js +++ b/test/messages/defaults.js @@ -1,12 +1,12 @@ var test = require('../../'); test('default messages', function (t) { - t.plan(7); - t.ok(true); - t.notOk(false); - t.equal(true, true); - t.notEqual(true, false); - t.deepEqual(true, true); - t.deepLooseEqual(true, true); - t.notDeepLooseEqual(true, false); + t.plan(7); + t.ok(true); + t.notOk(false); + t.equal(true, true); + t.notEqual(true, false); + t.deepEqual(true, true); + 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 6f8cfdd0..69f43b9d 100644 --- a/test/nested-async-plan-noend.js +++ b/test/nested-async-plan-noend.js @@ -1,36 +1,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() { - 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); - }); + setTimeout(function() { + tt.test('async grandchild B', function(ttt) { + ttt.plan(1); + ttt.ok(true); + }); + }, 100); }); - }, 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 6039093d..42735a80 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -7,7 +7,7 @@ tap.test('nested sync test without plan or end', function (tt) { var test = tape.createHarness(); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(rows.toString('utf8'), [ 'TAP version 13', '# nested without plan or end', '# first', @@ -27,15 +27,15 @@ tap.test('nested sync test without plan or end', function (tt) { test('nested without plan or end', function(t) { t.test('first', function(q) { - setTimeout(function first() { + setTimeout(function first() { q.ok(true); - q.end() + q.end() }, 10); }); t.test('second', function(q) { - setTimeout(function second() { + setTimeout(function second() { q.ok(true); - q.end() + q.end() }, 10); }); }); diff --git a/test/nested.js b/test/nested.js index f444f95f..46822594 100644 --- a/test/nested.js +++ b/test/nested.js @@ -5,7 +5,7 @@ var concat = require('concat-stream'); tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); var tc = function (rows) { tt.same(rows.toString('utf8'), [ @@ -29,40 +29,40 @@ tap.test('array test', function (tt) { '# ok' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + 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); - + setTimeout(function () { q.ok(true); }, 100); }); - + 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); diff --git a/test/only-twice.js b/test/only-twice.js index ce6048ef..488e49ba 100644 --- a/test/only-twice.js +++ b/test/only-twice.js @@ -2,20 +2,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(); + assert.throws(function() { + test.only('second only', function(t) { + t.end(); + }); + }, { + name: 'Error', + message: 'there can only be one only test' }); - }, { - name: 'Error', - message: 'there can only be one only test' - }); - assert.end(); + assert.end(); }); - diff --git a/test/require.js b/test/require.js index 6b05a000..5e39e170 100644 --- a/test/require.js +++ b/test/require.js @@ -4,7 +4,7 @@ var concat = require('concat-stream'); tap.test('requiring a single module', function (t) { t.plan(2); - + var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', @@ -21,7 +21,7 @@ tap.test('requiring a single module', function (t) { '# ok' ].join('\n') + '\n\n'); }; - + var ps = tape('-r ./require/a require/test-a.js'); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { @@ -31,7 +31,7 @@ tap.test('requiring a single module', function (t) { tap.test('requiring multiple modules', function (t) { t.plan(2); - + var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', @@ -53,7 +53,7 @@ tap.test('requiring multiple modules', function (t) { '# 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) { @@ -62,8 +62,8 @@ tap.test('requiring multiple modules', function (t) { }); function tape(args) { - var proc = require('child_process') - var bin = __dirname + '/../bin/tape' + var proc = require('child_process') + var bin = __dirname + '/../bin/tape' - return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }) -} \ No newline at end of file + return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }) +} diff --git a/test/require/a.js b/test/require/a.js index b2dd811b..097eb883 100644 --- a/test/require/a.js +++ b/test/require/a.js @@ -1,8 +1,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 \ No newline at end of file +global.module_a = true diff --git a/test/require/b.js b/test/require/b.js index 2206c17c..2f10a0ec 100644 --- a/test/require/b.js +++ b/test/require/b.js @@ -1,8 +1,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 \ No newline at end of file +global.module_b = true diff --git a/test/require/test-a.js b/test/require/test-a.js index 822ef540..769e40cd 100644 --- a/test/require/test-a.js +++ b/test/require/test-a.js @@ -1,7 +1,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() -}) \ No newline at end of file + 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 8efcba1c..4eb3b681 100644 --- a/test/require/test-b.js +++ b/test/require/test-b.js @@ -1,7 +1,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() -}) \ No newline at end of file + 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 54c53f90..c3bf8d9e 100644 --- a/test/skip.js +++ b/test/skip.js @@ -30,7 +30,7 @@ tap.test('test SKIP comment', function (assert) { test('skip this', { skip: true }, function(t) { t.fail('this should not even run'); - ran++; + ran++; t.end(); }); diff --git a/test/stackTrace.js b/test/stackTrace.js index 1cab4ace..8da3b529 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -239,13 +239,13 @@ function getDiag (body) { var yamlEnd = body.indexOf(' ...\n'); var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { return line.slice(2); - }).join('\n'); + }).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; + // 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) { diff --git a/test/subtest_and_async.js b/test/subtest_and_async.js index 719dbf5b..9e49965d 100644 --- a/test/subtest_and_async.js +++ b/test/subtest_and_async.js @@ -1,23 +1,23 @@ 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 (t) { - t.pass('subtest 1 before async call'); - asyncFunction(function () { - t.pass('subtest 1 in async callback'); - t.end(); - }) - }); + t.test('subtest 1', function (t) { + t.pass('subtest 1 before async call'); + asyncFunction(function () { + t.pass('subtest 1 in async callback'); + t.end(); + }) + }); - t.test('subtest 2', function (t) { - t.pass('subtest 2 before async call'); - asyncFunction(function () { - t.pass('subtest 2 in async callback'); - t.end(); - }) - }); + t.test('subtest 2', function (t) { + t.pass('subtest 2 before async call'); + asyncFunction(function () { + t.pass('subtest 2 in async callback'); + t.end(); + }) + }); }); diff --git a/test/throws.js b/test/throws.js index 5b576eb1..9b2bba96 100644 --- a/test/throws.js +++ b/test/throws.js @@ -32,142 +32,142 @@ tap.test('failures', function (tt) { tt.equal( stripFullStack(body.toString('utf8')), 'TAP version 13\n' - + '# non functions\n' - + 'not ok 1 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(undefined) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 2 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(null) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 3 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(true) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 4 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(false) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 5 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage('abc') + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 6 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage(/a/g) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 7 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage([]) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + 'not ok 8 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' TypeError: ' + getNonFunctionMessage({}) + '\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '# function\n' - + 'not ok 9 should throw\n' - + ' ---\n' - + ' operator: throws\n' - + ' expected: undefined\n' - + ' actual: undefined\n' - + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' stack: |-\n' - + ' Error: should throw\n' - + ' [... stack stripped ...]\n' - + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' - + ' [... stack stripped ...]\n' - + ' ...\n' - + '# custom error messages\n' - + 'ok 10 "message" is enumerable\n' - + "ok 11 { custom: 'error', message: 'message' }\n" - + 'ok 12 getter is still the same\n' - + '# throws null\n' - + 'ok 13 throws null\n' - + '\n1..13\n' - + '# tests 13\n' - + '# pass 4\n' - + '# fail 9\n' + + '# non functions\n' + + 'not ok 1 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(undefined) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 2 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(null) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 3 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(true) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 4 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(false) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 5 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage('abc') + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 6 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage(/a/g) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 7 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage([]) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 8 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' TypeError: ' + getNonFunctionMessage({}) + '\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '# function\n' + + 'not ok 9 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: undefined\n' + + ' actual: undefined\n' + + ' at: Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: should throw\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/throws.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '# custom error messages\n' + + 'ok 10 "message" is enumerable\n' + + "ok 11 { custom: 'error', message: 'message' }\n" + + 'ok 12 getter is still the same\n' + + '# throws null\n' + + 'ok 13 throws null\n' + + '\n1..13\n' + + '# tests 13\n' + + '# pass 4\n' + + '# fail 9\n' ); })); @@ -196,8 +196,8 @@ tap.test('failures', function (tt) { }); test('throws null', function (t) { - t.plan(1); - t.throws(function () { throw null; }, 'throws null'); - t.end(); + t.plan(1); + t.throws(function () { throw null; }, 'throws null'); + t.end(); }); }); diff --git a/test/timeoutAfter.js b/test/timeoutAfter.js index 7b8bf647..80752d28 100644 --- a/test/timeoutAfter.js +++ b/test/timeoutAfter.js @@ -6,7 +6,7 @@ var stripFullStack = require('./common').stripFullStack; tap.test('timeoutAfter test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); var tc = function (rows) { tt.same(stripFullStack(rows.toString('utf8')), [ @@ -26,9 +26,9 @@ tap.test('timeoutAfter test', function (tt) { '# fail 1' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + test('timeoutAfter', function (t) { t.plan(1); t.timeoutAfter(1); diff --git a/test/too_many.js b/test/too_many.js index 3bd0ca56..5c7e4b38 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -7,7 +7,7 @@ var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness({ exit : false }); var tc = function (rows) { tt.same(stripFullStack(rows.toString('utf8')), [ @@ -40,31 +40,31 @@ tap.test('array test', function (tt) { '# fail 1' ].join('\n') + '\n'); }; - + test.createStream().pipe(concat(tc)); - + test('array', function (t) { t.plan(3); - + 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); diff --git a/test/undef.js b/test/undef.js index f809384b..52759ac7 100644 --- a/test/undef.js +++ b/test/undef.js @@ -6,7 +6,7 @@ var stripFullStack = require('./common').stripFullStack; tap.test('array test', function (tt) { tt.plan(1); - + var test = tape.createHarness(); test.createStream().pipe(concat(function (body) { tt.equal( @@ -34,7 +34,7 @@ tap.test('array test', function (tt) { + '# fail 1\n' ); })); - + test('undef', function (t) { t.plan(1); t.deepEqual({}, { beep: undefined }); From 8a2d29bc8adcd179ccef15a551f0df35fa3ab6c1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 5 Jun 2018 22:24:26 -0700 Subject: [PATCH 340/373] [Deps] update `has`, `for-each`, `resolve`, `object-inspect` --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1247ec8f..b3cd11c4 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,14 @@ "dependencies": { "deep-equal": "~1.0.1", "defined": "~1.0.0", - "for-each": "~0.3.2", + "for-each": "~0.3.3", "function-bind": "~1.1.1", "glob": "~7.1.2", - "has": "~1.0.1", + "has": "~1.0.3", "inherits": "~2.0.3", "minimist": "~1.2.0", - "object-inspect": "~1.5.0", - "resolve": "~1.5.0", + "object-inspect": "~1.6.0", + "resolve": "~1.7.1", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" From 73232c01ef4d794c6c502e4f5a349d8fb26e2eeb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 5 Jun 2018 22:24:40 -0700 Subject: [PATCH 341/373] [Dev Deps] update `js-yaml` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3cd11c4..bfb2683c 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "eclint": "^2.7.0", "eslint": "^4.19.1", "falafel": "^2.1.0", - "js-yaml": "^3.11.0", + "js-yaml": "^3.12.0", "tap": "^8.0.1", "tap-parser": "^3.0.5" }, From 050b318651f9a5858564e9818482851b35df1c47 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 7 Jun 2018 16:03:18 -0700 Subject: [PATCH 342/373] v4.9.1 - [fix] Fix bug in functionName regex during stack parsing (#437) - [docs] Fix spelling of "parameterize" (#430) - [docs] Add tap-react-browser (#433) - [deps] update `has`, `for-each`, `resolve`, `object-inspect` - [dev deps] use ^ for dev deps; update to latest nonbreaking; update `concat-stream`, `js-yaml` - [Tests] add eclint and eslint, to enforce a consistent style --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfb2683c..354730bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.9.0", + "version": "4.9.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 4337f5878dedadf430e0e4c8146f3c6a691f5cda Mon Sep 17 00:00:00 2001 From: Ash Belmokadem Date: Thu, 21 Jun 2018 10:40:05 +0200 Subject: [PATCH 343/373] Convert list of tap reporters to links --- readme.markdown | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/readme.markdown b/readme.markdown index 7c53801a..187c198f 100644 --- a/readme.markdown +++ b/readme.markdown @@ -95,26 +95,26 @@ The default TAP output is good for machines and humans that are robots. If you want a more colorful / pretty output there are lots of modules on npm that will output something pretty if you pipe TAP into them: - - https://github.com/scottcorgan/tap-spec - - https://github.com/scottcorgan/tap-dot - - https://github.com/substack/faucet - - https://github.com/juliangruber/tap-bail - - https://github.com/kirbysayshi/tap-browser-color - - https://github.com/gummesson/tap-json - - https://github.com/derhuerst/tap-min - - https://github.com/calvinmetcalf/tap-nyan - - https://www.npmjs.org/package/tap-pessimist - - https://github.com/toolness/tap-prettify - - https://github.com/shuhei/colortape - - https://github.com/aghassemi/tap-xunit - - https://github.com/namuol/tap-difflet - - https://github.com/gritzko/tape-dom - - https://github.com/axross/tap-diff - - https://github.com/axross/tap-notify - - https://github.com/zoubin/tap-summary - - https://github.com/Hypercubed/tap-markdown - - https://github.com/gabrielcsapo/tap-html - - https://github.com/mcnuttandrew/tap-react-browser +- [tap-spec](https://github.com/scottcorgan/tap-spec) +- [tap-dot](https://github.com/scottcorgan/tap-dot) +- [faucet](https://github.com/substack/faucet) +- [tap-bail](https://github.com/juliangruber/tap-bail) +- [tap-browser-color](https://github.com/kirbysayshi/tap-browser-color) +- [tap-json](https://github.com/gummesson/tap-json) +- [tap-min](https://github.com/derhuerst/tap-min) +- [tap-nyan](https://github.com/calvinmetcalf/tap-nyan) +- [package/tap-pessimist](https://www.npmjs.org/package/tap-pessimist) +- [tap-prettify](https://github.com/toolness/tap-prettify) +- [colortape](https://github.com/shuhei/colortape) +- [tap-xunit](https://github.com/aghassemi/tap-xunit) +- [tap-difflet](https://github.com/namuol/tap-difflet) +- [tape-dom](https://github.com/gritzko/tape-dom) +- [tap-diff](https://github.com/axross/tap-diff) +- [tap-notify](https://github.com/axross/tap-notify) +- [tap-summary](https://github.com/zoubin/tap-summary) +- [tap-markdown](https://github.com/Hypercubed/tap-markdown) +- [tap-html](https://github.com/gabrielcsapo/tap-html) +- [tap-react-browser](https://github.com/mcnuttandrew/tap-react-browser) To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From 5f1c5a2f07a0aaa48b44764b32cca61566d10442 Mon Sep 17 00:00:00 2001 From: Ash Belmokadem Date: Fri, 22 Jun 2018 15:39:42 +0200 Subject: [PATCH 344/373] [Docs] cleanup from #439 --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 187c198f..cc58aa2b 100644 --- a/readme.markdown +++ b/readme.markdown @@ -103,7 +103,7 @@ that will output something pretty if you pipe TAP into them: - [tap-json](https://github.com/gummesson/tap-json) - [tap-min](https://github.com/derhuerst/tap-min) - [tap-nyan](https://github.com/calvinmetcalf/tap-nyan) -- [package/tap-pessimist](https://www.npmjs.org/package/tap-pessimist) +- [tap-pessimist](https://www.npmjs.org/package/tap-pessimist) - [tap-prettify](https://github.com/toolness/tap-prettify) - [colortape](https://github.com/shuhei/colortape) - [tap-xunit](https://github.com/aghassemi/tap-xunit) From b1df632b408418fcdcb266383c889cd2567f843b Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 10 Sep 2018 13:46:12 -0400 Subject: [PATCH 345/373] [readme] Change broken image to use web archive --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index cc58aa2b..faf426d1 100644 --- a/readme.markdown +++ b/readme.markdown @@ -6,7 +6,7 @@ tap-producing test harness for node and browsers [![build status](https://secure.travis-ci.org/substack/tape.svg?branch=master)](http://travis-ci.org/substack/tape) -![tape](http://substack.net/images/tape_drive.png) +![tape](https://web.archive.org/web/20170612184731if_/http://substack.net/images/tape_drive.png) # example From 96de340ce96683a4789884eb83412e5f36640f19 Mon Sep 17 00:00:00 2001 From: Dustin Hershman Date: Wed, 21 Nov 2018 09:21:43 -0500 Subject: [PATCH 346/373] Adding tap-junit It was brought to my attention to add my tap-junit module to the batch. I've done so here --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index faf426d1..5f5347c6 100644 --- a/readme.markdown +++ b/readme.markdown @@ -115,6 +115,7 @@ that will output something pretty if you pipe TAP into them: - [tap-markdown](https://github.com/Hypercubed/tap-markdown) - [tap-html](https://github.com/gabrielcsapo/tap-html) - [tap-react-browser](https://github.com/mcnuttandrew/tap-react-browser) +- [tap-junit](https://github.com/dhershman1/tap-junit) To use them, try `node test/index.js | tap-spec` or pipe it into one of the modules of your choice! From f53e3f14cdc5cd2f4551d0114dffb481f87a65aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Akseli=20Pal=C3=A9n?= Date: Sun, 25 Nov 2018 23:58:33 +0200 Subject: [PATCH 347/373] Clarify doesNotThrow parameters To prevent issues like #334, here is a proposal to clarify the purpose of the second argument. My own first reaction to the second argument was like "Whaaat, the docs cannot be right. Even the mere word 'expected' is against the purpose of the assertion. How we can expect something that is not thrown. The argument cannot have any meaning." Then I browsed through the issues, found #334 and then it became clear. --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 5f5347c6..3ba74310 100644 --- a/readme.markdown +++ b/readme.markdown @@ -266,7 +266,7 @@ Assert that the function call `fn()` throws an exception. `expected`, if present ## t.doesNotThrow(fn, expected, msg) -Assert that the function call `fn()` does not throw an exception. `msg` is an optional description of the assertion. +Assert that the function call `fn()` does not throw an exception. `expected`, if present, limits what should not be thrown. For example, set `expected` to `/user/` to fail the test only if the string representation of the exception contains the word `user`. Any other exception would pass the test. If `expected` is omitted, any exception will fail the test. `msg` is an optional description of the assertion. ## t.test(name, [opts], cb) From 75c467eff9b4beba9f9ce5bc186853495b871fdc Mon Sep 17 00:00:00 2001 From: Rafal Date: Fri, 14 Dec 2018 23:36:22 +0100 Subject: [PATCH 348/373] [Docs] Updated readme to make test, test.only and test.skip consistent. --- readme.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.markdown b/readme.markdown index 3ba74310..29ddb349 100644 --- a/readme.markdown +++ b/readme.markdown @@ -153,7 +153,7 @@ Available `opts` options are: If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. -## test.skip(name, cb) +## test.skip([name], [opts], cb) Generate a new test that will be skipped over. @@ -289,9 +289,9 @@ By default the TAP output goes to `console.log()`. You can pipe the output to someplace else if you `htest.createStream().pipe()` to a destination stream on the first tick. -## test.only(name, cb) +## test.only([name], [opts], cb) -Like `test(name, cb)` except if you use `.only` this is the only test case +Like `test([name], [opts], cb)` except if you use `.only` this is the only test case that will run for the entire process, all other test cases using tape will be ignored From 9ced99195a40b4ed835bc4b5b2c9e0ff89fd413b Mon Sep 17 00:00:00 2001 From: Josh Grams Date: Sat, 22 Dec 2018 07:54:11 -0500 Subject: [PATCH 349/373] [Fix] notEqual and notDeepEqual show "expected" value on failure Fixes #453. --- lib/test.js | 4 +- test/not-deep-equal-failure.js | 191 +++++++++++++++++++++++++++++++++ test/not-equal-failure.js | 67 ++++++++++++ 3 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 test/not-deep-equal-failure.js create mode 100644 test/not-equal-failure.js diff --git a/lib/test.js b/lib/test.js index d31c2558..9df5c8b0 100644 --- a/lib/test.js +++ b/lib/test.js @@ -402,7 +402,7 @@ function notEqual(a, b, msg, extra) { message : defined(msg, 'should not be equal'), operator : 'notEqual', actual : a, - notExpected : b, + expected : b, extra : extra }); } @@ -451,7 +451,7 @@ function notDeepEqual(a, b, msg, extra) { message : defined(msg, 'should not be equivalent'), operator : 'notDeepEqual', actual : a, - notExpected : b, + expected : b, extra : extra }); } diff --git a/test/not-deep-equal-failure.js b/test/not-deep-equal-failure.js new file mode 100644 index 00000000..efeed5b7 --- /dev/null +++ b/test/not-deep-equal-failure.js @@ -0,0 +1,191 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); +var tapParser = require('tap-parser'); +var common = require('./common'); + +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.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# not deep equal\n' + + 'not ok 1 should not be equivalent\n' + + ' ---\n' + + ' operator: notDeepEqual\n' + + ' expected: |-\n' + + ' { b: 2 }\n' + + ' actual: |-\n' + + ' { b: 2 }\n' + + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: should not be equivalent\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + assert.deepEqual(getDiag(body), { + operator: 'notDeepEqual', + expected: '{ b: 2 }', + actual: '{ b: 2 }' + }); + })); + + parser.once('assert', function (data) { + delete data.diag.stack; + delete data.diag.at; + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ b: 2 }', + actual: '{ b: 2 }' + } + }); + }); + + 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.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# not deep equal\n' + + 'not ok 1 should not be equivalent\n' + + ' ---\n' + + ' operator: notDeepEqual\n' + + ' expected: |-\n' + + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' + + ' actual: |-\n' + + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' + + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: should not be equivalent\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + 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) { + delete data.diag.stack; + delete data.diag.at; + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' + } + }); + }); + + 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.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# not deep equal\n' + + 'not ok 1 should not be equivalent\n' + + ' ---\n' + + ' operator: notDeepEqual\n' + + ' expected: |-\n' + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' actual: |-\n' + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' + + ' at: Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: should not be equivalent\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + 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) { + delete data.diag.stack; + delete data.diag.at; + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be equivalent', + diag: { + operator: 'notDeepEqual', + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' + } + }); + }); + + 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 new file mode 100644 index 00000000..763e363f --- /dev/null +++ b/test/not-equal-failure.js @@ -0,0 +1,67 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); +var tapParser = require('tap-parser'); +var common = require('./common'); + +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); + + stream.pipe(parser); + stream.pipe(concat(function (body) { + assert.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# not equal\n' + + 'not ok 1 should not be equal\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: 2\n' + + ' actual: 2\n' + + ' at: Test. ($TEST/not-equal-failure.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: should not be equal\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/not-equal-failure.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n' + + '1..1\n' + + '# tests 1\n' + + '# pass 0\n' + + '# fail 1\n' + ); + + assert.deepEqual(getDiag(body), { + operator: 'notEqual', + expected: '2', + actual: '2' + }); + })); + + parser.once('assert', function (data) { + delete data.diag.stack; + delete data.diag.at; + assert.deepEqual(data, { + ok: false, + id: 1, + name: 'should not be equal', + diag: { + operator: 'notEqual', + expected: '2', + actual: '2' + } + }); + }); + + test("not equal", function (t) { + t.plan(1); + t.notEqual(2, 2); + }); +}) From 4b9c951b1629ccb95b42900fb953d18032844b74 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 28 Dec 2018 14:37:41 -0800 Subject: [PATCH 350/373] [Dev Deps] update `eslint`, `eclint` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 354730bd..85d96197 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ }, "devDependencies": { "concat-stream": "^1.6.2", - "eclint": "^2.7.0", - "eslint": "^4.19.1", + "eclint": "^2.8.1", + "eslint": "^5.11.1", "falafel": "^2.1.0", "js-yaml": "^3.12.0", "tap": "^8.0.1", From a1e8f7e21cc7831cf5a857b00627b5dbcdd68aea Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 29 Dec 2018 14:13:06 -0800 Subject: [PATCH 351/373] v4.9.2 - [Fix] notEqual and notDeepEqual show "expected" value on failure (#454) - [Docs] Updated readme to make test, test.only, and test.skip consistent (#452) - [Docs] Clarify doesNotThrow parameters (#450) - [Docs] Adding tap-junit (#449) - [readme] Change broken image to use web archive (#443) - [Docs] convert list of tap reporters to links (#439, #440) - [Dev Deps] update `eslint`, `eclint` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85d96197..fb6d83d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "4.9.1", + "version": "4.9.2", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From aac3e70c29cfd6dd4ff559741a9a43abf918a741 Mon Sep 17 00:00:00 2001 From: Niklas Lindgren Date: Thu, 13 Oct 2016 22:34:00 +0100 Subject: [PATCH 352/373] [Docs] Add an alternative ES6 tape runner I wrapped Buble and Reify for running ES6 syntax tests for my own purposes. Maybe someone else would enjoy it, too. --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index 29ddb349..f2c126c9 100644 --- a/readme.markdown +++ b/readme.markdown @@ -128,7 +128,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - CoffeeScript support with https://www.npmjs.com/package/coffeetape - Promise support with https://www.npmjs.com/package/blue-tape -- ES6 support with https://www.npmjs.com/package/babel-tape-runner +- ES6 support with https://www.npmjs.com/package/babel-tape-runner or https://www.npmjs.com/package/buble-tape-runner # methods From 1693c341abf44462dc0a83aed68ed976a7fc1ad5 Mon Sep 17 00:00:00 2001 From: Per Guth Date: Sun, 16 Apr 2017 22:23:21 +0200 Subject: [PATCH 353/373] [Docs] Mention [`flip-tape`](https://github.com/pguth/flip-tape/blob/master/README.md) in the section "other". --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index f2c126c9..418a4d2a 100644 --- a/readme.markdown +++ b/readme.markdown @@ -129,6 +129,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - CoffeeScript support with https://www.npmjs.com/package/coffeetape - Promise support with https://www.npmjs.com/package/blue-tape - ES6 support with https://www.npmjs.com/package/babel-tape-runner or https://www.npmjs.com/package/buble-tape-runner +- Different test syntax with https://github.com/pguth/flip-tape (warning: mutates String.prototype) # methods From 35844e6143da924b5bba5e67dd0b5914298461f2 Mon Sep 17 00:00:00 2001 From: bambusekd Date: Wed, 22 Nov 2017 10:56:56 +0100 Subject: [PATCH 354/373] [New] add alias 'notDeepEquals' to 'notDeepEqual' function --- lib/test.js | 1 + readme.markdown | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index 9df5c8b0..9f0916ff 100644 --- a/lib/test.js +++ b/lib/test.js @@ -456,6 +456,7 @@ function notDeepEqual(a, b, msg, extra) { }); } Test.prototype.notDeepEqual += Test.prototype.notDeepEquals = Test.prototype.notEquivalent = Test.prototype.notDeeply = Test.prototype.notSame diff --git a/readme.markdown b/readme.markdown index 418a4d2a..b43a1700 100644 --- a/readme.markdown +++ b/readme.markdown @@ -241,7 +241,7 @@ Assert that `actual` and `expected` do not have the same structure and nested va [node's deepEqual() algorithm](https://github.com/substack/node-deep-equal) with strict comparisons (`===`) on leaf nodes and an optional description of the assertion `msg`. -Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, +Aliases: `t.notDeepEquals`, `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, `t.isNotDeepEqual()`, `t.isNotDeeply()`, `t.isNotEquivalent()`, `t.isInequivalent()` From d15bc4b693f26824c03fbd647bc4fea89a4af5e2 Mon Sep 17 00:00:00 2001 From: JP Richardson Date: Fri, 6 Nov 2015 08:34:13 -0600 Subject: [PATCH 355/373] [Docs] Add tape-promise into 'other' Unlike `blue-tape`, `tape-promise` has the following benefits: 1. Doesn't explicitly depend upon `tape`. i.e. can directly modify `tape` if need be and not fixed to the `tape` version of `blue-tape`. 2. Explicitly supports async/await. 3. Has better documentation. --- readme.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.markdown b/readme.markdown index b43a1700..cf9296db 100644 --- a/readme.markdown +++ b/readme.markdown @@ -127,7 +127,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will ## other - CoffeeScript support with https://www.npmjs.com/package/coffeetape -- Promise support with https://www.npmjs.com/package/blue-tape +- Promise support with https://www.npmjs.com/package/blue-tape or https://www.npmjs.com/package/tape-promise - ES6 support with https://www.npmjs.com/package/babel-tape-runner or https://www.npmjs.com/package/buble-tape-runner - Different test syntax with https://github.com/pguth/flip-tape (warning: mutates String.prototype) From 5c36aa862b7b356cd773ae09016039d4b523f304 Mon Sep 17 00:00:00 2001 From: tundrax Date: Wed, 20 Jan 2016 18:40:55 +0900 Subject: [PATCH 356/373] [Docs] Add electron-tap Test electron application with tape --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index cf9296db..a3e6dfe4 100644 --- a/readme.markdown +++ b/readme.markdown @@ -130,6 +130,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - Promise support with https://www.npmjs.com/package/blue-tape or https://www.npmjs.com/package/tape-promise - ES6 support with https://www.npmjs.com/package/babel-tape-runner or https://www.npmjs.com/package/buble-tape-runner - Different test syntax with https://github.com/pguth/flip-tape (warning: mutates String.prototype) +- Electron test runner with https://github.com/tundrax/electron-tap # methods From 8a7567ae54a7f057f7016f76b5f7cef354e011b4 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 3 Oct 2018 16:33:14 +0200 Subject: [PATCH 357/373] [Docs] link to mixed tape --- readme.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.markdown b/readme.markdown index a3e6dfe4..9cb5492e 100644 --- a/readme.markdown +++ b/readme.markdown @@ -131,6 +131,7 @@ By default, uncaught exceptions in your tests will not be intercepted, and will - ES6 support with https://www.npmjs.com/package/babel-tape-runner or https://www.npmjs.com/package/buble-tape-runner - Different test syntax with https://github.com/pguth/flip-tape (warning: mutates String.prototype) - Electron test runner with https://github.com/tundrax/electron-tap +- Concurrency support with https://github.com/imsnif/mixed-tape # methods From fb548b33bc9ec01a4f0242da3345f5f86e90e97d Mon Sep 17 00:00:00 2001 From: mkls Date: Mon, 17 Oct 2016 22:39:02 +0200 Subject: [PATCH 358/373] [Fix] windows: Show failure location even if driver letter is lowercase --- lib/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index 9f0916ff..127fe4ef 100644 --- a/lib/test.js +++ b/lib/test.js @@ -263,9 +263,9 @@ Test.prototype._assert = function assert (ok, opts) { Last part captures file path plus line no (and optional column no). - /((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ + /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ */ - var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[A-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ var m = re.exec(err[i]); if (!m) { From b494b188dc4f909ec7ca085e299fefe247d7b1c0 Mon Sep 17 00:00:00 2001 From: Bill Ticehurst Date: Thu, 27 Apr 2017 12:14:04 -0700 Subject: [PATCH 359/373] [Fix] Stop createStream for creating additional test runner loops --- lib/results.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/results.js b/lib/results.js index 56fdc4ba..0531a101 100644 --- a/lib/results.js +++ b/lib/results.js @@ -24,6 +24,7 @@ function Results () { this._stream = through(); this.tests = []; this._only = null; + this._isRunning = false; } Results.prototype.createStream = function (opts) { @@ -65,14 +66,17 @@ Results.prototype.createStream = function (opts) { self._stream.pipe(output); } - nextTick(function next() { - var t; - while (t = getNextTest(self)) { - t.run(); - if (!t.ended) return t.once('end', function(){ nextTick(next); }); - } - self.emit('done'); - }); + if (!this._isRunning) { + this._isRunning = true; + nextTick(function next() { + var t; + while (t = getNextTest(self)) { + t.run(); + if (!t.ended) return t.once('end', function(){ nextTick(next); }); + } + self.emit('done'); + }); + } return output; }; From 144a36184b8edeb8f586fd1f257bcc8ecf483476 Mon Sep 17 00:00:00 2001 From: Norman Date: Sat, 14 Oct 2017 15:59:33 -0700 Subject: [PATCH 360/373] [Tests] missing t.end(); avoid shadowing --- test/add-subtest-async.js | 8 ++++---- test/subtest_and_async.js | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js index ddc39f76..51a9d0b6 100644 --- a/test/add-subtest-async.js +++ b/test/add-subtest-async.js @@ -3,9 +3,9 @@ var test = require('../') test('parent', function (t) { t.pass('parent'); setTimeout(function () { - t.test('child', function (t) { - t.pass('child'); - t.end(); + t.test('child', function (st) { + st.pass('child'); + st.end(); }); - }, 100) + }, 100); }) diff --git a/test/subtest_and_async.js b/test/subtest_and_async.js index 9e49965d..3703a979 100644 --- a/test/subtest_and_async.js +++ b/test/subtest_and_async.js @@ -5,19 +5,21 @@ var asyncFunction = function (callback) { }; test('master test', function (t) { - t.test('subtest 1', function (t) { - t.pass('subtest 1 before async call'); + t.test('subtest 1', function (st) { + st.pass('subtest 1 before async call'); asyncFunction(function () { - t.pass('subtest 1 in async callback'); - t.end(); + st.pass('subtest 1 in async callback'); + st.end(); }) }); - t.test('subtest 2', function (t) { - t.pass('subtest 2 before async call'); + t.test('subtest 2', function (st) { + st.pass('subtest 2 before async call'); asyncFunction(function () { - t.pass('subtest 2 in async callback'); - t.end(); + st.pass('subtest 2 in async callback'); + st.end(); }) }); + + t.end(); }); From 367b010d21c7c9814c4bc6b21d1c2a9a67596c11 Mon Sep 17 00:00:00 2001 From: Norman Date: Sun, 15 Oct 2017 09:15:30 -0700 Subject: [PATCH 361/373] [Fix] Fix premature end of tests (and running sibling tests) when test includes subtests Fixes #222. --- lib/test.js | 44 +++++++------- test/add-subtest-async.js | 1 + test/async_end.js | 21 +++++++ test/nested-sync-noplan-noend.js | 24 +++++--- test/nested_test_ordering.js | 98 ++++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 32 deletions(-) create mode 100644 test/async_end.js create mode 100644 test/nested_test_ordering.js diff --git a/lib/test.js b/lib/test.js index 127fe4ef..a7f18397 100644 --- a/lib/test.js +++ b/lib/test.js @@ -104,19 +104,11 @@ Test.prototype.test = function (name, opts, cb) { this.emit('test', t); t.on('prerun', function () { self.assertCount++; - }) + }); - if (!self._pendingAsserts()) { - nextTick(function () { - self._end(); - }); + if (!this._pendingAsserts()) { + this._runProgeny(); } - - nextTick(function() { - if (!self._plan && self.pendingCount == self._progeny.length) { - self._end(); - } - }); }; Test.prototype.comment = function (msg) { @@ -144,7 +136,6 @@ Test.prototype.timeoutAfter = function(ms) { } Test.prototype.end = function (err) { - var self = this; if (arguments.length >= 1 && !!err) { this.ifError(err); } @@ -153,18 +144,10 @@ Test.prototype.end = function (err) { this.fail('.end() called twice'); } this.calledEnd = true; - this._end(); + this._runProgeny(); }; Test.prototype._end = function (err) { - var self = this; - if (this._progeny.length) { - var t = this._progeny.shift(); - t.on('end', function () { self._end() }); - t.run(); - return; - } - if (!this.ended) this.emit('end'); var pendingAsserts = this._pendingAsserts(); if (!this._planError && this._plan !== undefined && pendingAsserts) { @@ -177,6 +160,21 @@ Test.prototype._end = function (err) { this.ended = true; }; +Test.prototype._runProgeny = function () { + var self = this; + if (this._progeny.length) { + var t = this._progeny.shift(); + t.on('end', function () { self._runProgeny() }); + nextTick(function() { + t.run(); + }); + return; + } + if(this.calledEnd || this._plan) { + this._end(); + } +}; + Test.prototype._exit = function () { if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { @@ -298,9 +296,7 @@ Test.prototype._assert = function assert (ok, opts) { if (extra.exiting) { self._end(); } else { - nextTick(function () { - self._end(); - }); + self._runProgeny(); } } diff --git a/test/add-subtest-async.js b/test/add-subtest-async.js index 51a9d0b6..efb89060 100644 --- a/test/add-subtest-async.js +++ b/test/add-subtest-async.js @@ -7,5 +7,6 @@ test('parent', function (t) { st.pass('child'); st.end(); }); + t.end(); }, 100); }) diff --git a/test/async_end.js b/test/async_end.js new file mode 100644 index 00000000..2e47e60c --- /dev/null +++ b/test/async_end.js @@ -0,0 +1,21 @@ +var test = require('../'); + +test('async end', function (t) { + setTimeout(function () { + t.assert(!t.ended, '!t.ended'); + t.end(); + }, 200); +}); + +test('async end with subtest', function (t) { + setTimeout(function () { + t.assert(!t.ended, '!t.ended'); + t.end(); + }, 200); + + t.test('subtest', function (g) { + g.assert(!t.ended, 'subtest !t.ended'); + g.end(); + }); +}); + diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 42735a80..aeb920d1 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -1,25 +1,32 @@ var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); +var stripFullStack = require('./common').stripFullStack; tap.test('nested sync test without plan or end', function (tt) { tt.plan(1); var test = tape.createHarness(); var tc = function (rows) { - tt.same(rows.toString('utf8'), [ + tt.same(stripFullStack(rows.toString('utf8')), [ 'TAP version 13', '# nested without plan or end', + 'not ok 1 test timed out after 100ms', + ' ---', + ' operator: fail', + ' stack: |-', + ' Error: test timed out after 100ms', + ' [... stack stripped ...]', + ' ...', '# first', - 'ok 1 should be truthy', - '# second', 'ok 2 should be truthy', + '# second', + 'ok 3 should be truthy', '', - '1..2', - '# tests 2', + '1..3', + '# tests 3', '# pass 2', - '', - '# ok' + '# fail 1', ].join('\n') + '\n'); }; @@ -38,6 +45,7 @@ tap.test('nested sync test without plan or end', function (tt) { q.end() }, 10); }); - }); + t.timeoutAfter(100); + }); }); diff --git a/test/nested_test_ordering.js b/test/nested_test_ordering.js new file mode 100644 index 00000000..5abd4c3f --- /dev/null +++ b/test/nested_test_ordering.js @@ -0,0 +1,98 @@ + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('plan vs end: plan', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (rows) { + tt.same(rows.toString('utf8'), [ + 'TAP version 13', + '# first', + 'ok 1 first test', + 'ok 2 t not ended', + 'ok 3 t has progeny', + '# second', + 'ok 4 second test', + '# third', + 'ok 5 third test', + '', + '1..5', + '# tests 5', + '# pass 5', + '', + '# ok' + ].join('\n') + '\n'); + })); + + test('first', function (t) { + t.plan(4); + setTimeout(function () { + t.ok(1, 'first test'); + t.ok(!t.ended, 't not ended'); + t.ok(t._progeny.length, 't has progeny'); + }, 200); + + t.test('second', function (t) { + t.plan(1); + t.ok(1, 'second test'); + }); + }); + + test('third', function (t) { + t.plan(1); + setTimeout(function () { + t.ok(1, 'third test'); + }, 100); + }); +}); + +tap.test('plan vs end: end', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (rows) { + tt.same(rows.toString('utf8'), [ + 'TAP version 13', + '# first', + 'ok 1 first test', + 'ok 2 t not ended', + 'ok 3 t has progeny', + '# second', + 'ok 4 second test', + '# third', + 'ok 5 third test', + '', + '1..5', + '# tests 5', + '# pass 5', + '', + '# ok' + ].join('\n') + '\n'); + })); + + test('first', function (t) { + setTimeout(function () { + t.ok(1, 'first test'); + t.ok(!t.ended, 't not ended'); + t.ok(t._progeny.length, 't has progeny'); + t.end(); + }, 200); + + t.test('second', function (t) { + t.ok(1, 'second test'); + t.end(); + }); + }); + + test('third', function (t) { + setTimeout(function () { + t.ok(1, 'third test'); + t.end(); + }, 100); + }); +}); From fa586b445cef771d688ee6287f07b19cae30ca19 Mon Sep 17 00:00:00 2001 From: Norman Date: Sun, 15 Oct 2017 13:24:05 -0700 Subject: [PATCH 362/373] [Test]: only use one test runner for results, even if multiple streams are created Fixes #105. --- test/create_multiple_streams.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/create_multiple_streams.js diff --git a/test/create_multiple_streams.js b/test/create_multiple_streams.js new file mode 100644 index 00000000..4b87d044 --- /dev/null +++ b/test/create_multiple_streams.js @@ -0,0 +1,31 @@ +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"); + }); +}); + + From fbe4b951cb6c6cc4f0e9e3ae4a57b123dd82c0fb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 29 Jan 2019 23:19:13 -0800 Subject: [PATCH 363/373] [Refactor] Avoid adding a new observable method to the API. --- lib/test.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/test.js b/lib/test.js index a7f18397..93ddbf68 100644 --- a/lib/test.js +++ b/lib/test.js @@ -39,6 +39,21 @@ var getTestArgs = function (name_, opts_, cb_) { return { name: name, opts: opts, cb: cb }; }; +var runProgeny = function () { + var self = this; + if (this._progeny.length) { + var t = this._progeny.shift(); + t.on('end', function () { runProgeny.call(self) }); + nextTick(function () { + t.run(); + }); + return; + } + if (this.calledEnd || this._plan) { + this._end(); + } +}; + function Test (name_, opts_, cb_) { if (! (this instanceof Test)) { return new Test(name_, opts_, cb_); @@ -107,7 +122,7 @@ Test.prototype.test = function (name, opts, cb) { }); if (!this._pendingAsserts()) { - this._runProgeny(); + runProgeny.call(this); } }; @@ -123,14 +138,14 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; -Test.prototype.timeoutAfter = function(ms) { +Test.prototype.timeoutAfter = function (ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; - var timeout = safeSetTimeout(function() { + var timeout = safeSetTimeout(function () { self.fail('test timed out after ' + ms + 'ms'); self.end(); }, ms); - this.once('end', function() { + this.once('end', function () { safeClearTimeout(timeout); }); } @@ -144,7 +159,7 @@ Test.prototype.end = function (err) { this.fail('.end() called twice'); } this.calledEnd = true; - this._runProgeny(); + runProgeny.call(this); }; Test.prototype._end = function (err) { @@ -160,21 +175,6 @@ Test.prototype._end = function (err) { this.ended = true; }; -Test.prototype._runProgeny = function () { - var self = this; - if (this._progeny.length) { - var t = this._progeny.shift(); - t.on('end', function () { self._runProgeny() }); - nextTick(function() { - t.run(); - }); - return; - } - if(this.calledEnd || this._plan) { - this._end(); - } -}; - Test.prototype._exit = function () { if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { @@ -296,7 +296,7 @@ Test.prototype._assert = function assert (ok, opts) { if (extra.exiting) { self._end(); } else { - self._runProgeny(); + runProgeny.call(self); } } From 5cdaf548b9b1d19c638e937ada10d550290a07c0 Mon Sep 17 00:00:00 2001 From: ronkorving Date: Sun, 14 Feb 2016 14:57:20 +0900 Subject: [PATCH 364/373] [New] Implements TAP TODO directive --- lib/results.js | 10 ++++++---- lib/test.js | 16 +++++++++------- readme.markdown | 1 + test/todo.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 test/todo.js diff --git a/lib/results.js b/lib/results.js index 0531a101..cfe6c022 100644 --- a/lib/results.js +++ b/lib/results.js @@ -21,6 +21,7 @@ function Results () { this.count = 0; this.fail = 0; this.pass = 0; + this.todo = 0; this._stream = through(); this.tests = []; this._only = null; @@ -107,7 +108,7 @@ Results.prototype._watch = function (t) { write(encodeResult(res, self.count + 1)); self.count ++; - if (res.ok) self.pass ++ + if (res.ok || res.todo) self.pass ++ else { self.fail ++; self.emit('fail'); @@ -125,9 +126,10 @@ Results.prototype.close = function () { write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); - write('# pass ' + self.pass + '\n'); - if (self.fail) write('# fail ' + self.fail + '\n') - else write('\n# ok\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); }; diff --git a/lib/test.js b/lib/test.js index 93ddbf68..d594ba46 100644 --- a/lib/test.js +++ b/lib/test.js @@ -66,6 +66,7 @@ function Test (name_, opts_, cb_) { 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; @@ -203,12 +204,13 @@ Test.prototype._assert = function assert (ok, opts) { var extra = opts.extra || {}; var res = { - id : self.assertCount ++, - ok : Boolean(ok), - skip : defined(extra.skip, opts.skip), - name : defined(extra.message, opts.message, '(unnamed assert)'), - operator : defined(extra.operator, opts.operator), - objectPrintDepth : self._objectPrintDepth + id: self.assertCount++, + ok: Boolean(ok), + skip: defined(extra.skip, opts.skip), + todo: defined(extra.todo, opts.todo, self._todo), + name: defined(extra.message, opts.message, '(unnamed assert)'), + operator: defined(extra.operator, opts.operator), + objectPrintDepth: self._objectPrintDepth }; if (has(opts, 'actual') || has(extra, 'actual')) { res.actual = defined(extra.actual, opts.actual); @@ -218,7 +220,7 @@ Test.prototype._assert = function assert (ok, opts) { } this._ok = Boolean(this._ok && ok); - if (!ok) { + if (!ok && !res.todo) { res.error = defined(extra.error, opts.error, new Error(res.name)); } diff --git a/readme.markdown b/readme.markdown index 9cb5492e..3306790c 100644 --- a/readme.markdown +++ b/readme.markdown @@ -152,6 +152,7 @@ Available `opts` options are: - opts.skip = true/false. See test.skip. - opts.timeout = 500. Set a timeout for the test, after which it will fail. See test.timeoutAfter. - opts.objectPrintDepth = 5. Configure max depth of expected / actual object printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the desired default depth for all tests; locally-set values will take precedence. +- opts.todo = true/false. Test will be allowed to fail. If you forget to `t.plan()` out how many assertions you are going to run and you don't call `t.end()` explicitly, your test will hang. diff --git a/test/todo.js b/test/todo.js new file mode 100644 index 00000000..907eaeec --- /dev/null +++ b/test/todo.js @@ -0,0 +1,42 @@ +var tap = require('tap'); +var tape = require('../'); +var concat = require('concat-stream'); + +var common = require('./common'); +var stripFullStack = common.stripFullStack; + +tap.test('tape todo test', function (assert) { + var test = tape.createHarness({ exit: false }); + assert.plan(1); + + test.createStream().pipe(concat(function (body) { + assert.equal( + stripFullStack(body.toString('utf8')), + 'TAP version 13\n' + + '# success\n' + + 'ok 1 this test runs\n' + + '# failure\n' + + 'not ok 2 should never happen # TODO\n' + + ' ---\n' + + ' operator: fail\n' + + ' at: Test. ($TEST/todo.js:$LINE:$COL)\n' + + ' ...\n' + + '\n' + + '1..2\n' + + '# tests 2\n' + + '# pass 2\n' + + '\n' + + '# ok\n' + ) + })); + + 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(); + }); +}); From 040549cd7919726789ba21a9f0cd18f42d5f2da9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:05:32 -0800 Subject: [PATCH 365/373] Merge pull request #268 from ljharb/throws_non_function_should_fail [Fix] Ensure that non-functions passed to `throws` fail the test, just like `assert` --- lib/test.js | 2 +- test/throws.js | 123 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 5 deletions(-) diff --git a/lib/test.js b/lib/test.js index f65f12ad..d7c9f395 100644 --- a/lib/test.js +++ b/lib/test.js @@ -450,7 +450,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { caught.error = caught.error.constructor; } - this._assert(passed, { + this._assert(typeof fn === 'function' && passed, { message : defined(msg, 'should throw'), operator : 'throws', actual : caught && caught.error, diff --git a/test/throws.js b/test/throws.js index ec91fb8d..b8cf056f 100644 --- a/test/throws.js +++ b/test/throws.js @@ -1,20 +1,135 @@ -var test = require('../'); +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); function fn() { throw new TypeError('RegExp'); } -test('throws', function (t) { +function getNonFunctionMessage(fn) { + try { + fn(); + } catch (e) { + return e.message; + } +} + +tape('throws', function (t) { t.throws(fn); t.end(); }); -test('throws (RegExp match)', function (t) { +tape('throws (RegExp match)', function (t) { t.throws(fn, /RegExp/); t.end(); }); -test('throws (Function match)', function (t) { +tape('throws (Function match)', function (t) { t.throws(fn, TypeError); t.end(); }); + +tap.test('failures', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# non functions\n' + + 'not ok 1 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' ...\n' + + 'not ok 2 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' ...\n' + + 'not ok 3 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' ...\n' + + 'not ok 4 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' ...\n' + + 'not ok 5 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' ...\n' + + 'not ok 6 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' ...\n' + + 'not ok 7 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' ...\n' + + 'not ok 8 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' ...\n' + + '# function\n' + + 'not ok 9 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: undefined\n' + + ' actual: undefined\n' + + ' ...\n\n' + + '1..9\n' + + '# tests 9\n' + + '# pass 0\n' + + '# fail 9\n' + ); + })); + + 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 () {}); + }); +}); From 7ed6651b984fa8da66e3014b93bc1beda57bee9b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:24:44 -0800 Subject: [PATCH 366/373] Minor test tweaks due to whitespace differences in v3 vs v4. --- test/throws.js | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/test/throws.js b/test/throws.js index b8cf056f..ed4ed920 100644 --- a/test/throws.js +++ b/test/throws.js @@ -41,66 +41,50 @@ tap.test('failures', function (tt) { + 'not ok 1 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage() + "' }\n" + ' ...\n' + 'not ok 2 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage(null) + "' }\n" + ' ...\n' + 'not ok 3 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage(true) + "' }\n" + ' ...\n' + 'not ok 4 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage(false) + "' }\n" + ' ...\n' + 'not ok 5 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage('abc') + "' }\n" + ' ...\n' + 'not ok 6 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage(/a/g) + "' }\n" + ' ...\n' + 'not ok 7 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage([]) + "' }\n" + ' ...\n' + 'not ok 8 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' - + ' undefined\n' - + ' actual: |-\n' - + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' expected: undefined\n' + + " actual: { message: '" + getNonFunctionMessage({}) + "' }\n" + ' ...\n' + '# function\n' + 'not ok 9 should throw\n' From d0a675ff4970179745e5d528b354f846e67c63ab Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:25:06 -0800 Subject: [PATCH 367/373] v3.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15e892f4..367776c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "3.6.0", + "version": "3.6.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 4c0d9e6b90884fc4024419ac831d972918e593eb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:05:32 -0800 Subject: [PATCH 368/373] Merge pull request #268 from ljharb/throws_non_function_should_fail [Fix] Ensure that non-functions passed to `throws` fail the test, just like `assert` --- lib/test.js | 2 +- test/throws.js | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 test/throws.js diff --git a/lib/test.js b/lib/test.js index e3dda4a1..006af2e5 100644 --- a/lib/test.js +++ b/lib/test.js @@ -425,7 +425,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { expected = String(expected); } - this._assert(passed, { + this._assert(typeof fn === 'function' && passed, { message : defined(msg, 'should throw'), operator : 'throws', actual : caught && caught.error, diff --git a/test/throws.js b/test/throws.js new file mode 100644 index 00000000..b8cf056f --- /dev/null +++ b/test/throws.js @@ -0,0 +1,135 @@ +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +function fn() { + throw new TypeError('RegExp'); +} + +function getNonFunctionMessage(fn) { + try { + fn(); + } catch (e) { + return e.message; + } +} + +tape('throws', function (t) { + t.throws(fn); + t.end(); +}); + +tape('throws (RegExp match)', function (t) { + t.throws(fn, /RegExp/); + t.end(); +}); + +tape('throws (Function match)', function (t) { + t.throws(fn, TypeError); + t.end(); +}); + +tap.test('failures', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + test.createStream().pipe(concat(function (body) { + tt.equal( + body.toString('utf8'), + 'TAP version 13\n' + + '# non functions\n' + + 'not ok 1 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + + ' ...\n' + + 'not ok 2 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + + ' ...\n' + + 'not ok 3 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + + ' ...\n' + + 'not ok 4 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + + ' ...\n' + + 'not ok 5 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + + ' ...\n' + + 'not ok 6 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + + ' ...\n' + + 'not ok 7 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + + ' ...\n' + + 'not ok 8 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: |-\n' + + ' undefined\n' + + ' actual: |-\n' + + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + + ' ...\n' + + '# function\n' + + 'not ok 9 should throw\n' + + ' ---\n' + + ' operator: throws\n' + + ' expected: undefined\n' + + ' actual: undefined\n' + + ' ...\n\n' + + '1..9\n' + + '# tests 9\n' + + '# pass 0\n' + + '# fail 9\n' + ); + })); + + 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 () {}); + }); +}); From 71af8ba72437da9324e25a4606d340f4508a4ebf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:31:12 -0800 Subject: [PATCH 369/373] gitignore node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules From 6ce09d9a27c00ed4cee566feb13886b61f067d90 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:24:44 -0800 Subject: [PATCH 370/373] Minor test tweaks due to whitespace differences in v2 vs v4. --- test/throws.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/throws.js b/test/throws.js index b8cf056f..b33be6cf 100644 --- a/test/throws.js +++ b/test/throws.js @@ -41,65 +41,65 @@ tap.test('failures', function (tt) { + 'not ok 1 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n" + ' ...\n' + 'not ok 2 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n" + ' ...\n' + 'not ok 3 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n" + ' ...\n' + 'not ok 4 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n" + ' ...\n' + 'not ok 5 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n" + ' ...\n' + 'not ok 6 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n" + ' ...\n' + 'not ok 7 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n" + ' ...\n' + 'not ok 8 should throw\n' + ' ---\n' + ' operator: throws\n' - + ' expected: |-\n' + + ' expected:\n' + ' undefined\n' - + ' actual: |-\n' + + ' actual:\n' + " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n" + ' ...\n' + '# function\n' From eddbff5a45b15ccea43cb221e32dbf52ce0cdbf1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Mar 2016 13:31:27 -0800 Subject: [PATCH 371/373] v2.14.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 07ac10ab..de11fac9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tape", - "version": "2.14.0", + "version": "2.14.1", "description": "tap-producing test harness for node and browsers", "main": "index.js", "bin": "./bin/tape", From 9e3d25ec41a0c29d173c6451a30ff19fb8b699ff Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 9 Feb 2019 13:03:30 -0800 Subject: [PATCH 372/373] [Dev Deps] update `eslint`, `js-yaml` --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fb6d83d3..8c498c4b 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "devDependencies": { "concat-stream": "^1.6.2", "eclint": "^2.8.1", - "eslint": "^5.11.1", + "eslint": "^5.13.0", "falafel": "^2.1.0", - "js-yaml": "^3.12.0", + "js-yaml": "^3.12.1", "tap": "^8.0.1", "tap-parser": "^3.0.5" }, From 82e7b266565d080a9cb3bfa7bb18be7029813b9c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 9 Feb 2019 13:04:08 -0800 Subject: [PATCH 373/373] [Deps] update `glob` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c498c4b..c80629d9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "defined": "~1.0.0", "for-each": "~0.3.3", "function-bind": "~1.1.1", - "glob": "~7.1.2", + "glob": "~7.1.3", "has": "~1.0.3", "inherits": "~2.0.3", "minimist": "~1.2.0",