pax_global_header00006660000000000000000000000064130147514170014515gustar00rootroot0000000000000052 comment=72213e119fb9c52e7620fdc58908b1227dd1c9f8 tape-4.6.3/000077500000000000000000000000001301475141700124605ustar00rootroot00000000000000tape-4.6.3/.gitignore000066400000000000000000000000161301475141700144450ustar00rootroot00000000000000/node_modules tape-4.6.3/.travis.yml000066400000000000000000000007221301475141700145720ustar00rootroot00000000000000language: node_js sudo: true node_js: - "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" tape-4.6.3/LICENSE000066400000000000000000000020611301475141700134640ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tape-4.6.3/bin/000077500000000000000000000000001301475141700132305ustar00rootroot00000000000000tape-4.6.3/bin/tape000077500000000000000000000015651301475141700141160ustar00rootroot00000000000000#!/usr/bin/env node var resolveModule = require('resolve').sync; var resolvePath = require('path').resolve; var parseOpts = require('minimist'); var glob = require('glob'); var opts = parseOpts(process.argv.slice(2), { alias: { r: 'require' }, string: 'require', default: { r: [] } }); var cwd = process.cwd(); if (typeof opts.require === 'string') { opts.require = [opts.require]; } 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 })); } }); opts._.forEach(function (arg) { glob(arg, function (err, files) { files.forEach(function (file) { require(resolvePath(cwd, file)); }); }); }); // vim: ft=javascript tape-4.6.3/example/000077500000000000000000000000001301475141700141135ustar00rootroot00000000000000tape-4.6.3/example/array.js000066400000000000000000000014341301475141700155710ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/example/fail.js000066400000000000000000000014371301475141700153710ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/example/nested.js000066400000000000000000000021511301475141700157320ustar00rootroot00000000000000var falafel = require('falafel'); var test = require('../'); test('nested array test', function (t) { t.plan(5); var src = '(' + function () { var xs = [ 1, 2, [ 3, 4 ] ]; var ys = [ 5, 6 ]; g([ xs, ys ]); } + ')()'; var output = falafel(src, function (node) { if (node.type === 'ArrayExpression') { node.update('fn(' + node.source() + ')'); } }); t.test('inside test', function (q) { q.plan(2); q.ok(true, 'inside ok'); setTimeout(function () { q.ok(true, 'inside delayed'); }, 3000); }); var arrays = [ [ 3, 4 ], [ 1, 2, [ 3, 4 ] ], [ 5, 6 ], [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], ]; Function(['fn','g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); test('another', function (t) { t.plan(1); setTimeout(function () { t.ok(true); }, 100); }); tape-4.6.3/example/nested_fail.js000066400000000000000000000021151301475141700167250ustar00rootroot00000000000000var falafel = require('falafel'); var test = require('../'); test('nested array test', function (t) { t.plan(5); var src = '(' + function () { var xs = [ 1, 2, [ 3, 4 ] ]; var ys = [ 5, 6 ]; g([ xs, ys ]); } + ')()'; var output = falafel(src, function (node) { if (node.type === 'ArrayExpression') { node.update('fn(' + node.source() + ')'); } }); t.test('inside test', function (q) { q.plan(2); q.ok(true); setTimeout(function () { q.equal(3, 4); }, 3000); }); var arrays = [ [ 3, 4 ], [ 1, 2, [ 3, 4 ] ], [ 5, 6 ], [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], ]; Function(['fn','g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); test('another', function (t) { t.plan(1); setTimeout(function () { t.ok(true); }, 100); }); tape-4.6.3/example/not_enough.js000066400000000000000000000014341301475141700166200ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/example/static/000077500000000000000000000000001301475141700154025ustar00rootroot00000000000000tape-4.6.3/example/static/build.sh000077500000000000000000000000611301475141700170350ustar00rootroot00000000000000#!/bin/bash browserify ../timing.js -o bundle.js tape-4.6.3/example/static/index.html000066400000000000000000000005421301475141700174000ustar00rootroot00000000000000 tape-4.6.3/example/static/server.js000066400000000000000000000002121301475141700172410ustar00rootroot00000000000000var http = require('http'); var ecstatic = require('ecstatic')(__dirname); var server = http.createServer(ecstatic); server.listen(8000); tape-4.6.3/example/stream/000077500000000000000000000000001301475141700154065ustar00rootroot00000000000000tape-4.6.3/example/stream/object.js000066400000000000000000000003761301475141700172200ustar00rootroot00000000000000var test = require('../../'); 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)); }); tape-4.6.3/example/stream/tap.js000066400000000000000000000002731301475141700165320ustar00rootroot00000000000000var test = require('../../'); var path = require('path'); test.createStream().pipe(process.stdout); process.argv.slice(2).forEach(function (file) { require(path.resolve(file)); }); tape-4.6.3/example/stream/test/000077500000000000000000000000001301475141700163655ustar00rootroot00000000000000tape-4.6.3/example/stream/test/x.js000066400000000000000000000001451301475141700171720ustar00rootroot00000000000000var test = require('../../../'); test(function (t) { t.plan(1); t.equal('beep', 'boop'); }); tape-4.6.3/example/stream/test/y.js000066400000000000000000000002541301475141700171740ustar00rootroot00000000000000var 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(); }); tape-4.6.3/example/throw.js000066400000000000000000000002761301475141700156210ustar00rootroot00000000000000var falafel = require('falafel'); var test = require('../'); test('throw', function (t) { t.plan(2); setTimeout(function () { throw new Error('doom'); }, 100); }); tape-4.6.3/example/timing.js000066400000000000000000000003621301475141700157410ustar00rootroot00000000000000var 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); }); tape-4.6.3/example/too_many.js000066400000000000000000000014341301475141700163000ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/example/two.js000066400000000000000000000005061301475141700152630ustar00rootroot00000000000000var test = require('../'); test('one', function (t) { t.plan(2); t.ok(true); setTimeout(function () { t.equal(1+3, 4); }, 100); }); test('two', function (t) { t.plan(3); t.equal(5, 2+3); setTimeout(function () { t.equal('a'.charCodeAt(0), 97); t.ok(true); }, 50); }); tape-4.6.3/index.js000066400000000000000000000076041301475141700141340ustar00rootroot00000000000000var 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' && process.browser !== true ; var canExit = typeof process !== 'undefined' && process && typeof process.exit === 'function' ; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; exports = module.exports = (function () { var harness; 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) { var output = through(); getHarness({ stream: output, objectMode: opts.objectMode }); return output; } return harness.createStream(opts); }; lazyLoad.onFinish = function () { return getHarness().onFinish.apply(this, arguments); }; lazyLoad.getHarness = getHarness return lazyLoad function getHarness (opts) { if (!opts) opts = {}; opts.autoclose = !canEmitExit; if (!harness) harness = createExitHarness(opts); return harness; } })(); function createExitHarness (conf) { if (!conf) 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; var inErrorState = false; process.on('exit', function (code) { // let the process exit cleanly. if (code !== 0) { return } if (!ended) { var only = harness._results._only; for (var i = 0; i < harness._tests.length; i++) { var t = harness._tests[i]; if (only && t !== only) continue; t._exit(); } } harness.close(); process.exit(code || harness._exitCode); }); return harness; } exports.createHarness = createHarness; exports.Test = Test; exports.test = exports; // tap compat exports.test.skip = Test.skip; var exitInterval; function createHarness (conf_) { if (!conf_) conf_ = {}; var results = createResult(); 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_); }); st.on('result', function (r) { 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); }; test.onFinish = function (cb) { results.on('done', cb); }; var only = false; test.only = function () { if (only) throw new Error('there can only be one only test'); only = true; var t = test.apply(null, arguments); results.only(t); return t; }; test._exitCode = 0; test.close = function () { results.close() }; return test; } tape-4.6.3/lib/000077500000000000000000000000001301475141700132265ustar00rootroot00000000000000tape-4.6.3/lib/default_stream.js000066400000000000000000000014451301475141700165670ustar00rootroot00000000000000var 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' ? buf.charAt(i) : String.fromCharCode(buf[i]) ; if (c === '\n') flush(); else line += c; } } function flush () { if (fs.writeSync && /^win/.test(process.platform)) { try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e) } } else { try { console.log(line) } catch (e) { stream.emit('error', e) } } line = ''; } }; tape-4.6.3/lib/results.js000066400000000000000000000122571301475141700152740ustar00rootroot00000000000000var EventEmitter = require('events').EventEmitter; 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 = bind.call(Function.call, RegExp.prototype.test); var yamlIndicators = /\:|\-|\?/; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; module.exports = Results; inherits(Results, EventEmitter); function Results () { if (!(this instanceof Results)) return new Results; this.count = 0; this.fail = 0; this.pass = 0; this._stream = through(); this.tests = []; this._only = null; } Results.prototype.createStream = function (opts) { if (!opts) opts = {}; var self = this; var output, testId = 0; if (opts.objectMode) { output = through(); self.on('_push', function ontest (t, extra) { if (!extra) extra = {}; var id = testId++; t.once('prerun', function () { var row = { type: 'test', name: t.name, id: id }; if (has(extra, 'parent')) { row.parent = extra.parent; } output.queue(row); }); t.on('test', function (st) { ontest(st, { parent: id }); }); t.on('result', function (res) { 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; while (t = getNextTest(self)) { t.run(); if (!t.ended) return t.once('end', function(){ nextTick(next); }); } self.emit('done'); }); return output; }; Results.prototype.push = function (t) { var self = this; self.tests.push(t); self._watch(t); self.emit('_push', t); }; Results.prototype.only = function (t) { this._only = t; }; Results.prototype._watch = function (t) { var self = this; var write = function (s) { self._stream.queue(s) }; t.once('prerun', function () { write('# ' + t.name + '\n'); }); t.on('result', function (res) { if (typeof res === 'string') { write('# ' + res + '\n'); return; } write(encodeResult(res, self.count + 1)); self.count ++; if (res.ok) self.pass ++ else self.fail ++ }); t.on('test', function (st) { self._watch(st) }); }; Results.prototype.close = function () { var self = this; if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED')); self.closed = true; var write = function (s) { self._stream.queue(s) }; write('\n1..' + self.count + '\n'); write('# tests ' + self.count + '\n'); write('# pass ' + self.pass + '\n'); if (self.fail) write('# fail ' + self.fail + '\n') else write('\n# ok\n') self._stream.queue(null); }; function encodeResult (res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; output += res.name ? ' ' + 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'; } else { output += inner + 'expected: ' + ex + '\n'; output += inner + 'actual: ' + ac + '\n'; } } 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'); output += inner + 'stack: |-\n'; for (var i = 0; i < lines.length; i++) { output += inner + ' ' + lines[i] + '\n'; } } output += outer + '...\n'; return output; } function getNextTest (results) { if (!results._only) { return results.tests.shift(); } do { var t = results.tests.shift(); if (!t) continue; if (results._only === t) { return t; } } while (results.tests.length !== 0) } function invalidYaml (str) { return regexpTest(yamlIndicators, str); } tape-4.6.3/lib/test.js000066400000000000000000000312131301475141700145430ustar00rootroot00000000000000var deepEqual = require('deep-equal'); var defined = require('defined'); var path = require('path'); 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 forEach = require('for-each'); var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable); module.exports = Test; var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick ; var safeSetTimeout = setTimeout; inherits(Test, EventEmitter); var getTestArgs = function (name_, opts_, cb_) { var name = '(anonymous)'; var opts = {}; var cb; for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; var t = typeof arg; if (t === 'string') { name = arg; } else if (t === 'object') { opts = arg || opts; } else if (t === 'function') { cb = arg; } } return { name: name, opts: opts, cb: cb }; }; function Test (name_, opts_, cb_) { if (! (this instanceof Test)) { return new Test(name_, opts_, cb_); } var args = getTestArgs(name_, opts_, cb_); this.readable = true; this.name = args.name || '(anonymous)'; this.assertCount = 0; this.pendingCount = 0; this._skip = args.opts.skip || false; this._timeout = args.opts.timeout; this._objectPrintDepth = args.opts.objectPrintDepth || 5; this._plan = undefined; this._cb = args.cb; this._progeny = []; this._ok = true; for (var 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 () { if (this._skip) { this.comment('SKIP ' + this.name); } 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'); }; 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(); }); } nextTick(function() { if (!self._plan && self.pendingCount == self._progeny.length) { self._end(); } }); }; Test.prototype.comment = function (msg) { var that = this; forEach(trim(msg).split('\n'), function (aMsg) { that.emit('result', trim(aMsg).replace(/^#\s*/, '')); }); }; Test.prototype.plan = function (n) { this._plan = n; this.emit('plan', n); }; Test.prototype.timeoutAfter = function(ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; var timeout = safeSetTimeout(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 && !!err) { this.ifError(err); } if (this.calledEnd) { this.fail('.end() called twice'); } this.calledEnd = true; this._end(); }; 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) { this._planError = true; this.fail('plan != count', { expected : this._plan, actual : this.assertCount }); } this.ended = true; }; Test.prototype._exit = function () { if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { this._planError = true; this.fail('plan != count', { expected : this._plan, actual : this.assertCount, exiting : true }); } else if (!this.ended) { this.fail('test exited without ending', { exiting: true }); } }; 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 || {}; 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 }; 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) { res.error = defined(extra.error, opts.error, new Error(res.name)); } if (!ok) { var e = new Error('exception'); var err = (e.stack || '').split('\n'); var dir = path.dirname(__dirname) + path.sep; 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 = /((?:\/|[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; } } } 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(); if (!pendingAsserts) { if (extra.exiting) { self._end(); } else { nextTick(function () { self._end(); }); } } if (!self._planError && pendingAsserts < 0) { self._planError = true; self.fail('plan != count', { expected : self._plan, actual : self._plan - pendingAsserts }); } }; Test.prototype.fail = function (msg, extra) { this._assert(false, { message : msg, operator : 'fail', extra : extra }); }; Test.prototype.pass = function (msg, extra) { this._assert(true, { message : msg, operator : 'pass', extra : extra }); }; Test.prototype.skip = function (msg, extra) { this._assert(true, { message : msg, operator : 'skip', skip : true, extra : extra }); }; Test.prototype.ok = Test.prototype['true'] = Test.prototype.assert = function (value, msg, extra) { this._assert(value, { message : defined(msg, 'should be truthy'), operator : 'ok', expected : true, actual : value, extra : extra }); }; Test.prototype.notOk = Test.prototype['false'] = Test.prototype.notok = function (value, msg, extra) { this._assert(!value, { message : defined(msg, 'should be falsy'), operator : 'notOk', expected : false, actual : value, extra : extra }); }; Test.prototype.error = Test.prototype.ifError = Test.prototype.ifErr = Test.prototype.iferror = function (err, msg, extra) { this._assert(!err, { message : defined(msg, String(err)), operator : 'error', actual : err, 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', actual : a, expected : b, extra : extra }); }; Test.prototype.notEqual = Test.prototype.notEquals = Test.prototype.notStrictEqual = Test.prototype.notStrictEquals = Test.prototype.isNotEqual = Test.prototype.isNot = 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', actual : a, notExpected : 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 }), { message : defined(msg, 'should be equivalent'), operator : 'deepEqual', 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', actual : a, expected : b, extra : extra }); }; Test.prototype.notDeepEqual = Test.prototype.notEquivalent = Test.prototype.notDeeply = Test.prototype.notSame = Test.prototype.isNotDeepEqual = 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 }); }; 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; expected = undefined; } var caught = undefined; try { fn(); } catch (err) { caught = { error : err }; if ((err != null) && (!isEnumerable(err, 'message') || !has(err, 'message'))) { var message = err.message; delete err.message; err.message = message; } } var passed = caught; if (expected instanceof RegExp) { passed = expected.test(caught && caught.error); expected = String(expected); } if (typeof expected === 'function' && caught) { passed = caught.error instanceof expected; caught.error = caught.error.constructor; } this._assert(typeof fn === 'function' && passed, { message : defined(msg, 'should throw'), operator : 'throws', actual : caught && caught.error, expected : expected, error: !passed && caught && caught.error, extra : extra }); }; Test.prototype.doesNotThrow = function (fn, expected, msg, extra) { if (typeof expected === 'string') { msg = expected; expected = undefined; } var caught = undefined; try { fn(); } catch (err) { caught = { error : err }; } this._assert(!caught, { message : defined(msg, 'should not throw'), operator : 'throws', actual : caught && caught.error, expected : expected, error : caught && caught.error, extra : extra }); }; Test.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: tape-4.6.3/package.json000066400000000000000000000026011301475141700147450ustar00rootroot00000000000000{ "name": "tape", "version": "4.6.3", "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.0", "glob": "~7.1.1", "has": "~1.0.1", "inherits": "~2.0.3", "minimist": "~1.2.0", "object-inspect": "~1.2.1", "resolve": "~1.1.7", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" }, "devDependencies": { "concat-stream": "~1.5.2", "falafel": "~2.0.0", "js-yaml": "~3.7.0", "tap": "~7.1.1", "tap-parser": "~3.0.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" } tape-4.6.3/readme.markdown000066400000000000000000000275011301475141700154660ustar00rootroot00000000000000# tape 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.svg?branch=master)](http://travis-ci.org/substack/tape) ![tape](http://substack.net/images/tape_drive.png) # example ``` js 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); }); ``` ``` $ node example/timing.js TAP version 13 # timing test ok 1 should be equal not ok 2 should be equal --- operator: equal expected: 100 actual: 107 ... 1..2 # tests 2 # pass 1 # 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" ``` ## 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 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. ## 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 - 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 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. ## other - 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 The assertion methods in tape are heavily influenced or copied from the methods in [node-tap](https://github.com/isaacs/node-tap). ``` 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 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. 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. ## 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 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(err) Declare the end of a test explicitly. If `err` is passed in `t.end` will assert that it is falsey. ## t.fail(msg) Generate a failing assertion with a message `msg`. ## t.pass(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. ## t.ok(value, 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 of the assertion `msg`. Aliases: `t.false()`, `t.notok()` ## t.error(err, msg) Assert that `err` is falsy. If `err` is non-falsy, use its `err.message` as the description message. Aliases: `t.ifError()`, `t.ifErr()`, `t.iferror()` ## t.equal(actual, expected, 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 of the assertion `msg`. Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNotEqual()`, `t.isNot()`, `t.not()`, `t.doesNotEqual()`, `t.isInequal()` ## t.deepEqual(actual, expected, msg) 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 of the assertion `msg`. Aliases: `t.deepEquals()`, `t.isEquivalent()`, `t.same()` ## t.notDeepEqual(actual, expected, msg) 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 of the assertion `msg`. Aliases: `t.notEquivalent()`, `t.notDeeply()`, `t.notSame()`, `t.isNotDeepEqual()`, `t.isNotDeeply()`, `t.isNotEquivalent()`, `t.isInequivalent()` ## t.deepLooseEqual(actual, expected, msg) 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 of the assertion `msg`. Aliases: `t.looseEqual()`, `t.looseEquals()` ## t.notDeepLooseEqual(actual, expected, msg) 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 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`. 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. `msg` is an optional description of the assertion. ## 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.) ## var htest = test.createHarness() 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 `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) 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: ``` npm install tape --save-dev ``` # license MIT tape-4.6.3/test/000077500000000000000000000000001301475141700134375ustar00rootroot00000000000000tape-4.6.3/test/add-subtest-async.js000066400000000000000000000003061301475141700173260ustar00rootroot00000000000000var test = require('../') test('parent', function (t) { t.pass('parent'); setTimeout(function () { t.test('child', function (t) { t.pass('child'); t.end(); }); }, 100) }) tape-4.6.3/test/array.js000066400000000000000000000031151301475141700151130ustar00rootroot00000000000000var falafel = require('falafel'); 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 (rows) { tt.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); }); tape-4.6.3/test/bound.js000066400000000000000000000002661301475141700151100ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/browser/000077500000000000000000000000001301475141700151225ustar00rootroot00000000000000tape-4.6.3/test/browser/asserts.js000066400000000000000000000003061301475141700171430ustar00rootroot00000000000000var test = require('../../'); test(function (t) { t.plan(4); t.ok(true); t.equal(3, 1+2); t.deepEqual([1,2,[3,4]], [1,2,[3,4]]); t.notDeepEqual([1,2,[3,4,5]], [1,2,[3,4]]); }); tape-4.6.3/test/child_ordering.js000066400000000000000000000025641301475141700167600ustar00rootroot00000000000000var test = require('../'); var childRan = false; test('parent', function(t) { t.test('child', function(t) { childRan = true; t.pass('child ran'); t.end(); }); t.end(); }); test('uncle', function(t) { t.ok(childRan, 'Child should run before next top-level test'); t.end(); }); var grandParentRan = false; var parentRan = false; var grandChildRan = false; test('grandparent', function(t) { t.ok(!grandParentRan, 'grand parent ran twice'); grandParentRan = true; t.test('parent', function(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(); }); t.pass('parent ran'); t.end(); }); t.test('other parent', function(t) { t.ok(parentRan, 'first parent runs before second parent'); t.ok(grandChildRan, 'grandchild runs before second parent'); t.end(); }); t.pass('grandparent ran'); t.end(); }); test('second grandparent', function(t) { t.ok(grandParentRan, 'grandparent ran'); t.ok(parentRan, 'parent ran'); t.ok(grandChildRan, 'grandchild ran'); t.pass('other grandparent ran'); t.end(); }); // vim: set softtabstop=4 shiftwidth=4: tape-4.6.3/test/circular-things.js000066400000000000000000000017051301475141700170760ustar00rootroot00000000000000var tape = require('../'); var tap = require('tap'); var concat = require('concat-stream'); 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'), '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, {}); }) }) tape-4.6.3/test/comment.js000066400000000000000000000105471301475141700154460ustar00rootroot00000000000000var 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(1); var test = tape.createHarness(); test.createStream(); test('missing argument', function (t) { try { t.comment(); t.end(); } catch (err) { assert.equal(err.constructor, TypeError); } finally { assert.end(); } }); }); // Exploratory test, can we call t.comment() passing nothing? tap.test('null argument', function (assert) { assert.plan(1); var test = tape.createHarness(); test.createStream(); test('null argument', function (t) { try { t.comment(null); t.end(); } catch (err) { assert.equal(err.constructor, TypeError); } finally { assert.end(); } }); }); // 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(); }); }); tap.test('multiline string', function (assert) { assert.plan(1); var verify = function (output) { assert.equal(output.toString('utf8'), [ 'TAP version 13', '# multiline strings', '# a', '# b', '# c', '# d', '', '1..0', '# tests 0', '# pass 0', '', '# ok', '' ].join('\n')); }; var test = tape.createHarness(); test.createStream().pipe(concat(verify)); test('multiline strings', function (t) { t.comment([ 'a', 'b', ].join('\n')); t.comment([ 'c', 'd', ].join('\r\n')); t.end(); }); }); tape-4.6.3/test/deep-equal-failure.js000066400000000000000000000121111301475141700174400ustar00rootroot00000000000000var 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}); }); }) 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'); var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { return line.slice(2); }).join('\n'); return yaml.safeLoad(diag); } tape-4.6.3/test/deep.js000066400000000000000000000004421301475141700147120ustar00rootroot00000000000000var test = require('../'); test('deep strict equal', function (t) { t.notDeepEqual( [ { a: '3' } ], [ { a: 3 } ] ); t.end(); }); test('deep loose equal', function (t) { t.deepLooseEqual( [ { a: '3' } ], [ { a: 3 } ] ); t.end(); }); tape-4.6.3/test/default-messages.js000066400000000000000000000015571301475141700172360ustar00rootroot00000000000000var tap = require('tap'); var path = require('path'); var spawn = require('child_process').spawn; var concat = require('concat-stream'); 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'), [ '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'); })); }); tape-4.6.3/test/double_end.js000066400000000000000000000014311301475141700160740ustar00rootroot00000000000000var 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, [path.join(__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'); })); }); tape-4.6.3/test/double_end/000077500000000000000000000000001301475141700155375ustar00rootroot00000000000000tape-4.6.3/test/double_end/double.js000066400000000000000000000002421301475141700173450ustar00rootroot00000000000000var test = require('../../'); test('double end', function (t) { t.equal(1 + 1, 2); t.end(); setTimeout(function () { t.end(); }, 5); }); tape-4.6.3/test/end-as-callback.js000066400000000000000000000044621301475141700167040ustar00rootroot00000000000000var tap = require("tap"); var forEach = require("for-each"); var tape = require("../"); 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' ].join('\n') + '\n'); tt.end() })); test("do a task and write", function (assert) { fakeAsyncTask("foo", function (err, value) { assert.ifError(err) assert.equal(value, "taskfoo") 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")) } /** * 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; forEach(rows.toString('utf8').split('\n'), function (row) { if (!extract) { if (row.indexOf('---') > -1) { // start of stack trace extract = true; } } else { if (row.indexOf('...') > -1) { // end of stack trace extract = false; stacktrace += ' ...'; } else { stacktrace += row + '\n'; } } }); // console.log(stacktrace); return stacktrace; } tape-4.6.3/test/exit.js000066400000000000000000000071271301475141700147550ustar00rootroot00000000000000var tap = require('tap'); var path = require('path'); var spawn = require('child_process').spawn; var concat = require('concat-stream'); tap.test('exit ok', function (t) { t.plan(2); var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', '# array', '# hi', 'ok 1 should be 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); }); }); tap.test('exit fail', function (t) { t.plan(2); var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); }); }); tap.test('too few exit', function (t) { t.plan(2); var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); }); }); tap.test('more planned in a second test', function (t) { t.plan(2); var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', '# first', 'ok 1 should be truthy', '# second', 'ok 2 should be truthy', 'not ok 3 plan != count', ' ---', ' operator: fail', ' expected: 2', ' actual: 1', ' ...', '', '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); }); }); tape-4.6.3/test/exit/000077500000000000000000000000001301475141700144105ustar00rootroot00000000000000tape-4.6.3/test/exit/fail.js000066400000000000000000000014421301475141700156620ustar00rootroot00000000000000var test = require('../../'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/test/exit/ok.js000066400000000000000000000014641301475141700153640ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/test/exit/second.js000066400000000000000000000002411301475141700162160ustar00rootroot00000000000000var test = require('../../'); test('first', function (t) { t.plan(1); t.ok(true); }); test('second', function (t) { t.plan(2); t.ok(true); }); tape-4.6.3/test/exit/too_few.js000066400000000000000000000014371301475141700164150ustar00rootroot00000000000000var falafel = require('falafel'); 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); tape-4.6.3/test/exposed-harness.js000066400000000000000000000004261301475141700171070ustar00rootroot00000000000000var 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() }) tape-4.6.3/test/fail.js000066400000000000000000000035031301475141700147110ustar00rootroot00000000000000var falafel = require('falafel'); 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({ exit : false }); var tc = function (rows) { tt.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); } ); }); }); tape-4.6.3/test/many.js000066400000000000000000000002771301475141700147470ustar00rootroot00000000000000var test = require('../'); test('many tests', function (t) { t.plan(100); for (var i = 0; i < 100; i++) { setTimeout(function () { t.pass() }, Math.random() * 50); } }); tape-4.6.3/test/max_listeners.js000066400000000000000000000004401301475141700166500ustar00rootroot00000000000000var spawn = require('child_process').spawn; 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) { console.log('not ok ' + buf); }); tape-4.6.3/test/max_listeners/000077500000000000000000000000001301475141700163145ustar00rootroot00000000000000tape-4.6.3/test/max_listeners/source.js000066400000000000000000000002031301475141700201450ustar00rootroot00000000000000var test = require('../../'); for (var i = 0; i < 11; i ++) { test(function (t) { t.ok(true, 'true is truthy'); t.end() }); } tape-4.6.3/test/messages/000077500000000000000000000000001301475141700152465ustar00rootroot00000000000000tape-4.6.3/test/messages/defaults.js000066400000000000000000000004111301475141700174070ustar00rootroot00000000000000var 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); }); tape-4.6.3/test/nested-async-plan-noend.js000066400000000000000000000013671301475141700204320ustar00rootroot00000000000000var 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); }); tape-4.6.3/test/nested-sync-noplan-noend.js000066400000000000000000000020701301475141700206160ustar00rootroot00000000000000var tape = require('../'); var tap = require('tap'); 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 = function (rows) { tt.same(rows.toString('utf8'), [ 'TAP version 13', '# nested without plan or end', '# first', 'ok 1 should be truthy', '# second', 'ok 2 should be truthy', '', '1..2', '# tests 2', '# pass 2', '', '# ok' ].join('\n') + '\n'); }; test.createStream().pipe(concat(tc)); test('nested without plan or end', function(t) { t.test('first', function(q) { setTimeout(function first() { q.ok(true); q.end() }, 10); }); t.test('second', function(q) { setTimeout(function second() { q.ok(true); q.end() }, 10); }); }); }); tape-4.6.3/test/nested.js000066400000000000000000000041671301475141700152670ustar00rootroot00000000000000var falafel = require('falafel'); 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(); var tc = function (rows) { tt.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); test('another', function (t) { t.plan(1); setTimeout(function () { t.ok(true); }, 50); }); }); tape-4.6.3/test/nested2.js000066400000000000000000000004621301475141700153430ustar00rootroot00000000000000var 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() }) tape-4.6.3/test/no_callback.js000066400000000000000000000000621301475141700162230ustar00rootroot00000000000000var test = require('../'); test('No callback.'); tape-4.6.3/test/onFinish.js000066400000000000000000000004051301475141700155510ustar00rootroot00000000000000var tap = require("tap"); var tape = require("../"); tap.test("on finish", {timeout: 1000}, function (tt) { tt.plan(1); tape.onFinish(function() { tt.pass('tape ended'); }); tape('dummy test', function(t) { t.end(); }); }); tape-4.6.3/test/only-twice.js000066400000000000000000000006321301475141700160700ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/only.js000066400000000000000000000017341301475141700147630ustar00rootroot00000000000000var tap = require('tap'); var tape = require('../'); var concat = require('concat-stream'); tap.test('tape only test', function (tt) { var test = tape.createHarness({ exit: false }); var ran = []; var tc = function (rows) { tt.deepEqual(rows.toString('utf8'), [ 'TAP version 13', '# 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(concat(tc)); test("never run fail", function (t) { ran.push(1); t.equal(true, false) t.end() }) test("never run success", function (t) { ran.push(2); t.equal(true, true) t.end() }) test.only("run success", function (t) { ran.push(3); t.ok(true, "assert name") t.end() }) }) tape-4.6.3/test/only2.js000066400000000000000000000002141301475141700150350ustar00rootroot00000000000000var test = require('../'); test('only2 test 1', function (t) { t.end(); }); test.only('only2 test 2', function (t) { t.end(); }); tape-4.6.3/test/only3.js000066400000000000000000000003541301475141700150430ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/only4.js000066400000000000000000000002731301475141700150440ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/only5.js000066400000000000000000000002731301475141700150450ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/order.js000066400000000000000000000004351301475141700151120ustar00rootroot00000000000000var test = require('../'); var current = 0; test(function (t) { t.equal(current++, 0); t.end(); }); test(function (t) { t.plan(1); setTimeout(function () { t.equal(current++, 1); }, 100); }); test(function (t) { t.equal(current++, 2); t.end(); }); tape-4.6.3/test/plan_optional.js000066400000000000000000000004331301475141700166340ustar00rootroot00000000000000var test = require('../'); test('plan should be optional', function (t) { t.pass('no plan here'); t.end(); }); test('no plan async', function (t) { setTimeout(function() { t.pass('ok'); t.end(); }, 100); }); // vim: set softtabstop=4 shiftwidth=4: tape-4.6.3/test/require.js000066400000000000000000000035611301475141700154560ustar00rootroot00000000000000var tap = require('tap'); var spawn = require('child_process').spawn; 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', '# 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(concat(tc)); ps.on('exit', function (code) { t.equal(code, 0); }); }); tap.test('requiring multiple modules', function (t) { t.plan(2); var tc = function (rows) { t.same(rows.toString('utf8'), [ 'TAP version 13', '# module-a', 'ok 1 loaded module a', '# module-b', 'ok 2 loaded module b', '# test-a', 'ok 3 module-a loaded in same context', 'ok 4 test ran after module-a was loaded', '# test-b', 'ok 5 module-b loaded in same context', 'ok 6 test ran after module-b was loaded', '', '1..6', '# tests 6', '# pass 6', '', '# ok' ].join('\n') + '\n\n'); }; var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js'); ps.stdout.pipe(concat(tc)); ps.on('exit', function (code) { t.equal(code, 0); }); }); function tape(args) { var proc = require('child_process') var bin = __dirname + '/../bin/tape' return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname }) }tape-4.6.3/test/require/000077500000000000000000000000001301475141700151135ustar00rootroot00000000000000tape-4.6.3/test/require/a.js000066400000000000000000000002041301475141700156650ustar00rootroot00000000000000var tape = require('../..'); tape.test('module-a', function(t) { t.plan(1) t.pass('loaded module a') }) global.module_a = truetape-4.6.3/test/require/b.js000066400000000000000000000002041301475141700156660ustar00rootroot00000000000000var tape = require('../..'); tape.test('module-b', function(t) { t.plan(1) t.pass('loaded module b') }) global.module_b = truetape-4.6.3/test/require/test-a.js000066400000000000000000000002661301475141700166520ustar00rootroot00000000000000var 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() })tape-4.6.3/test/require/test-b.js000066400000000000000000000002661301475141700166530ustar00rootroot00000000000000var 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() })tape-4.6.3/test/skip.js000066400000000000000000000021361301475141700147450ustar00rootroot00000000000000var 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('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 subtest', function(t) { ran++; t.test('skip this', { skip: true }, function(t) { t.fail('this should not even run'); t.end(); }); t.end(); }); // vim: set softtabstop=4 shiftwidth=4: tape-4.6.3/test/stackTrace.js000066400000000000000000000041251301475141700160630ustar00rootroot00000000000000var 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); } tape-4.6.3/test/subcount.js000066400000000000000000000004221301475141700156350ustar00rootroot00000000000000var 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'); }) }) tape-4.6.3/test/subtest_and_async.js000066400000000000000000000010161301475141700175030ustar00rootroot00000000000000var 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(); }) }); }); tape-4.6.3/test/subtest_plan.js000066400000000000000000000006701301475141700165030ustar00rootroot00000000000000var 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 first'); t.pass('pass second child'); }); }); tape-4.6.3/test/throws.js000066400000000000000000000117111301475141700153240ustar00rootroot00000000000000var 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; } } 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' + '# 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' ); })); test('non functions', function (t) { t.plan(8); t.throws(); t.throws(null); t.throws(true); t.throws(false); t.throws('abc'); t.throws(/a/g); t.throws([]); t.throws({}); }); test('function', function (t) { t.plan(1); t.throws(function () {}); }); test('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'); }); test('throws null', function (t) { t.plan(1); t.throws(function () { throw null; }, 'throws null'); t.end(); }); }); tape-4.6.3/test/timeout.js000066400000000000000000000004171301475141700154650ustar00rootroot00000000000000var 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(); }); tape-4.6.3/test/timeoutAfter.js000066400000000000000000000013571301475141700164530ustar00rootroot00000000000000var tape = require('../'); var tap = require('tap'); 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'), [ 'TAP version 13', '# 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); }); }); tape-4.6.3/test/too_many.js000066400000000000000000000034231301475141700156240ustar00rootroot00000000000000var falafel = require('falafel'); 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({ exit : false }); var tc = function (rows) { tt.same(rows.toString('utf8'), [ 'TAP version 13', '# 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); return xs; }, function (xs) { t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); } ); }); }); tape-4.6.3/test/undef.js000066400000000000000000000015741301475141700151050ustar00rootroot00000000000000var 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: |-\n' + ' { beep: undefined }\n' + ' actual: |-\n' + ' {}\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 }); }); });