Socket
Socket
Sign inDemoInstall

tape

Package Overview
Dependencies
Maintainers
4
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tape - npm Package Compare versions

Comparing version 4.16.0 to 4.16.1

CHANGELOG.md

52

example/array.js

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(5);
t.plan(5);
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
});

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(5);
t.plan(5);
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]);
}
);
});

@@ -7,48 +7,48 @@ 'use strict';

test('nested array test', function (t) {
t.plan(5);
t.plan(5);
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
t.test('inside test', function (q) {
q.plan(2);
q.ok(true);
t.test('inside test', function (q) {
q.plan(2);
q.ok(true);
setTimeout(function () {
q.equal(3, 4);
}, 3000);
});
setTimeout(function () {
q.equal(3, 4);
}, 3000);
});
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
});
test('another', function (t) {
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
});

@@ -7,48 +7,48 @@ 'use strict';

test('nested array test', function (t) {
t.plan(5);
t.plan(5);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
t.test('inside test', function (q) {
q.plan(2);
q.ok(true, 'inside ok');
t.test('inside test', function (q) {
q.plan(2);
q.ok(true, 'inside ok');
setTimeout(function () {
q.ok(true, 'inside delayed');
}, 3000);
});
setTimeout(function () {
q.ok(true, 'inside delayed');
}, 3000);
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[ 1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});
test('another', function (t) {
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 100);
});

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(8);
t.plan(8);
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [ 1, 2, [ 3, 4 ] ];
var ys = [ 5, 6 ];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
var arrays = [
[ 3, 4 ],
[ 1, 2, [ 3, 4 ] ],
[ 5, 6 ],
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
}
);
});

@@ -7,7 +7,7 @@ 'use strict';

test.createStream({ objectMode: true }).on('data', function (row) {
console.log(JSON.stringify(row));
console.log(JSON.stringify(row));
});
process.argv.slice(2).forEach(function (file) {
require(path.resolve(file));
require(path.resolve(file));
});

@@ -9,3 +9,3 @@ 'use strict';

process.argv.slice(2).forEach(function (file) {
require(path.resolve(file));
require(path.resolve(file));
});

@@ -5,4 +5,4 @@ 'use strict';

test(function (t) {
t.plan(1);
t.equal('beep', 'boop');
t.plan(1);
t.equal('beep', 'boop');
});

@@ -5,10 +5,10 @@ 'use strict';

test(function (t) {
t.plan(2);
t.equal(1 + 1, 2);
t.ok(true);
t.plan(2);
t.equal(1 + 1, 2);
t.ok(true);
});
test('wheee', function (t) {
t.ok(true);
t.end();
t.ok(true);
t.end();
});

@@ -6,7 +6,7 @@ 'use strict';

test('throw', function (t) {
t.plan(2);
t.plan(2);
setTimeout(function () {
throw new Error('doom');
}, 100);
setTimeout(function () {
throw new Error('doom');
}, 100);
});

@@ -6,10 +6,10 @@ 'use strict';

test('timing test', function (t) {
t.plan(2);
t.plan(2);
t.equal(typeof Date.now, 'function');
var start = new Date();
t.equal(typeof Date.now, 'function');
var start = new Date();
setTimeout(function () {
t.equal(new Date() - start, 100);
}, 100);
setTimeout(function () {
t.equal(new Date() - start, 100);
}, 100);
});

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(3);
t.plan(3);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([ xs, ys ]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});

@@ -6,16 +6,16 @@ 'use strict';

test('one', function (t) {
t.plan(2);
t.ok(true);
setTimeout(function () {
t.equal(1 + 3, 4);
}, 100);
t.plan(2);
t.ok(true);
setTimeout(function () {
t.equal(1 + 3, 4);
}, 100);
});
test('two', function (t) {
t.plan(3);
t.equal(5, 2 + 3);
setTimeout(function () {
t.equal('a'.charCodeAt(0), 97);
t.ok(true);
}, 50);
t.plan(3);
t.equal(5, 2 + 3);
setTimeout(function () {
t.equal('a'.charCodeAt(0), 97);
t.ok(true);
}, 50);
});

@@ -15,141 +15,144 @@ 'use strict';

module.exports = (function () {
var harness;
var lazyLoad = function () {
// eslint-disable-next-line no-invalid-this
return getHarness().apply(this, arguments);
};
var harness;
lazyLoad.only = function () {
return getHarness().only.apply(this, arguments);
};
function getHarness(opts) {
if (!opts) { opts = {}; }
opts.autoclose = !canEmitExit;
// this override is here since tests fail via nyc if createHarness is moved upwards
// eslint-disable-next-line no-use-before-define
if (!harness) { harness = createExitHarness(opts); }
return harness;
}
lazyLoad.createStream = function (opts) {
var options = opts || {};
if (!harness) {
var output = through();
getHarness({ stream: output, objectMode: options.objectMode });
return output;
}
return harness.createStream(options);
};
function lazyLoad() {
// eslint-disable-next-line no-invalid-this
return getHarness().apply(this, arguments);
}
lazyLoad.onFinish = function () {
return getHarness().onFinish.apply(this, arguments);
};
lazyLoad.only = function () {
return getHarness().only.apply(this, arguments);
};
lazyLoad.onFailure = function () {
return getHarness().onFailure.apply(this, arguments);
};
lazyLoad.createStream = function (opts) {
var options = opts || {};
if (!harness) {
var output = through();
getHarness({ stream: output, objectMode: options.objectMode });
return output;
}
return harness.createStream(options);
};
lazyLoad.getHarness = getHarness;
lazyLoad.onFinish = function () {
return getHarness().onFinish.apply(this, arguments);
};
return lazyLoad;
lazyLoad.onFailure = function () {
return getHarness().onFailure.apply(this, arguments);
};
function getHarness(opts) {
if (!opts) { opts = {}; }
opts.autoclose = !canEmitExit;
if (!harness) { harness = createExitHarness(opts); }
return harness;
}
lazyLoad.getHarness = getHarness;
return lazyLoad;
}());
function createExitHarness(conf) {
var config = conf || {};
var harness = createHarness({
autoclose: defined(config.autoclose, false),
noOnly: defined(conf.noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false))
});
function createHarness(conf_) {
var results = createResult();
if (!conf_ || conf_.autoclose !== false) {
results.once('done', function () { results.close(); });
}
var stream = harness.createStream({ objectMode: conf.objectMode });
var es = stream.pipe(conf.stream || createDefaultStream());
if (canEmitExit) {
// eslint-disable-next-line no-unused-vars
es.on('error', function (err) { harness._exitCode = 1; });
}
function test(name, conf, cb) {
var t = new Test(name, conf, cb);
test._tests.push(t);
var ended = false;
stream.on('end', function () { ended = true; });
(function inspectCode(st) {
st.on('test', function sub(st_) {
inspectCode(st_);
});
st.on('result', function (r) {
if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; }
});
}(t));
if (config.exit === false) { return harness; }
if (!canEmitExit || !canExit) { return harness; }
results.push(t);
return t;
}
test._results = results;
process.on('exit', function (code) {
// let the process exit cleanly.
if (code !== 0) {
return;
}
test._tests = [];
if (!ended) {
var only = harness._results._only;
for (var i = 0; i < harness._tests.length; i++) {
var t = harness._tests[i];
if (!only || t === only) {
t._exit();
}
}
}
harness.close();
process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit
});
test.createStream = function (opts) {
return results.createStream(opts);
};
return harness;
}
test.onFinish = function (cb) {
results.on('done', cb);
};
module.exports.createHarness = createHarness;
module.exports.Test = Test;
module.exports.test = module.exports; // tap compat
module.exports.test.skip = Test.skip;
test.onFailure = function (cb) {
results.on('fail', cb);
};
function createHarness(conf_) {
var results = createResult();
if (!conf_ || conf_.autoclose !== false) {
results.once('done', function () { results.close(); });
}
var only = false;
test.only = function () {
if (only) { throw new Error('there can only be one only test'); }
if (conf_.noOnly) { throw new Error('`only` tests are prohibited'); }
only = true;
var t = test.apply(null, arguments);
results.only(t);
return t;
};
test._exitCode = 0;
var test = function (name, conf, cb) {
var t = new Test(name, conf, cb);
test._tests.push(t);
test.close = function () { results.close(); };
(function inspectCode(st) {
st.on('test', function sub(st_) {
inspectCode(st_);
});
st.on('result', function (r) {
if (!r.todo && !r.ok && typeof r !== 'string') { test._exitCode = 1; }
});
}(t));
return test;
}
results.push(t);
return t;
};
test._results = results;
function createExitHarness(conf) {
var config = conf || {};
var harness = createHarness({
autoclose: defined(config.autoclose, false),
noOnly: defined(conf.noOnly, defined(process.env.NODE_TAPE_NO_ONLY_TEST, false))
});
test._tests = [];
var stream = harness.createStream({ objectMode: conf.objectMode });
var es = stream.pipe(conf.stream || createDefaultStream());
if (canEmitExit) {
// eslint-disable-next-line no-unused-vars
es.on('error', function (err) { harness._exitCode = 1; });
}
test.createStream = function (opts) {
return results.createStream(opts);
};
var ended = false;
stream.on('end', function () { ended = true; });
test.onFinish = function (cb) {
results.on('done', cb);
};
if (config.exit === false) { return harness; }
if (!canEmitExit || !canExit) { return harness; }
test.onFailure = function (cb) {
results.on('fail', cb);
};
process.on('exit', function (code) {
// let the process exit cleanly.
if (code !== 0) {
return;
}
var only = false;
test.only = function () {
if (only) { throw new Error('there can only be one only test'); }
if (conf_.noOnly) { throw new Error('`only` tests are prohibited'); }
only = true;
var t = test.apply(null, arguments);
results.only(t);
return t;
};
test._exitCode = 0;
if (!ended) {
var only = harness._results._only;
for (var i = 0; i < harness._tests.length; i++) {
var t = harness._tests[i];
if (!only || t === only) {
t._exit();
}
}
}
harness.close();
process.exit(code || harness._exitCode); // eslint-disable-line no-process-exit
});
test.close = function () { results.close(); };
return harness;
}
return test;
}
module.exports.createHarness = createHarness;
module.exports.Test = Test;
module.exports.test = module.exports; // tap compat
module.exports.test.skip = Test.skip;

@@ -7,35 +7,35 @@ 'use strict';

module.exports = function () {
var line = '';
var stream = through(write, flush);
return stream;
var line = '';
var stream = through(write, flush);
return stream;
function write(buf) {
for (var i = 0; i < buf.length; i++) {
var c = typeof buf === 'string'
? buf.charAt(i)
: String.fromCharCode(buf[i]);
if (c === '\n') {
flush();
} else {
line += c;
}
}
}
function write(buf) {
for (var i = 0; i < buf.length; i++) {
var c = typeof buf === 'string'
? buf.charAt(i)
: String.fromCharCode(buf[i]);
if (c === '\n') {
flush();
} else {
line += c;
}
}
}
function flush() {
if (fs.writeSync && (/^win/).test(process.platform)) {
try {
fs.writeSync(1, line + '\n');
} catch (e) {
stream.emit('error', e);
}
} else {
try {
console.log(line); // eslint-disable-line no-console
} catch (e) {
stream.emit('error', e);
}
}
line = '';
}
function flush() {
if (fs.writeSync && (/^win/).test(process.platform)) {
try {
fs.writeSync(1, line + '\n');
} catch (e) {
stream.emit('error', e);
}
} else {
try {
console.log(line); // eslint-disable-line no-console
} catch (e) {
stream.emit('error', e);
}
}
line = '';
}
};

@@ -14,213 +14,215 @@ 'use strict';

var nextTick = typeof setImmediate !== 'undefined' ? setImmediate : process.nextTick;
module.exports = Results;
inherits(Results, EventEmitter);
function coalesceWhiteSpaces(str) {
return String(str).replace(/\s+/g, ' ');
return String(str).replace(/\s+/g, ' ');
}
function invalidYaml(str) {
return $exec(yamlIndicators, str) !== null;
}
function encodeResult(res, count) {
var output = '';
output += (res.ok ? 'ok ' : 'not ok ') + count;
output += res.name ? ' ' + coalesceWhiteSpaces(res.name) : '';
if (res.skip) {
output += ' # SKIP' + (typeof res.skip === 'string' ? ' ' + coalesceWhiteSpaces(res.skip) : '');
} else if (res.todo) {
output += ' # TODO' + (typeof res.todo === 'string' ? ' ' + coalesceWhiteSpaces(res.todo) : '');
}
output += '\n';
if (res.ok) { return output; }
var outer = ' ';
var inner = outer + ' ';
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';
if (has(res, 'expected') || has(res, 'actual')) {
var ex = inspect(res.expected, { depth: res.objectPrintDepth });
var ac = inspect(res.actual, { depth: res.objectPrintDepth });
if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) {
output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n';
output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n';
} else {
output += inner + 'expected: ' + ex + '\n';
output += inner + 'actual: ' + ac + '\n';
}
}
if (res.at) {
output += inner + 'at: ' + res.at + '\n';
}
var actualStack = res.actual && (typeof res.actual === 'object' || typeof res.actual === 'function') ? res.actual.stack : undefined;
var errorStack = res.error && res.error.stack;
var stack = defined(actualStack, errorStack);
if (stack) {
var lines = String(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 && results._only === t) {
return t;
}
} while (results.tests.length !== 0);
return void undefined;
}
function Results() {
if (!(this instanceof Results)) { return new Results(); }
this.count = 0;
this.fail = 0;
this.pass = 0;
this.todo = 0;
this._stream = through();
this.tests = [];
this._only = null;
this._isRunning = false;
if (!(this instanceof Results)) { return new Results(); }
this.count = 0;
this.fail = 0;
this.pass = 0;
this.todo = 0;
this._stream = through();
this.tests = [];
this._only = null;
this._isRunning = false;
}
inherits(Results, EventEmitter);
Results.prototype.createStream = function (opts) {
if (!opts) { opts = {}; }
var self = this;
var output;
var testId = 0;
if (opts.objectMode) {
output = through();
self.on('_push', function ontest(t, extra) {
if (!extra) { extra = {}; }
var id = testId++;
t.once('prerun', function () {
var row = {
type: 'test',
name: t.name,
id: id,
skip: t._skip,
todo: t._todo
};
if (has(extra, 'parent')) {
row.parent = extra.parent;
}
output.queue(row);
});
t.on('test', function (st) {
ontest(st, { parent: id });
});
t.on('result', function (res) {
if (res && typeof res === 'object') {
res.test = id;
res.type = 'assert';
}
output.queue(res);
});
t.on('end', function () {
output.queue({ type: 'end', test: id });
});
});
self.on('done', function () { output.queue(null); });
} else {
output = resumer();
output.queue('TAP version 13\n');
self._stream.pipe(output);
}
if (!opts) { opts = {}; }
var self = this;
var output;
var testId = 0;
if (opts.objectMode) {
output = through();
self.on('_push', function ontest(t, extra) {
if (!extra) { extra = {}; }
var id = testId++;
t.once('prerun', function () {
var row = {
type: 'test',
name: t.name,
id: id,
skip: t._skip,
todo: t._todo
};
if (has(extra, 'parent')) {
row.parent = extra.parent;
}
output.queue(row);
});
t.on('test', function (st) {
ontest(st, { parent: id });
});
t.on('result', function (res) {
if (res && typeof res === 'object') {
res.test = id;
res.type = 'assert';
}
output.queue(res);
});
t.on('end', function () {
output.queue({ type: 'end', test: id });
});
});
self.on('done', function () { output.queue(null); });
} else {
output = resumer();
output.queue('TAP version 13\n');
self._stream.pipe(output);
}
if (!this._isRunning) {
this._isRunning = true;
nextTick(function next() {
var t;
while (t = getNextTest(self)) {
t.run();
if (!t.ended) {
t.once('end', function () { nextTick(next); });
return;
}
}
self.emit('done');
});
}
if (!this._isRunning) {
this._isRunning = true;
nextTick(function next() {
var t;
while (t = getNextTest(self)) {
t.run();
if (!t.ended) {
t.once('end', function () { nextTick(next); });
return;
}
}
self.emit('done');
});
}
return output;
return output;
};
Results.prototype.push = function (t) {
var self = this;
self.tests.push(t);
self._watch(t);
self.emit('_push', t);
var self = this;
self.tests.push(t);
self._watch(t);
self.emit('_push', t);
};
Results.prototype.only = function (t) {
this._only = t;
this._only = t;
};
Results.prototype._watch = function (t) {
var self = this;
var write = function (s) { self._stream.queue(s); };
t.once('prerun', function () {
var premsg = '';
if (t._skip) {
premsg = 'SKIP ';
} else if (t._todo) {
premsg = 'TODO ';
}
write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n');
});
var self = this;
function write(s) { self._stream.queue(s); }
t.once('prerun', function () {
var premsg = '';
if (t._skip) {
premsg = 'SKIP ';
} else if (t._todo) {
premsg = 'TODO ';
}
write('# ' + premsg + coalesceWhiteSpaces(t.name) + '\n');
});
t.on('result', function (res) {
if (typeof res === 'string') {
write('# ' + res + '\n');
return;
}
write(encodeResult(res, self.count + 1));
self.count++;
t.on('result', function (res) {
if (typeof res === 'string') {
write('# ' + res + '\n');
return;
}
write(encodeResult(res, self.count + 1));
self.count++;
if (res.ok || res.todo) {
self.pass++;
} else {
self.fail++;
self.emit('fail');
}
});
if (res.ok || res.todo) {
self.pass++;
} else {
self.fail++;
self.emit('fail');
}
});
t.on('test', function (st) { self._watch(st); });
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); };
var self = this;
if (self.closed) { self._stream.emit('error', new Error('ALREADY CLOSED')); }
self.closed = true;
function write(s) { self._stream.queue(s); }
write('\n1..' + self.count + '\n');
write('# tests ' + self.count + '\n');
write('# pass ' + (self.pass + self.todo) + '\n');
if (self.todo) {
write('# todo ' + self.todo + '\n');
} if (self.fail) {
write('# fail ' + self.fail + '\n');
} else {
write('\n# ok\n');
}
write('\n1..' + self.count + '\n');
write('# tests ' + self.count + '\n');
write('# pass ' + (self.pass + self.todo) + '\n');
if (self.todo) {
write('# todo ' + self.todo + '\n');
} if (self.fail) {
write('# fail ' + self.fail + '\n');
} else {
write('\n# ok\n');
}
self._stream.queue(null);
self._stream.queue(null);
};
function encodeResult(res, count) {
var output = '';
output += (res.ok ? 'ok ' : 'not ok ') + count;
output += res.name ? ' ' + coalesceWhiteSpaces(res.name) : '';
if (res.skip) {
output += ' # SKIP' + (typeof res.skip === 'string' ? ' ' + coalesceWhiteSpaces(res.skip) : '');
} else if (res.todo) {
output += ' # TODO' + (typeof res.todo === 'string' ? ' ' + coalesceWhiteSpaces(res.todo) : '');
}
output += '\n';
if (res.ok) { return output; }
var outer = ' ';
var inner = outer + ' ';
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';
if (has(res, 'expected') || has(res, 'actual')) {
var ex = inspect(res.expected, { depth: res.objectPrintDepth });
var ac = inspect(res.actual, { depth: res.objectPrintDepth });
if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) {
output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n';
output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n';
} else {
output += inner + 'expected: ' + ex + '\n';
output += inner + 'actual: ' + ac + '\n';
}
}
if (res.at) {
output += inner + 'at: ' + res.at + '\n';
}
var actualStack = res.actual && (typeof res.actual === 'object' || typeof res.actual === 'function') ? res.actual.stack : undefined;
var errorStack = res.error && res.error.stack;
var stack = defined(actualStack, errorStack);
if (stack) {
var lines = String(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 && results._only === t) {
return t;
}
} while (results.tests.length !== 0);
return void undefined;
}
function invalidYaml(str) {
return $exec(yamlIndicators, str) !== null;
}
module.exports = Results;

@@ -19,268 +19,266 @@ 'use strict';

module.exports = Test;
var nextTick = typeof setImmediate !== 'undefined'
? setImmediate
: process.nextTick;
? setImmediate
: process.nextTick;
var safeSetTimeout = setTimeout;
var safeClearTimeout = clearTimeout;
inherits(Test, EventEmitter);
// eslint-disable-next-line no-unused-vars
var getTestArgs = function (name_, opts_, cb_) {
var name = '(anonymous)';
var opts = {};
var cb;
function getTestArgs(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
};
};
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_);
}
if (!(this instanceof Test)) {
return new Test(name_, opts_, cb_);
}
var args = getTestArgs(name_, opts_, cb_);
var args = getTestArgs(name_, opts_, cb_);
this.readable = true;
this.name = args.name || '(anonymous)';
this.assertCount = 0;
this.pendingCount = 0;
this._skip = args.opts.skip || false;
this._todo = args.opts.todo || false;
this._timeout = args.opts.timeout;
this._plan = undefined;
this._cb = args.cb;
this._progeny = [];
this._teardown = [];
this._ok = true;
var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH;
if (args.opts.objectPrintDepth) {
this._objectPrintDepth = args.opts.objectPrintDepth;
} else if (depthEnvVar) {
if (toLowerCase(depthEnvVar) === 'infinity') {
this._objectPrintDepth = Infinity;
} else {
this._objectPrintDepth = depthEnvVar;
}
} else {
this._objectPrintDepth = 5;
}
this.readable = true;
this.name = args.name || '(anonymous)';
this.assertCount = 0;
this.pendingCount = 0;
this._skip = args.opts.skip || false;
this._todo = args.opts.todo || false;
this._timeout = args.opts.timeout;
this._plan = undefined;
this._cb = args.cb;
this._progeny = [];
this._teardown = [];
this._ok = true;
var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH;
if (args.opts.objectPrintDepth) {
this._objectPrintDepth = args.opts.objectPrintDepth;
} else if (depthEnvVar) {
if (toLowerCase(depthEnvVar) === 'infinity') {
this._objectPrintDepth = Infinity;
} else {
this._objectPrintDepth = depthEnvVar;
}
} else {
this._objectPrintDepth = 5;
}
for (var prop in this) {
this[prop] = (function bind(self, val) {
if (typeof val === 'function') {
return function bound() {
return val.apply(self, arguments);
};
}
return val;
}(this, this[prop]));
}
for (var prop in this) {
this[prop] = (function bind(self, val) {
if (typeof val === 'function') {
return function bound() {
return val.apply(self, arguments);
};
}
return val;
}(this, this[prop]));
}
}
inherits(Test, EventEmitter);
Test.prototype.run = function run() {
this.emit('prerun');
if (!this._cb || this._skip) {
this._end();
return;
}
if (this._timeout != null) {
this.timeoutAfter(this._timeout);
}
this._cb(this);
this.emit('run');
this.emit('prerun');
if (!this._cb || this._skip) {
this._end();
return;
}
if (this._timeout != null) {
this.timeoutAfter(this._timeout);
}
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++;
});
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();
});
}
if (!self._pendingAsserts()) {
nextTick(function () {
self._end();
});
}
nextTick(function () {
if (!self._plan && self.pendingCount == self._progeny.length) {
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*/, ''));
});
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);
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(self.name + ' timed out after ' + ms + 'ms');
self.end();
}, ms);
this.once('end', function () {
safeClearTimeout(timeout);
});
if (!ms) { throw new Error('timeoutAfter requires a timespan'); }
var self = this;
var timeout = safeSetTimeout(function () {
self.fail(self.name + ' timed out after ' + ms + 'ms');
self.end();
}, ms);
this.once('end', function () {
safeClearTimeout(timeout);
});
};
Test.prototype.end = function end(err) {
if (arguments.length >= 1 && !!err) {
this.ifError(err);
}
if (arguments.length >= 1 && !!err) {
this.ifError(err);
}
if (this.calledEnd) {
this.fail('.end() already called');
}
this.calledEnd = true;
this._end();
if (this.calledEnd) {
this.fail('.end() already called');
}
this.calledEnd = true;
this._end();
};
Test.prototype.teardown = function (fn) {
if (typeof fn !== 'function') {
this.fail('teardown: ' + inspect(fn) + ' is not a function');
} else {
this._teardown.push(fn);
}
if (typeof fn !== 'function') {
this.fail('teardown: ' + inspect(fn) + ' is not a function');
} else {
this._teardown.push(fn);
}
};
Test.prototype._end = function (err) {
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () { self._end(); });
t.run();
return;
}
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () { self._end(); });
t.run();
return;
}
function next(i) {
if (i === self._teardown.length) {
completeEnd();
return;
}
var fn = self._teardown[i];
var res;
try {
res = fn();
} catch (e) {
self.fail(e);
}
if (res && typeof res.then === 'function') {
res.then(function () {
next(++i);
}, function (_err) {
err = err || _err;
});
} else {
next(++i);
}
}
function completeEnd() {
if (!self.ended) { self.emit('end'); }
var pendingAsserts = self._pendingAsserts();
if (!self._planError && self._plan !== undefined && pendingAsserts) {
self._planError = true;
self.fail('plan != count', {
expected: self._plan,
actual: self.assertCount
});
}
self.ended = true;
}
if (this._teardown.length > 0) {
next(0);
} else {
completeEnd();
}
function next(i) {
if (i === self._teardown.length) {
completeEnd();
return;
}
var fn = self._teardown[i];
var res;
try {
res = fn();
} catch (e) {
self.fail(e);
}
if (res && typeof res.then === 'function') {
res.then(function () {
next(++i);
}, function (_err) {
err = err || _err;
});
} else {
next(++i);
}
}
function completeEnd() {
if (!self.ended) { self.emit('end'); }
var pendingAsserts = self._pendingAsserts();
if (!self._planError && self._plan !== undefined && pendingAsserts) {
self._planError = true;
self.fail('plan != count', {
expected: self._plan,
actual: self.assertCount
});
}
self.ended = true;
}
if (this._teardown.length > 0) {
next(0);
} else {
completeEnd();
}
};
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: ' + this.name, {
exiting: true
});
}
if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) {
this._planError = true;
this.fail('plan != count', {
expected: this._plan,
actual: this.assertCount,
exiting: true
});
} else if (!this.ended) {
this.fail('test exited without ending: ' + this.name, {
exiting: true
});
}
};
Test.prototype._pendingAsserts = function () {
if (this._plan === undefined) {
return 1;
}
return this._plan - (this._progeny.length + this.assertCount);
if (this._plan === undefined) {
return 1;
}
return this._plan - (this._progeny.length + this.assertCount);
};
Test.prototype._assert = function assert(ok, opts) {
var self = this;
var extra = opts.extra || {};
var self = this;
var extra = opts.extra || {};
ok = !!ok || !!extra.skip;
ok = !!ok || !!extra.skip;
var res = {
id: self.assertCount++,
ok: 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);
}
if (has(opts, 'expected') || has(extra, 'expected')) {
res.expected = defined(extra.expected, opts.expected);
}
this._ok = !!(this._ok && ok);
var res = {
id: self.assertCount++,
ok: 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);
}
if (has(opts, 'expected') || has(extra, 'expected')) {
res.expected = defined(extra.expected, opts.expected);
}
this._ok = !!(this._ok && ok);
if (!ok && !res.todo) {
res.error = defined(extra.error, opts.error, new Error(res.name));
}
if (!ok && !res.todo) {
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 = __dirname + path.sep;
if (!ok) {
var e = new Error('exception');
var err = (e.stack || '').split('\n');
var dir = __dirname + path.sep;
for (var i = 0; i < err.length; i++) {
/*
for (var i = 0; i < err.length; i++) {
/*
Stack trace lines may resemble one of the following. We need

@@ -320,83 +318,84 @@ to correctly extract a function name (if any) and path / line

*/
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/;
var lineWithTokens = err[i].replace(process.cwd(), '/$CWD').replace(__dirname, '/$TEST');
var m = re.exec(lineWithTokens);
var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:)]+:(\d+)(?::(\d+))?)\)?$/;
var lineWithTokens = err[i].replace(process.cwd(), '/$CWD').replace(__dirname, '/$TEST');
var m = re.exec(lineWithTokens);
if (!m) {
continue;
}
if (!m) {
continue;
}
var callDescription = m[1] || '<anonymous>';
var filePath = m[2].replace('/$CWD', process.cwd()).replace('/$TEST', __dirname);
var callDescription = m[1] || '<anonymous>';
var filePath = m[2].replace('/$CWD', process.cwd()).replace('/$TEST', __dirname);
if (filePath.slice(0, dir.length) === dir) {
continue;
}
if (filePath.slice(0, dir.length) === dir) {
continue;
}
// Function call description may not (just) be a function name. Try to extract function name by looking at first "word" only.
res.functionName = callDescription.split(/\s+/)[0];
res.file = filePath;
res.line = Number(m[3]);
if (m[4]) { res.column = Number(m[4]); }
// 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 = callDescription + ' (' + filePath + ')';
break;
}
}
res.at = callDescription + ' (' + filePath + ')';
break;
}
}
self.emit('result', res);
self.emit('result', res);
var pendingAsserts = self._pendingAsserts();
if (!pendingAsserts) {
if (extra.exiting) {
self._end();
} else {
nextTick(function () {
self._end();
});
}
}
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
});
}
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
});
this._assert(false, {
message: msg,
operator: 'fail',
extra: extra
});
};
Test.prototype.pass = function (msg, extra) {
this._assert(true, {
message: msg,
operator: 'pass',
extra: 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
});
this._assert(true, {
message: msg,
operator: 'skip',
skip: true,
extra: extra
});
};
// eslint-disable-next-line func-style
var tapeAssert = function assert(value, msg, extra) {
this._assert(value, {
message: defined(msg, 'should be truthy'),
operator: 'ok',
expected: true,
actual: value,
extra: extra
});
this._assert(value, {
message: defined(msg, 'should be truthy'),
operator: 'ok',
expected: true,
actual: value,
extra: extra
});
};

@@ -409,9 +408,9 @@ Test.prototype.ok

function notOK(value, msg, extra) {
this._assert(!value, {
message: defined(msg, 'should be falsy'),
operator: 'notOk',
expected: false,
actual: value,
extra: extra
});
this._assert(!value, {
message: defined(msg, 'should be falsy'),
operator: 'notOk',
expected: false,
actual: value,
extra: extra
});
}

@@ -424,8 +423,8 @@ Test.prototype.notOk

function error(err, msg, extra) {
this._assert(!err, {
message: defined(msg, String(err)),
operator: 'error',
actual: err,
extra: extra
});
this._assert(!err, {
message: defined(msg, String(err)),
operator: 'error',
actual: err,
extra: extra
});
}

@@ -439,9 +438,9 @@ Test.prototype.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
});
this._assert(a === b, {
message: defined(msg, 'should be equal'),
operator: 'equal',
actual: a,
expected: b,
extra: extra
});
}

@@ -457,9 +456,9 @@ Test.prototype.equal

function notEqual(a, b, msg, extra) {
this._assert(a !== b, {
message: defined(msg, 'should not be equal'),
operator: 'notEqual',
actual: a,
expected: b,
extra: extra
});
this._assert(a !== b, {
message: defined(msg, 'should not be equal'),
operator: 'notEqual',
actual: a,
expected: b,
extra: extra
});
}

@@ -478,9 +477,9 @@ Test.prototype.notEqual

function tapeDeepEqual(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
});
this._assert(deepEqual(a, b, { strict: true }), {
message: defined(msg, 'should be equivalent'),
operator: 'deepEqual',
actual: a,
expected: b,
extra: extra
});
}

@@ -494,9 +493,9 @@ Test.prototype.deepEqual

function deepLooseEqual(a, b, msg, extra) {
this._assert(deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
operator: 'deepLooseEqual',
actual: a,
expected: b,
extra: extra
});
this._assert(deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
operator: 'deepLooseEqual',
actual: a,
expected: b,
extra: extra
});
}

@@ -509,9 +508,9 @@ Test.prototype.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,
extra: extra
});
this._assert(!deepEqual(a, b, { strict: true }), {
message: defined(msg, 'should not be equivalent'),
operator: 'notDeepEqual',
actual: a,
expected: b,
extra: extra
});
}

@@ -530,9 +529,9 @@ Test.prototype.notDeepEqual

function notDeepLooseEqual(a, b, msg, extra) {
this._assert(!deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
operator: 'notDeepLooseEqual',
actual: a,
expected: b,
extra: extra
});
this._assert(!deepEqual(a, b), {
message: defined(msg, 'should be equivalent'),
operator: 'notDeepLooseEqual',
actual: a,
expected: b,
extra: extra
});
}

@@ -545,126 +544,126 @@ Test.prototype.notDeepLooseEqual

Test.prototype['throws'] = function (fn, expected, msg, extra) {
if (typeof expected === 'string') {
msg = expected;
expected = undefined;
}
if (typeof expected === 'string') {
msg = expected;
expected = undefined;
}
var caught;
var caught;
try {
fn();
} catch (err) {
caught = { error: err };
if (Object(err) === err && (!isEnumerable(err, 'message') || !has(err, 'message'))) {
var message = err.message;
delete err.message;
err.message = message;
}
}
try {
fn();
} catch (err) {
caught = { error: err };
if (Object(err) === err && (!isEnumerable(err, 'message') || !has(err, 'message'))) {
var message = err.message;
delete err.message;
err.message = message;
}
}
var passed = caught;
var passed = caught;
if (isRegExp(expected)) {
passed = $exec(expected, caught && caught.error) !== null;
expected = String(expected);
}
if (isRegExp(expected)) {
passed = $exec(expected, caught && caught.error) !== null;
expected = String(expected);
}
if (typeof expected === 'function' && caught) {
passed = caught.error instanceof expected;
}
if (typeof expected === 'function' && caught) {
passed = caught.error instanceof expected;
}
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
});
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;
try {
fn();
} catch (err) {
caught = { error: err };
}
this._assert(!caught, {
message: defined(msg, 'should not throw'),
operator: 'throws',
actual: caught && caught.error,
expected: expected,
error: caught && caught.error,
extra: extra
});
if (typeof expected === 'string') {
msg = expected;
expected = undefined;
}
var caught;
try {
fn();
} catch (err) {
caught = { error: err };
}
this._assert(!caught, {
message: defined(msg, 'should not throw'),
operator: 'throws',
actual: caught && caught.error,
expected: expected,
error: caught && caught.error,
extra: extra
});
};
Test.prototype.match = function match(string, regexp, msg, extra) {
if (!isRegExp(regexp)) {
this._assert(false, {
message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'),
operator: 'match',
actual: objectToString(regexp),
expected: '[object RegExp]',
extra: extra
});
} else if (typeof string !== 'string') {
this._assert(false, {
message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'),
operator: 'match',
actual: string === null ? null : typeof string,
expected: 'string',
extra: extra
});
} else {
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(matches, {
message: message,
operator: 'match',
actual: string,
expected: regexp,
extra: extra
});
}
if (!isRegExp(regexp)) {
this._assert(false, {
message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'),
operator: 'match',
actual: objectToString(regexp),
expected: '[object RegExp]',
extra: extra
});
} else if (typeof string !== 'string') {
this._assert(false, {
message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'),
operator: 'match',
actual: string === null ? null : typeof string,
expected: 'string',
extra: extra
});
} else {
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(matches, {
message: message,
operator: 'match',
actual: string,
expected: regexp,
extra: extra
});
}
};
Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra) {
if (!isRegExp(regexp)) {
this._assert(false, {
message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'),
operator: 'doesNotMatch',
actual: objectToString(regexp),
expected: '[object RegExp]',
extra: extra
});
} else if (typeof string !== 'string') {
this._assert(false, {
message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'),
operator: 'doesNotMatch',
actual: string === null ? null : typeof string,
expected: 'string',
extra: extra
});
} else {
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(!matches, {
message: message,
operator: 'doesNotMatch',
actual: string,
expected: regexp,
extra: extra
});
}
if (!isRegExp(regexp)) {
this._assert(false, {
message: defined(msg, 'The "regexp" argument must be an instance of RegExp. Received type ' + typeof regexp + ' (' + inspect(regexp) + ')'),
operator: 'doesNotMatch',
actual: objectToString(regexp),
expected: '[object RegExp]',
extra: extra
});
} else if (typeof string !== 'string') {
this._assert(false, {
message: defined(msg, 'The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')'),
operator: 'doesNotMatch',
actual: string === null ? null : typeof string,
expected: 'string',
extra: extra
});
} else {
var matches = $exec(regexp, string) !== null;
var message = defined(
msg,
'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(!matches, {
message: message,
operator: 'doesNotMatch',
actual: string,
expected: regexp,
extra: extra
});
}
};

@@ -674,7 +673,9 @@

Test.skip = function (name_, _opts, _cb) {
var args = getTestArgs.apply(null, arguments);
args.opts.skip = true;
return new Test(args.name, args.opts, args.cb);
var args = getTestArgs.apply(null, arguments);
args.opts.skip = true;
return new Test(args.name, args.opts, args.cb);
};
module.exports = Test;
// vim: set softtabstop=4 shiftwidth=4:
{
"name": "tape",
"version": "4.16.0",
"version": "4.16.1",
"description": "tap-producing test harness for node and browsers",

@@ -35,2 +35,3 @@ "main": "index.js",

"aud": "^2.0.0",
"auto-changelog": "^2.4.0",
"concat-stream": "^1.6.2",

@@ -44,2 +45,3 @@ "eclint": "^2.8.1",

"npm-run-posix-or-windows": "^2.0.2",
"npmignore": "^0.3.0",
"safe-publish-latest": "^2.0.0",

@@ -50,2 +52,5 @@ "tap": "^8.0.1",

"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"",
"prepublishOnly": "safe-publish-latest",

@@ -78,5 +83,5 @@ "prepublish": "!(type not-in-publish) || not-in-publish || npm run prepublishOnly",

"type": "git",
"url": "git://github.com/substack/tape.git"
"url": "git://github.com/ljharb/tape.git"
},
"homepage": "https://github.com/substack/tape",
"homepage": "https://github.com/ljharb/tape",
"keywords": [

@@ -89,8 +94,20 @@ "tap",

],
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
"author": "Jordan Harband <ljharb@gmail.com>",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT"
"license": "MIT",
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}

@@ -6,9 +6,9 @@ 'use strict';

test('parent', function (t) {
t.pass('parent');
setTimeout(function () {
t.test('child', function (st) {
st.pass('child');
st.end();
});
}, 100);
t.pass('parent');
setTimeout(function () {
t.test('child', function (st) {
st.pass('child');
st.end();
});
}, 100);
});

@@ -11,37 +11,37 @@ 'use strict';

tap.test('inside anonymous functions', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
var tc = function (rows) {
var body = stripFullStack(rows.toString('utf8'));
var test = tape.createHarness();
var tc = function (rows) {
var body = stripFullStack(rows.toString('utf8'));
tt.same(body, [
'TAP version 13',
'# wrapped test failure',
'not ok 1 fail',
' ---',
' operator: fail',
' at: <anonymous> ($TEST/anonymous-fn.js:$LINE:$COL)',
' stack: |-',
' Error: fail',
' [... stack stripped ...]',
' at $TEST/anonymous-fn.js:$LINE:$COL',
' at Test.<anonymous> ($TEST/anonymous-fn/test-wrapper.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
tt.same(body, [
'TAP version 13',
'# wrapped test failure',
'not ok 1 fail',
' ---',
' operator: fail',
' at: <anonymous> ($TEST/anonymous-fn.js:$LINE:$COL)',
' stack: |-',
' Error: fail',
' [... stack stripped ...]',
' at $TEST/anonymous-fn.js:$LINE:$COL',
' at Test.<anonymous> ($TEST/anonymous-fn/test-wrapper.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('wrapped test failure', testWrapper(function (t) {
t.fail('fail');
t.end();
}));
test('wrapped test failure', testWrapper(function (t) {
t.fail('fail');
t.end();
}));
});
'use strict';
// Example of wrapper function that would invoke tape
module.exports = function (testCase) {
return function (t) {
setUp();
testCase(t);
tearDown();
};
};
function setUp() {
// ... example ...
// ... example ...
}
function tearDown() {
// ... example ...
// ... example ...
}
// Example of wrapper function that would invoke tape
module.exports = function (testCase) {
return function (t) {
setUp();
testCase(t);
tearDown();
};
};

@@ -9,56 +9,56 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
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.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);
test('array', function (t) {
t.plan(5);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 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]]);
}
);
});
});

@@ -6,8 +6,8 @@ 'use strict';

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();
});

@@ -6,7 +6,7 @@ 'use strict';

test(function (t) {
t.plan(4);
t.ok(true);
t.equal(3, 1 + 2);
t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]);
t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]);
t.plan(4);
t.ok(true);
t.equal(3, 1 + 2);
t.deepEqual([1, 2, [3, 4]], [1, 2, [3, 4]]);
t.notDeepEqual([1, 2, [3, 4, 5]], [1, 2, [3, 4]]);
});

@@ -8,13 +8,13 @@ 'use strict';

test('parent', function (t) {
t.test('child', function (st) {
childRan = true;
st.pass('child ran');
st.end();
});
t.end();
t.test('child', function (st) {
childRan = true;
st.pass('child ran');
st.end();
});
t.end();
});
test('uncle', function (t) {
t.ok(childRan, 'Child should run before next top-level test');
t.end();
t.ok(childRan, 'Child should run before next top-level test');
t.end();
});

@@ -26,33 +26,33 @@

test('grandparent', function (t) {
t.ok(!grandParentRan, 'grand parent ran twice');
grandParentRan = true;
t.test('parent', function (st) {
st.ok(!parentRan, 'parent ran twice');
parentRan = true;
st.test('grandchild', function (s2t) {
s2t.ok(!grandChildRan, 'grand child ran twice');
grandChildRan = true;
s2t.pass('grand child ran');
s2t.end();
});
st.pass('parent ran');
st.end();
});
t.test('other parent', function (st) {
st.ok(parentRan, 'first parent runs before second parent');
st.ok(grandChildRan, 'grandchild runs before second parent');
st.end();
});
t.pass('grandparent ran');
t.end();
t.ok(!grandParentRan, 'grand parent ran twice');
grandParentRan = true;
t.test('parent', function (st) {
st.ok(!parentRan, 'parent ran twice');
parentRan = true;
st.test('grandchild', function (s2t) {
s2t.ok(!grandChildRan, 'grand child ran twice');
grandChildRan = true;
s2t.pass('grand child ran');
s2t.end();
});
st.pass('parent ran');
st.end();
});
t.test('other parent', function (st) {
st.ok(parentRan, 'first parent runs before second parent');
st.ok(grandChildRan, 'grandchild runs before second parent');
st.end();
});
t.pass('grandparent ran');
t.end();
});
test('second grandparent', function (t) {
t.ok(grandParentRan, 'grandparent ran');
t.ok(parentRan, 'parent ran');
t.ok(grandChildRan, 'grandchild ran');
t.pass('other grandparent ran');
t.end();
t.ok(grandParentRan, 'grandparent ran');
t.ok(parentRan, 'parent ran');
t.ok(grandChildRan, 'grandchild ran');
t.pass('other grandparent ran');
t.end();
});
// vim: set softtabstop=4 shiftwidth=4:

@@ -10,38 +10,38 @@ 'use strict';

tap.test('circular test', function (assert) {
var test = tape.createHarness({ exit: false });
assert.plan(1);
var test = tape.createHarness({ exit: false });
assert.plan(1);
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# circular',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' {}',
' actual: |-',
' { circular: [Circular] }',
' at: Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# circular',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' {}',
' actual: |-',
' { circular: [Circular] }',
' at: Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
test('circular', function (t) {
t.plan(1);
var circular = {};
circular.circular = circular;
t.equal(circular, {});
});
test('circular', function (t) {
t.plan(1);
var circular = {};
circular.circular = circular;
t.equal(circular, {});
});
});

@@ -10,23 +10,23 @@ 'use strict';

tap.test('no comment', function (assert) {
assert.plan(1);
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 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();
});
var test = tape.createHarness();
test.createStream().pipe(concat(verify));
test('no comment', function (t) {
t.end();
});
});

@@ -36,15 +36,15 @@

tap.test('missing argument', function (assert) {
assert.plan(1);
var test = tape.createHarness();
test.createStream();
test('missing argument', function (t) {
try {
t.comment();
t.end();
} catch (err) {
assert.equal(err.constructor, TypeError);
} finally {
assert.end();
}
});
assert.plan(1);
var test = tape.createHarness();
test.createStream();
test('missing argument', function (t) {
try {
t.comment();
t.end();
} catch (err) {
assert.equal(err.constructor, TypeError);
} finally {
assert.end();
}
});
});

@@ -54,15 +54,15 @@

tap.test('null argument', function (assert) {
assert.plan(1);
var test = tape.createHarness();
test.createStream();
test('null argument', function (t) {
try {
t.comment(null);
t.end();
} catch (err) {
assert.equal(err.constructor, TypeError);
} finally {
assert.end();
}
});
assert.plan(1);
var test = tape.createHarness();
test.createStream();
test('null argument', function (t) {
try {
t.comment(null);
t.end();
} catch (err) {
assert.equal(err.constructor, TypeError);
} finally {
assert.end();
}
});
});

@@ -72,31 +72,31 @@

tap.test('whitespace', function (assert) {
assert.plan(1);
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 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();
});
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();
});
});

@@ -106,91 +106,91 @@

tap.test('non-string types', function (assert) {
assert.plan(1);
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 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();
});
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);
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 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();
});
var test = tape.createHarness();
test.createStream().pipe(concat(verify));
test('multiline strings', function (t) {
t.comment([
'a',
'b'
].join('\n'));
t.comment([
'c',
'd'
].join('\r\n'));
t.end();
});
});
tap.test('comment with createStream/objectMode', function (assert) {
assert.plan(1);
assert.plan(1);
var test = tape.createHarness();
test.createStream({ objectMode: true }).on('data', function (row) {
if (typeof row === 'string') {
assert.equal(row, 'comment message');
}
});
test('t.comment', function (t) {
t.comment('comment message');
t.end();
});
var test = tape.createHarness();
test.createStream({ objectMode: true }).on('data', function (row) {
if (typeof row === 'string') {
assert.equal(row, 'comment message');
}
});
test('t.comment', function (t) {
t.comment('comment message');
t.end();
});
});

@@ -6,15 +6,17 @@ 'use strict';

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');
module.exports.getDiag = function (body, includeStack) {
var yamlStart = body.indexOf(' ---');
var yamlEnd = body.indexOf(' ...\n');
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
return line.slice(2);
}).join('\n');
// The stack trace and at variable will vary depending on where the code
// is run, so just strip it out.
var withStack = yaml.safeLoad(diag);
delete withStack.stack;
delete withStack.at;
return withStack;
// The stack trace and at variable will vary depending on where the code
// is run, so just strip it out.
var withStack = yaml.safeLoad(diag);
if (!includeStack) {
delete withStack.stack;
}
delete withStack.at;
return withStack;
};

@@ -39,43 +41,43 @@

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(/, <anonymous>:\$LINE:\$COL\)$/, ')');
return withoutNestedLineNumbers;
var withoutTestDir = line.replace(__dirname, '$TEST');
var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE');
var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/');
var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL');
var withoutNestedLineNumbers = withoutLineNumbers.replace(/, <anonymous>:\$LINE:\$COL\)$/, ')');
return withoutNestedLineNumbers;
};
module.exports.stripFullStack = function (output) {
var stripped = ' [... stack stripped ...]';
var withDuplicates = output.split(/\r?\n/g).map(stripChangingData).map(function (line) {
var m = line.match(/[ ]{8}at .*\((.*)\)/);
var stripped = ' [... stack stripped ...]';
var withDuplicates = output.split(/\r?\n/g).map(stripChangingData).map(function (line) {
var m = line.match(/[ ]{8}at .*\((.*)\)/);
if (m && m[1].slice(0, 5) !== '$TEST') {
return stripped;
}
return line;
});
if (m && m[1].slice(0, 5) !== '$TEST') {
return stripped;
}
return line;
});
var withoutInternals = withDuplicates.filter(function (line) {
return !line.match(/ \(node:[^)]+\)$/);
});
var withoutInternals = withDuplicates.filter(function (line) {
return !line.match(/ \(node:[^)]+\)$/);
});
var deduped = withoutInternals.filter(function (line, ix) {
var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
return !hasPrior;
});
var deduped = withoutInternals.filter(function (line, ix) {
var hasPrior = line === stripped && withDuplicates[ix - 1] === stripped;
return !hasPrior;
});
return deduped.join('\n').replace(
// Handle stack trace variation in Node v0.8
/at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g,
'at$1 Test.<anonymous>'
).replace(
// Handle stack trace variation in Node v0.8
/at(:?) (Test\.)?tap\.test\.test\.skip/g,
'at$1 $2<anonymous>'
).replace(
// Handle stack trace variation in Node v0.8
/(\[\.\.\. stack stripped \.\.\.\]\r?\n *at) <anonymous> \(([^)]+)\)/g,
'$1 $2'
).split(/\r?\n/g);
return deduped.join('\n').replace(
// Handle stack trace variation in Node v0.8
/at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g,
'at$1 Test.<anonymous>'
).replace(
// Handle stack trace variation in Node v0.8
/at(:?) (Test\.)?tap\.test\.test\.skip/g,
'at$1 $2<anonymous>'
).replace(
// Handle stack trace variation in Node v0.8
/(\[\.\.\. stack stripped \.\.\.\]\r?\n *at) <anonymous> \(([^)]+)\)/g,
'$1 $2'
).split(/\r?\n/g);
};

@@ -6,28 +6,28 @@ 'use strict';

tape.test('createMultipleStreams', function (tt) {
tt.plan(2);
tt.plan(2);
var th = tape.createHarness();
th.createStream();
th.createStream();
var th = tape.createHarness();
th.createStream();
th.createStream();
var testOneComplete = false;
var testOneComplete = false;
th('test one', function (tht) {
tht.plan(1);
setTimeout(function () {
tht.pass();
testOneComplete = true;
}, 100);
});
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('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");
});
th.onFinish(function () {
tt.equal(th._results.count, 2, 'harness test ran');
tt.equal(th._results.fail, 0, "harness test didn't fail");
});
});

@@ -13,182 +13,182 @@ 'use strict';

tap.test('deep equal failure', function (assert) {
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { b: 2 }',
' actual: |-',
' { a: 1 }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { b: 2 }',
' actual: |-',
' { a: 1 }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ b: 2 }',
actual: '{ a: 1 }'
});
}));
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ b: 2 }',
actual: '{ a: 1 }'
});
}));
parser.once('assert', function (data) {
delete data.diag.stack;
delete data.diag.at;
assert.deepEqual(data, {
ok: false,
id: 1,
name: 'should be equal',
diag: {
operator: 'equal',
expected: '{ b: 2 }',
actual: '{ a: 1 }'
}
});
});
parser.once('assert', function (data) {
delete data.diag.stack;
delete data.diag.at;
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 });
});
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);
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.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
});
}));
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) {
delete data.diag.stack;
delete data.diag.at;
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 } } } } } }'
}
});
});
parser.once('assert', function (data) {
delete data.diag.stack;
delete data.diag.at;
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 } } } } } });
});
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);
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.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
});
}));
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) {
delete data.diag.stack;
delete data.diag.at;
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] } } } } }'
}
});
});
parser.once('assert', function (data) {
delete data.diag.stack;
delete data.diag.at;
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 } } } } } });
});
test('deep equal', function (t) {
t.plan(1);
t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } });
});
});

@@ -6,15 +6,15 @@ 'use strict';

test('deep strict equal', function (t) {
t.notDeepEqual(
[{ a: '3' }],
[{ a: 3 }]
);
t.end();
t.notDeepEqual(
[{ a: '3' }],
[{ a: 3 }]
);
t.end();
});
test('deep loose equal', function (t) {
t.deepLooseEqual(
[{ a: '3' }],
[{ a: 3 }]
);
t.end();
t.deepLooseEqual(
[{ a: '3' }],
[{ a: 3 }]
);
t.end();
});

@@ -11,42 +11,42 @@ 'use strict';

tap.test('default messages', function (t) {
t.plan(1);
t.plan(1);
var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]);
var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]);
ps.stdout.pipe(concat(function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# default messages',
'ok 1 should be truthy',
'ok 2 should be falsy',
'ok 3 should be equal',
'ok 4 should not be equal',
'ok 5 should be equivalent',
'ok 6 should be equivalent',
'ok 7 should be equal',
'ok 8 should not be equal',
'ok 9 should be equivalent',
'not ok 10 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: true',
' actual: true',
' at: Test.<anonymous> ($TEST/messages/defaults.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/messages/defaults.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 11 should be equivalent',
'ok 12 should be equivalent',
'',
'1..12',
'# tests 12',
'# pass 11',
'# fail 1',
'',
''
]);
}));
ps.stdout.pipe(concat(function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# default messages',
'ok 1 should be truthy',
'ok 2 should be falsy',
'ok 3 should be equal',
'ok 4 should not be equal',
'ok 5 should be equivalent',
'ok 6 should be equivalent',
'ok 7 should be equal',
'ok 8 should not be equal',
'ok 9 should be equivalent',
'not ok 10 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: true',
' actual: true',
' at: Test.<anonymous> ($TEST/messages/defaults.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/messages/defaults.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 11 should be equivalent',
'ok 12 should be equivalent',
'',
'1..12',
'# tests 12',
'# pass 11',
'# fail 1',
'',
''
]);
}));
});

@@ -11,53 +11,53 @@ 'use strict';

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) {
// The implementation of node's timer library has changed over time. We
// need to reverse engineer the error we expect to see.
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) {
// The implementation of node's timer library has changed over time. We
// need to reverse engineer the error we expect to see.
// This code is unfortunately by necessity highly coupled to node
// versions, and may require tweaking with future versions of the timers
// library.
function doEnd() { throw new Error(); }
var to = setTimeout(doEnd, 5000);
clearTimeout(to);
to._onTimeout = doEnd;
// This code is unfortunately by necessity highly coupled to node
// versions, and may require tweaking with future versions of the timers
// library.
function doEnd() { throw new Error(); }
var to = setTimeout(doEnd, 5000);
clearTimeout(to);
to._onTimeout = doEnd;
var stackExpected;
var atExpected;
try {
to._onTimeout();
} catch (e) {
stackExpected = stripFullStack(e.stack)[1];
stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js');
stackExpected = stackExpected.trim();
atExpected = stackExpected.replace(/^at\s+/, 'at: ');
}
var stackExpected;
var atExpected;
try {
to._onTimeout();
} catch (e) {
stackExpected = stripFullStack(e.stack)[1];
stackExpected = stackExpected.replace('double_end.js', 'double_end/double.js');
stackExpected = stackExpected.trim();
atExpected = stackExpected.replace(/^at\s+/, 'at: ');
}
t.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# double end',
'ok 1 should be equal',
'not ok 2 .end() already called',
' ---',
' operator: fail',
' ' + atExpected,
' stack: |-',
' Error: .end() already called',
' [... stack stripped ...]',
' ' + stackExpected,
' [... stack stripped ...]',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1',
'',
''
]);
}));
t.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# double end',
'ok 1 should be equal',
'not ok 2 .end() already called',
' ---',
' operator: fail',
' ' + atExpected,
' stack: |-',
' Error: .end() already called',
' [... stack stripped ...]',
' ' + stackExpected,
' [... stack stripped ...]',
' ...',
'',
'1..2',
'# tests 2',
'# pass 1',
'# fail 1',
'',
''
]);
}));
});

@@ -6,9 +6,9 @@ 'use strict';

test('double end', function (t) {
function doEnd() {
t.end();
}
function doEnd() {
t.end();
}
t.equal(1 + 1, 2);
t.end();
setTimeout(doEnd, 5);
t.equal(1 + 1, 2);
t.end();
setTimeout(doEnd, 5);
});

@@ -10,281 +10,281 @@ 'use strict';

tap.test('edge cases', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# zeroes',
'ok 1 0 equal to -0',
'ok 2 -0 equal to 0',
'not ok 3 0 notEqual to -0',
' ---',
' operator: notEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 -0 notEqual to 0',
' ---',
' operator: notEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 5 0 looseEqual to -0',
'ok 6 -0 looseEqual to 0',
'not ok 7 0 notLooseEqual to -0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notLooseEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 -0 notLooseEqual to 0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notLooseEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 9 0 strictEqual to -0',
'ok 10 -0 strictEqual to 0',
'not ok 11 0 notStrictEqual to -0',
' ---',
' operator: notEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notStrictEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 12 -0 notStrictEqual to 0',
' ---',
' operator: notEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notStrictEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 13 0 deepLooseEqual to -0',
'ok 14 -0 deepLooseEqual to 0',
'not ok 15 0 notDeepLooseEqual to -0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notDeepLooseEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 16 -0 notDeepLooseEqual to 0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notDeepLooseEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 17 0 deepEqual to -0',
' ---',
' operator: deepEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 deepEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 18 -0 deepEqual to 0',
' ---',
' operator: deepEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 deepEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 19 0 notDeepEqual to -0',
'ok 20 -0 notDeepEqual to 0',
'# NaNs',
'not ok 21 NaN equal to NaN',
' ---',
' operator: equal',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN equal to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 22 NaN notEqual to NaN',
'not ok 23 NaN looseEqual to NaN',
' ---',
' operator: deepLooseEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN looseEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 24 NaN notLooseEqual to NaN',
'not ok 25 NaN strictEqual to NaN',
' ---',
' operator: equal',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN strictEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 26 NaN notStrictEqual to NaN',
'not ok 27 NaN deepLooseEqual to NaN',
' ---',
' operator: deepLooseEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN deepLooseEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 28 NaN notDeepLooseEqual to NaN',
'ok 29 NaN deepEqual to NaN',
'not ok 30 NaN notDeepEqual to NaN',
' ---',
' operator: notDeepEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN notDeepEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..30',
'# tests 30',
'# pass 15',
'# fail 15',
''
]);
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# zeroes',
'ok 1 0 equal to -0',
'ok 2 -0 equal to 0',
'not ok 3 0 notEqual to -0',
' ---',
' operator: notEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 -0 notEqual to 0',
' ---',
' operator: notEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 5 0 looseEqual to -0',
'ok 6 -0 looseEqual to 0',
'not ok 7 0 notLooseEqual to -0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notLooseEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 -0 notLooseEqual to 0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notLooseEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 9 0 strictEqual to -0',
'ok 10 -0 strictEqual to 0',
'not ok 11 0 notStrictEqual to -0',
' ---',
' operator: notEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notStrictEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 12 -0 notStrictEqual to 0',
' ---',
' operator: notEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notStrictEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 13 0 deepLooseEqual to -0',
'ok 14 -0 deepLooseEqual to 0',
'not ok 15 0 notDeepLooseEqual to -0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 notDeepLooseEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 16 -0 notDeepLooseEqual to 0',
' ---',
' operator: notDeepLooseEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 notDeepLooseEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 17 0 deepEqual to -0',
' ---',
' operator: deepEqual',
' expected: |-',
' -0',
' actual: |-',
' 0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: 0 deepEqual to -0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 18 -0 deepEqual to 0',
' ---',
' operator: deepEqual',
' expected: |-',
' 0',
' actual: |-',
' -0',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: -0 deepEqual to 0',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 19 0 notDeepEqual to -0',
'ok 20 -0 notDeepEqual to 0',
'# NaNs',
'not ok 21 NaN equal to NaN',
' ---',
' operator: equal',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN equal to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 22 NaN notEqual to NaN',
'not ok 23 NaN looseEqual to NaN',
' ---',
' operator: deepLooseEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN looseEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 24 NaN notLooseEqual to NaN',
'not ok 25 NaN strictEqual to NaN',
' ---',
' operator: equal',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN strictEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 26 NaN notStrictEqual to NaN',
'not ok 27 NaN deepLooseEqual to NaN',
' ---',
' operator: deepLooseEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN deepLooseEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 28 NaN notDeepLooseEqual to NaN',
'ok 29 NaN deepEqual to NaN',
'not ok 30 NaN notDeepEqual to NaN',
' ---',
' operator: notDeepEqual',
' expected: NaN',
' actual: NaN',
' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' stack: |-',
' Error: NaN notDeepEqual to NaN',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..30',
'# tests 30',
'# pass 15',
'# fail 15',
''
]);
}));
test('zeroes', function (t) {
t.equal(0, -0, '0 equal to -0');
t.equal(-0, 0, '-0 equal to 0');
t.notEqual(0, -0, '0 notEqual to -0');
t.notEqual(-0, 0, '-0 notEqual to 0');
test('zeroes', function (t) {
t.equal(0, -0, '0 equal to -0');
t.equal(-0, 0, '-0 equal to 0');
t.notEqual(0, -0, '0 notEqual to -0');
t.notEqual(-0, 0, '-0 notEqual to 0');
t.looseEqual(0, -0, '0 looseEqual to -0');
t.looseEqual(-0, 0, '-0 looseEqual to 0');
t.notLooseEqual(0, -0, '0 notLooseEqual to -0');
t.notLooseEqual(-0, 0, '-0 notLooseEqual to 0');
t.looseEqual(0, -0, '0 looseEqual to -0');
t.looseEqual(-0, 0, '-0 looseEqual to 0');
t.notLooseEqual(0, -0, '0 notLooseEqual to -0');
t.notLooseEqual(-0, 0, '-0 notLooseEqual to 0');
t.strictEqual(0, -0, '0 strictEqual to -0');
t.strictEqual(-0, 0, '-0 strictEqual to 0');
t.notStrictEqual(0, -0, '0 notStrictEqual to -0');
t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0');
t.strictEqual(0, -0, '0 strictEqual to -0');
t.strictEqual(-0, 0, '-0 strictEqual to 0');
t.notStrictEqual(0, -0, '0 notStrictEqual to -0');
t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0');
t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0');
t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0');
t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0');
t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0');
t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0');
t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0');
t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0');
t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0');
t.deepEqual(0, -0, '0 deepEqual to -0');
t.deepEqual(-0, 0, '-0 deepEqual to 0');
t.notDeepEqual(0, -0, '0 notDeepEqual to -0');
t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0');
t.deepEqual(0, -0, '0 deepEqual to -0');
t.deepEqual(-0, 0, '-0 deepEqual to 0');
t.notDeepEqual(0, -0, '0 notDeepEqual to -0');
t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0');
t.end();
});
t.end();
});
test('NaNs', function (t) {
t.equal(NaN, NaN, 'NaN equal to NaN');
t.notEqual(NaN, NaN, 'NaN notEqual to NaN');
test('NaNs', function (t) {
t.equal(NaN, NaN, 'NaN equal to NaN');
t.notEqual(NaN, NaN, 'NaN notEqual to NaN');
t.looseEqual(NaN, NaN, 'NaN looseEqual to NaN');
t.notLooseEqual(NaN, NaN, 'NaN notLooseEqual to NaN');
t.looseEqual(NaN, NaN, 'NaN looseEqual to NaN');
t.notLooseEqual(NaN, NaN, 'NaN notLooseEqual to NaN');
t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN');
t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN');
t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN');
t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN');
t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN');
t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN');
t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN');
t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN');
t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN');
t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN');
t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN');
t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN');
t.end();
});
t.end();
});
});

@@ -8,54 +8,12 @@ 'use strict';

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);
cb(null, 'task' + name);
}
function fakeAsyncWrite(name, cb) {
cb(null);
cb(null);
}
function fakeAsyncWriteFail(name, cb) {
cb(new Error('fail'));
cb(new Error('fail'));
}

@@ -72,18 +30,60 @@

function getStackTrace(rows) {
var stacktrace = ' ---\n';
var extract = false;
forEach(rows.toString('utf8').split('\n'), function (row) {
if (!extract) {
if (row.indexOf('---') > -1) { // start of stack trace
extract = true;
}
} else if (row.indexOf('...') > -1) { // end of stack trace
extract = false;
stacktrace += ' ...';
} else {
stacktrace += row + '\n';
}
});
// console.log(stacktrace);
return stacktrace;
var stacktrace = ' ---\n';
var extract = false;
forEach(rows.toString('utf8').split('\n'), function (row) {
if (!extract) {
if (row.indexOf('---') > -1) { // start of stack trace
extract = true;
}
} else if (row.indexOf('...') > -1) { // end of stack trace
extract = false;
stacktrace += ' ...';
} else {
stacktrace += row + '\n';
}
});
// console.log(stacktrace);
return stacktrace;
}
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);
});
});
});

@@ -10,35 +10,35 @@ 'use strict';

tap.test('failures', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# error',
'not ok 1 Error: this is a message',
' ---',
' operator: error',
' expected: |-',
' undefined',
' actual: |-',
' ' + ('cause' in Error.prototype ? '{ [Error: this is a message] [cause]: undefined }' : '[Error: this is a message]'),
' at: Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
' stack: |-',
' Error: this is a message',
' at Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# error',
'not ok 1 Error: this is a message',
' ---',
' operator: error',
' expected: |-',
' undefined',
' actual: |-',
' [Error: this is a message]',
' at: Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
' stack: |-',
' Error: this is a message',
' at Test.<anonymous> ($TEST/error.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
test('error', function (t) {
t.plan(1);
t.error(new Error('this is a message'));
});
test('error', function (t) {
t.plan(1);
t.error(new Error('this is a message'));
});
});

@@ -11,242 +11,242 @@ 'use strict';

tap.test('exit ok', function (t) {
t.plan(2);
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 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);
});
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);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(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 ] ]',
' at: <anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at $TEST/exit/fail.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(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 ] ]',
' at: <anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at $TEST/exit/fail.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/exit/fail.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/exit/fail.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, 'exit', 'fail.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
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);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(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',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'',
'1..6',
'# tests 6',
'# pass 5',
'# fail 1',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(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',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'',
'1..6',
'# tests 6',
'# pass 5',
'# fail 1',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/too_few.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
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);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
'# second',
'ok 2 should be truthy',
'not ok 3 plan != count',
' ---',
' operator: fail',
' expected: 2',
' actual: 1',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
'# second',
'ok 2 should be truthy',
'not ok 3 plan != count',
' ---',
' operator: fail',
' expected: 2',
' actual: 1',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/second.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
});
tap.test('todo passing', function (t) {
t.plan(2);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# TODO todo pass',
'ok 1 should be truthy # TODO',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# TODO todo pass',
'ok 1 should be truthy # TODO',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});
tap.test('todo failing', function (t) {
t.plan(2);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# TODO todo fail',
'not ok 1 should be truthy # TODO',
' ---',
' operator: ok',
' expected: true',
' actual: false',
' at: Test.<anonymous> ($TEST/exit/todo_fail.js:$LINE:$COL)',
' ...',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# TODO todo fail',
'not ok 1 should be truthy # TODO',
' ---',
' operator: ok',
' expected: true',
' actual: false',
' at: Test.<anonymous> ($TEST/exit/todo_fail.js:$LINE:$COL)',
' ...',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/todo_fail.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});
tap.test('forgot to call t.end()', function (t) {
t.plan(2);
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
'# oops forgot end',
'ok 2 should be truthy',
'not ok 3 test exited without ending: oops forgot end',
' ---',
' operator: fail',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: test exited without ending: oops forgot end',
' [... stack stripped ...]',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1',
'',
''
]);
};
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
'# oops forgot end',
'ok 2 should be truthy',
'not ok 3 test exited without ending: oops forgot end',
' ---',
' operator: fail',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: test exited without ending: oops forgot end',
' [... stack stripped ...]',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1',
'',
''
]);
};
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
});

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(5);
t.plan(5);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
}
);
});

@@ -6,8 +6,8 @@ 'use strict';

test('first', function (t) {
t.ok(true);
t.end();
t.ok(true);
t.end();
});
test('oops forgot end', function (t) {
t.ok(true);
t.ok(true);
});

@@ -7,33 +7,33 @@ 'use strict';

test('array', function (t) {
t.comment('hi');
t.plan(5);
t.comment('hi');
t.plan(5);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});

@@ -6,9 +6,9 @@ 'use strict';

test('first', function (t) {
t.plan(1);
t.ok(true);
t.plan(1);
t.ok(true);
});
test('second', function (t) {
t.plan(2);
t.ok(true);
t.plan(2);
t.ok(true);
});

@@ -6,4 +6,4 @@ 'use strict';

test('todo fail', { todo: true }, function (t) {
t.plan(1);
t.ok(false);
t.plan(1);
t.ok(false);
});

@@ -6,4 +6,4 @@ 'use strict';

test('todo pass', { todo: true }, function (t) {
t.plan(1);
t.ok(true);
t.plan(1);
t.ok(true);
});

@@ -7,32 +7,32 @@ 'use strict';

test('array', function (t) {
t.plan(6);
t.plan(6);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});

@@ -8,8 +8,8 @@ 'use strict';

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();
});

@@ -11,71 +11,71 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be 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 ] ]',
' at: <anonymous> ($TEST/fail.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at $TEST/fail.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/fail.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1',
''
]);
};
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be 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 ] ]',
' at: <anonymous> ($TEST/fail.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at $TEST/fail.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/fail.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('array', function (t) {
t.plan(5);
test('array', function (t) {
t.plan(5);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
}
);
});
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
}
);
});
});

@@ -10,34 +10,34 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# fail',
'not ok 1 this should fail',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/has spaces.js:$LINE:$COL)',
' stack: |-',
' Error: this should fail',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/has spaces.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# fail',
'not ok 1 this should fail',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/has spaces.js:$LINE:$COL)',
' stack: |-',
' Error: this should fail',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/has spaces.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('fail', function (t) {
t.fail('this should fail');
t.end();
});
test('fail', function (t) {
t.fail('this should fail');
t.end();
});
});

@@ -13,111 +13,111 @@ 'use strict';

tap.test('Should pass with ignoring', { skip: process.platform === 'win32' }, function (tt) {
tt.plan(2);
tt.plan(2);
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# (anonymous)',
'ok 1 should be truthy',
'# (anonymous)',
'ok 2 test/stub1',
'# (anonymous)',
'ok 3 test/stub2',
'# (anonymous)',
'ok 4 test/sub/stub1',
'# (anonymous)',
'ok 5 test/sub/stub2',
'# (anonymous)',
'ok 6 Should print',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok',
'',
''
]);
};
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# (anonymous)',
'ok 1 should be truthy',
'# (anonymous)',
'ok 2 test/stub1',
'# (anonymous)',
'ok 3 test/stub2',
'# (anonymous)',
'ok 4 test/sub/stub1',
'# (anonymous)',
'ok 5 test/sub/stub2',
'# (anonymous)',
'ok 6 Should print',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok',
'',
''
]);
};
var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
tt.equal(code, 0); // code 0
});
var ps = spawn(tapeBin, ['**/*.js', '-i', '.ignore'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
tt.equal(code, 0); // code 0
});
});
tap.test('Should pass', { skip: process.platform === 'win32' }, function (tt) {
tt.plan(2);
tt.plan(2);
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# (anonymous)',
'not ok 1 Should not print',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)',
' stack: |-',
' Error: Should not print',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# (anonymous)',
'not ok 2 Should not print',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)',
' stack: |-',
' Error: Should not print',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# (anonymous)',
'ok 3 should be truthy',
'# (anonymous)',
'ok 4 test/stub1',
'# (anonymous)',
'ok 5 test/stub2',
'# (anonymous)',
'ok 6 test/sub/stub1',
'# (anonymous)',
'ok 7 test/sub/stub2',
'# (anonymous)',
'ok 8 Should print',
'',
'1..8',
'# tests 8',
'# pass 6',
'# fail 2',
'',
''
]);
};
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# (anonymous)',
'not ok 1 Should not print',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)',
' stack: |-',
' Error: Should not print',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/ignore/fake_node_modules/stub1.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# (anonymous)',
'not ok 2 Should not print',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)',
' stack: |-',
' Error: Should not print',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/ignore/fake_node_modules/stub2.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# (anonymous)',
'ok 3 should be truthy',
'# (anonymous)',
'ok 4 test/stub1',
'# (anonymous)',
'ok 5 test/stub2',
'# (anonymous)',
'ok 6 test/sub/stub1',
'# (anonymous)',
'ok 7 test/sub/stub2',
'# (anonymous)',
'ok 8 Should print',
'',
'1..8',
'# tests 8',
'# pass 6',
'# fail 2',
'',
''
]);
};
var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
tt.equal(code, 1);
});
var ps = spawn(tapeBin, ['**/*.js'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
tt.equal(code, 1);
});
});
tap.test('Should fail when ignore file does not exist', { skip: process.platform === 'win32' }, function (tt) {
tt.plan(3);
tt.plan(3);
var testStdout = function (rows) {
tt.same(rows.toString('utf8'), '');
};
var testStdout = function (rows) {
tt.same(rows.toString('utf8'), '');
};
var testStderr = function (rows) {
tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n')));
};
var testStderr = function (rows) {
tt.ok((/^ENOENT[:,] no such file or directory,? (?:open )?'\$TEST\/ignore\/.gitignore'\n$/m).test(stripFullStack(rows.toString('utf8')).join('\n')));
};
var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(testStdout));
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
tt.equal(code, 2);
});
var ps = spawn(tapeBin, ['**/*.js', '-i'], { cwd: path.join(__dirname, 'ignore') });
ps.stdout.pipe(concat(testStdout));
ps.stderr.pipe(concat(testStderr));
ps.on('exit', function (code) {
tt.equal(code, 2);
});
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.plan(1);
t.fail('Should not print');
t.plan(1);
t.fail('Should not print');
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.fail('Should not print');
t.end();
t.fail('Should not print');
t.end();
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.plan(1);
t.ok('Okay');
t.plan(1);
t.ok('Okay');
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.plan(1);
t.pass('test/stub1');
t.plan(1);
t.pass('test/stub1');
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.pass('test/stub2');
t.end();
t.pass('test/stub2');
t.end();
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.plan(1);
t.pass('test/sub/stub1');
t.plan(1);
t.pass('test/sub/stub1');
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.pass('test/sub/stub2');
t.end();
t.pass('test/sub/stub2');
t.end();
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test(function (t) {
t.pass('Should print');
t.end();
t.pass('Should print');
t.end();
});

@@ -6,6 +6,6 @@ 'use strict';

test('many tests', function (t) {
t.plan(100);
for (var i = 0; i < 100; i++) {
setTimeout(function () { t.pass(); }, Math.random() * 50);
}
t.plan(100);
for (var i = 0; i < 100; i++) {
setTimeout(function () { t.pass(); }, Math.random() * 50);
}
});

@@ -10,250 +10,250 @@ 'use strict';

tap.test('match', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# match',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input did not match the regular expression /abc/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" does not match /abc/',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" does not match /abc/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'',
'ok 8 "I will pass" matches /pass$/',
'',
'1..8',
'# tests 8',
'# pass 2',
'# fail 6',
''
]);
};
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# match',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input did not match the regular expression /abc/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" does not match /abc/',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" does not match /abc/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'',
'ok 8 "I will pass" matches /pass$/',
'',
'1..8',
'# tests 8',
'# pass 2',
'# fail 6',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('match', function (t) {
t.plan(8);
test('match', function (t) {
t.plan(8);
t.match(/abc/, 'string');
t.match(/abc/, 'string', 'regex arg must not be a string');
t.match(/abc/, 'string');
t.match(/abc/, 'string', 'regex arg must not be a string');
t.match({ abc: 123 }, /abc/);
t.match({ abc: 123 }, /abc/, 'string arg must not be an object');
t.match({ abc: 123 }, /abc/);
t.match({ abc: 123 }, /abc/, 'string arg must not be an object');
t.match('string', /abc/);
t.match('string', /abc/, '"string" does not match /abc/');
t.match('string', /abc/);
t.match('string', /abc/, '"string" does not match /abc/');
t.match('I will pass', /pass$/);
t.match('I will pass', /pass$/, '"I will pass" matches /pass$/');
t.match('I will pass', /pass$/);
t.match('I will pass', /pass$/, '"I will pass" matches /pass$/');
t.end();
});
t.end();
});
});
tap.test('doesNotMatch', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# doesNotMatch',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /string/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" should not match /string/',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" should not match /string/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 "I will pass" should not match /pass$/',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "I will pass" should not match /pass$/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'',
'ok 10 "I will fail" does not match /pass$/',
'',
'1..10',
'# tests 10',
'# pass 2',
'# fail 8',
''
]);
};
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# doesNotMatch',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /string/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" should not match /string/',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" should not match /string/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 "I will pass" should not match /pass$/',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "I will pass" should not match /pass$/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'',
'ok 10 "I will fail" does not match /pass$/',
'',
'1..10',
'# tests 10',
'# pass 2',
'# fail 8',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('doesNotMatch', function (t) {
t.plan(10);
test('doesNotMatch', function (t) {
t.plan(10);
t.doesNotMatch(/abc/, 'string');
t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string');
t.doesNotMatch(/abc/, 'string');
t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string');
t.doesNotMatch({ abc: 123 }, /abc/);
t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object');
t.doesNotMatch({ abc: 123 }, /abc/);
t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object');
t.doesNotMatch('string', /string/);
t.doesNotMatch('string', /string/, '"string" should not match /string/');
t.doesNotMatch('string', /string/);
t.doesNotMatch('string', /string/, '"string" should not match /string/');
t.doesNotMatch('I will pass', /pass$/);
t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/');
t.doesNotMatch('I will pass', /pass$/);
t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/');
t.doesNotMatch('I will fail', /pass$/);
t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/');
t.doesNotMatch('I will fail', /pass$/);
t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/');
t.end();
});
t.end();
});
});

@@ -11,3 +11,3 @@ 'use strict';

ps.stderr.on('data', function (buf) {
console.log('not ok ' + buf);
console.log('not ok ' + buf);
});

@@ -6,6 +6,6 @@ 'use strict';

for (var i = 0; i < 11; i++) {
test(function (t) {
t.ok(true, 'true is truthy');
t.end();
});
test(function (t) {
t.ok(true, 'true is truthy');
t.end();
});
}

@@ -6,21 +6,21 @@ 'use strict';

test('default messages', function (t) {
t.plan(12);
t.plan(12);
t.ok(true);
t.notOk(false);
t.ok(true);
t.notOk(false);
t.equal(true, true);
t.notEqual(true, false);
t.equal(true, true);
t.notEqual(true, false);
t.looseEqual(true, true);
t.notLooseEqual(true, false);
t.looseEqual(true, true);
t.notLooseEqual(true, false);
t.strictEqual(true, true);
t.notStrictEqual(true, false);
t.strictEqual(true, true);
t.notStrictEqual(true, false);
t.deepEqual(true, true);
t.notDeepEqual(true, true);
t.deepEqual(true, true);
t.notDeepEqual(true, true);
t.deepLooseEqual(true, true);
t.notDeepLooseEqual(true, false);
t.deepLooseEqual(true, true);
t.notDeepLooseEqual(true, false);
});

@@ -6,34 +6,34 @@ 'use strict';

test('Harness async test support', function (t) {
t.plan(3);
t.plan(3);
t.ok(true, 'sync child A');
t.ok(true, 'sync child A');
t.test('sync child B', function (tt) {
tt.plan(2);
t.test('sync child B', function (tt) {
tt.plan(2);
setTimeout(function () {
tt.test('async grandchild A', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
}, 50);
setTimeout(function () {
tt.test('async grandchild A', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
}, 50);
setTimeout(function () {
tt.test('async grandchild B', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
}, 100);
});
setTimeout(function () {
tt.test('async grandchild B', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
}, 100);
});
setTimeout(function () {
t.test('async child', function (tt) {
tt.plan(2);
tt.ok(true, 'sync grandchild in async child A');
tt.test('sync grandchild in async child B', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
});
}, 200);
setTimeout(function () {
t.test('async child', function (tt) {
tt.plan(2);
tt.ok(true, 'sync grandchild in async child A');
tt.test('sync grandchild in async child B', function (ttt) {
ttt.plan(1);
ttt.ok(true);
});
});
}, 200);
});

@@ -8,39 +8,39 @@ 'use strict';

tap.test('nested sync test without plan or end', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
var tc = function (rows) {
tt.same(rows.toString('utf8'), [
'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');
};
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.createStream().pipe(concat(tc));
test('nested without plan or end', function (t) {
t.test('first', function (q) {
setTimeout(function first() {
q.ok(true);
q.end();
}, 10);
});
t.test('second', function (q) {
setTimeout(function second() {
q.ok(true);
q.end();
}, 10);
});
});
test('nested without plan or end', function (t) {
t.test('first', function (q) {
setTimeout(function first() {
q.ok(true);
q.end();
}, 10);
});
t.test('second', function (q) {
setTimeout(function second() {
q.ok(true);
q.end();
}, 10);
});
});
});

@@ -9,78 +9,78 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
var tc = function (rows) {
tt.same(rows.toString('utf8'), [
'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');
};
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.createStream().pipe(concat(tc));
test('nested array test', function (t) {
t.plan(6);
test('nested array test', function (t) {
t.plan(6);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
t.test('inside test', function (q) {
q.plan(2);
q.ok(true);
t.test('inside test', function (q) {
q.plan(2);
q.ok(true);
setTimeout(function () {
q.ok(true);
}, 100);
});
setTimeout(function () {
q.ok(true);
}, 100);
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});
test('another', function (t) {
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 50);
});
test('another', function (t) {
t.plan(1);
setTimeout(function () {
t.ok(true);
}, 50);
});
});

@@ -6,16 +6,16 @@ 'use strict';

test(function (t) {
var i = 0;
t.test('setup', function (st) {
process.nextTick(function () {
st.equal(i, 0, 'called once');
i++;
st.end();
});
});
var i = 0;
t.test('setup', function (st) {
process.nextTick(function () {
st.equal(i, 0, 'called once');
i++;
st.end();
});
});
t.test('teardown', function (st) {
st.end();
});
t.test('teardown', function (st) {
st.end();
});
t.end();
t.end();
});

@@ -15,97 +15,97 @@ 'use strict';

tap.test(
'Should throw error when --no-only is passed via cli and there is a .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
'Should throw error when --no-only is passed via cli and there is a .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
);
tap.test(
'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
'Should throw error when NODE_TAPE_NO_ONLY_TEST is passed via envs and there is an .only test',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
exec(tapeBin + ' "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' }
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
exec(tapeBin + ' "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'true' }
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
);
tap.test(
'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
'Should override NODE_TAPE_NO_ONLY_TEST env if --no-only is passed from cli',
{ todo: expectedExitCodeFailure || expectedStackTraceBug ? 'Fails on these node versions' : false },
function (tt) {
tt.plan(3);
exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' }
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
exec(tapeBin + ' --no-only "**/*.js"', {
cwd: path.join(__dirname, 'no_only'),
env: { PATH: process.env.PATH, NODE_TAPE_NO_ONLY_TEST: 'false' }
}, function (err, stdout, stderr) {
tt.same(stdout.toString('utf8'), '');
tt.match(stripFullStack(stderr.toString('utf8')).join('\n'), /Error: `only` tests are prohibited\n/);
tt.equal(err.code, 1);
});
}
);
tap.test('Should run successfully if there is no only test', function (tt) {
tt.plan(3);
tt.plan(3);
exec(tapeBin + ' --no-only "**/test-a.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass',
'ok 1 should be truthy',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
tt.equal(err, null); // code 0
});
exec(tapeBin + ' --no-only "**/test-a.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass',
'ok 1 should be truthy',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
tt.equal(err, null); // code 0
});
});
tap.test('Should run successfully if there is an only test and no --no-only flag', function (tt) {
tt.plan(3);
tt.plan(3);
exec(tapeBin + ' "**/test-b.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass again',
'ok 1 should be truthy',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.equal(err, null); // code 0
});
exec(tapeBin + ' "**/test-b.js"', {
cwd: path.join(__dirname, 'no_only')
}, function (err, stdout, stderr) {
tt.same(stripFullStack(stdout.toString('utf8')), [
'TAP version 13',
'# should pass again',
'ok 1 should be truthy',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
'',
''
]);
tt.match(stderr.toString('utf8'), /^\s*(\(node:\d+\) ExperimentalWarning: The ESM module loader is experimental\.)?\s*$/);
tt.equal(err, null); // code 0
});
});

@@ -6,4 +6,4 @@ 'use strict';

tape.test('should pass', function (t) {
t.plan(1);
t.ok(1);
t.plan(1);
t.ok(1);
});

@@ -6,10 +6,10 @@ 'use strict';

tape.test('should pass', function (t) {
t.plan(1);
t.ok(1);
t.plan(1);
t.ok(1);
});
tape.test.only('should pass again', function (t) {
t.plan(1);
t.ok(1);
t.plan(1);
t.ok(1);
});

@@ -13,182 +13,182 @@ 'use strict';

tap.test('deep equal failure', function (assert) {
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { b: 2 }',
' actual: |-',
' { b: 2 }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { b: 2 }',
' actual: |-',
' { b: 2 }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'notDeepEqual',
expected: '{ b: 2 }',
actual: '{ b: 2 }'
});
}));
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 }'
}
});
});
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 });
});
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);
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.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'notDeepEqual',
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
});
}));
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 } } } } } }'
}
});
});
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 } } } } } });
});
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);
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.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not deep equal',
'not ok 1 should not be equivalent',
' ---',
' operator: notDeepEqual',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'notDeepEqual',
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
});
}));
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] } } } } }'
}
});
});
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 } } } } } });
});
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 } } } } } });
});
});

@@ -13,58 +13,58 @@ 'use strict';

tap.test('not equal failure', function (assert) {
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
var test = tape.createHarness({ exit: false });
var stream = test.createStream();
var parser = tapParser();
assert.plan(3);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not equal',
'not ok 1 should not be equal',
' ---',
' operator: notEqual',
' expected: 2',
' actual: 2',
' at: Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# not equal',
'not ok 1 should not be equal',
' ---',
' operator: notEqual',
' expected: 2',
' actual: 2',
' at: Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should not be equal',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
assert.deepEqual(getDiag(body), {
operator: 'notEqual',
expected: '2',
actual: '2'
});
}));
assert.deepEqual(getDiag(body), {
operator: 'notEqual',
expected: '2',
actual: '2'
});
}));
parser.once('assert', function (data) {
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'
}
});
});
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);
});
test('not equal', function (t) {
t.plan(1);
t.notEqual(2, 2);
});
});

@@ -10,176 +10,176 @@ 'use strict';

tap.test('numerics', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# numeric strings',
'not ok 1 number equal to string',
' ---',
' operator: equal',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number equal to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 string equal to number',
' ---',
' operator: equal',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string equal to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 3 number notEqual to string',
'ok 4 string notEqual to number',
'ok 5 number looseEqual to string',
'ok 6 string looseEqual to number',
'not ok 7 number notLooseEqual to string',
' ---',
' operator: notDeepLooseEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number notLooseEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 string notLooseEqual to number',
' ---',
' operator: notDeepLooseEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string notLooseEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 9 number strictEqual to string',
' ---',
' operator: equal',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number strictEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 10 string strictEqual to number',
' ---',
' operator: equal',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string strictEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 11 number notStrictEqual to string',
'ok 12 string notStrictEqual to number',
'ok 13 number deepLooseEqual to string',
'ok 14 string deepLooseEqual to number',
'not ok 15 number notDeepLooseEqual to string',
' ---',
' operator: notDeepLooseEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number notDeepLooseEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 16 string notDeepLooseEqual to number',
' ---',
' operator: notDeepLooseEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string notDeepLooseEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 17 number deepEqual to string',
' ---',
' operator: deepEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number deepEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 18 string deepEqual to number',
' ---',
' operator: deepEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string deepEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 19 number notDeepEqual to string',
'ok 20 string notDeepEqual to number',
'',
'1..20',
'# tests 20',
'# pass 10',
'# fail 10',
''
]);
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# numeric strings',
'not ok 1 number equal to string',
' ---',
' operator: equal',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number equal to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 string equal to number',
' ---',
' operator: equal',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string equal to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 3 number notEqual to string',
'ok 4 string notEqual to number',
'ok 5 number looseEqual to string',
'ok 6 string looseEqual to number',
'not ok 7 number notLooseEqual to string',
' ---',
' operator: notDeepLooseEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number notLooseEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 string notLooseEqual to number',
' ---',
' operator: notDeepLooseEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string notLooseEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 9 number strictEqual to string',
' ---',
' operator: equal',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number strictEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 10 string strictEqual to number',
' ---',
' operator: equal',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string strictEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 11 number notStrictEqual to string',
'ok 12 string notStrictEqual to number',
'ok 13 number deepLooseEqual to string',
'ok 14 string deepLooseEqual to number',
'not ok 15 number notDeepLooseEqual to string',
' ---',
' operator: notDeepLooseEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number notDeepLooseEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 16 string notDeepLooseEqual to number',
' ---',
' operator: notDeepLooseEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string notDeepLooseEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 17 number deepEqual to string',
' ---',
' operator: deepEqual',
' expected: \'3\'',
' actual: 3',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: number deepEqual to string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 18 string deepEqual to number',
' ---',
' operator: deepEqual',
' expected: 3',
' actual: \'3\'',
' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' stack: |-',
' Error: string deepEqual to number',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 19 number notDeepEqual to string',
'ok 20 string notDeepEqual to number',
'',
'1..20',
'# tests 20',
'# pass 10',
'# fail 10',
''
]);
}));
test('numeric strings', function (t) {
t.equal(3, '3', 'number equal to string');
t.equal('3', 3, 'string equal to number');
t.notEqual(3, '3', 'number notEqual to string');
t.notEqual('3', 3, 'string notEqual to number');
test('numeric strings', function (t) {
t.equal(3, '3', 'number equal to string');
t.equal('3', 3, 'string equal to number');
t.notEqual(3, '3', 'number notEqual to string');
t.notEqual('3', 3, 'string notEqual to number');
t.looseEqual(3, '3', 'number looseEqual to string');
t.looseEqual('3', 3, 'string looseEqual to number');
t.notLooseEqual(3, '3', 'number notLooseEqual to string');
t.notLooseEqual('3', 3, 'string notLooseEqual to number');
t.looseEqual(3, '3', 'number looseEqual to string');
t.looseEqual('3', 3, 'string looseEqual to number');
t.notLooseEqual(3, '3', 'number notLooseEqual to string');
t.notLooseEqual('3', 3, 'string notLooseEqual to number');
t.strictEqual(3, '3', 'number strictEqual to string');
t.strictEqual('3', 3, 'string strictEqual to number');
t.notStrictEqual(3, '3', 'number notStrictEqual to string');
t.notStrictEqual('3', 3, 'string notStrictEqual to number');
t.strictEqual(3, '3', 'number strictEqual to string');
t.strictEqual('3', 3, 'string strictEqual to number');
t.notStrictEqual(3, '3', 'number notStrictEqual to string');
t.notStrictEqual('3', 3, 'string notStrictEqual to number');
t.deepLooseEqual(3, '3', 'number deepLooseEqual to string');
t.deepLooseEqual('3', 3, 'string deepLooseEqual to number');
t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string');
t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number');
t.deepLooseEqual(3, '3', 'number deepLooseEqual to string');
t.deepLooseEqual('3', 3, 'string deepLooseEqual to number');
t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string');
t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number');
t.deepEqual(3, '3', 'number deepEqual to string');
t.deepEqual('3', 3, 'string deepEqual to number');
t.notDeepEqual(3, '3', 'number notDeepEqual to string');
t.notDeepEqual('3', 3, 'string notDeepEqual to number');
t.deepEqual(3, '3', 'number deepEqual to string');
t.deepEqual('3', 3, 'string deepEqual to number');
t.notDeepEqual(3, '3', 'number notDeepEqual to string');
t.notDeepEqual('3', 3, 'string notDeepEqual to number');
t.end();
});
t.end();
});
});

@@ -9,64 +9,64 @@ 'use strict';

tap.test('object results', function (assert) {
var printer = through({ objectMode: true });
var objects = [];
var printer = through({ objectMode: true });
var objects = [];
printer.write = function (obj) {
objects.push(obj);
};
printer.write = function (obj) {
objects.push(obj);
};
printer.end = function (obj) {
if (obj) { objects.push(obj); }
printer.end = function (obj) {
if (obj) { objects.push(obj); }
var todos = 0;
var skips = 0;
var testIds = [];
var endIds = [];
var asserts = 0;
var todos = 0;
var skips = 0;
var testIds = [];
var endIds = [];
var asserts = 0;
assert.equal(objects.length, 13);
assert.equal(objects.length, 13);
forEach(objects, function (object) {
if (object.type === 'assert') {
asserts++;
} else if (object.type === 'test') {
testIds.push(object.id);
forEach(objects, function (object) {
if (object.type === 'assert') {
asserts++;
} else if (object.type === 'test') {
testIds.push(object.id);
if (object.skip) {
skips++;
} else if (object.todo) {
todos++;
}
} else if (object.type === 'end') {
endIds.push(object.text);
// test object should exist
assert.notEqual(testIds.indexOf(object.test), -1);
}
});
if (object.skip) {
skips++;
} else if (object.todo) {
todos++;
}
} else if (object.type === 'end') {
endIds.push(object.text);
// test object should exist
assert.notEqual(testIds.indexOf(object.test), -1);
}
});
assert.equal(asserts, 5);
assert.equal(skips, 1);
assert.equal(todos, 2);
assert.equal(testIds.length, endIds.length);
assert.end();
};
assert.equal(asserts, 5);
assert.equal(skips, 1);
assert.equal(todos, 2);
assert.equal(testIds.length, endIds.length);
assert.end();
};
tape.createStream({ objectMode: true }).pipe(printer);
tape.createStream({ objectMode: true }).pipe(printer);
tape('parent', function (t1) {
t1.equal(true, true);
t1.test('child1', { skip: true }, function (t2) {
t2.equal(true, true);
t2.equal(true, false);
t2.end();
});
t1.test('child2', { todo: true }, function (t3) {
t3.equal(true, false);
t3.equal(true, true);
t3.end();
});
t1.test('child3', { todo: true });
t1.equal(true, true);
t1.equal(true, true);
t1.end();
});
tape('parent', function (t1) {
t1.equal(true, true);
t1.test('child1', { skip: true }, function (t2) {
t2.equal(true, true);
t2.equal(true, false);
t2.end();
});
t1.test('child2', { todo: true }, function (t3) {
t3.equal(true, false);
t3.equal(true, true);
t3.end();
});
t1.test('child3', { todo: true });
t1.equal(true, true);
t1.equal(true, true);
t1.end();
});
});

@@ -8,35 +8,35 @@ 'use strict';

tap.test('test.comment() in objectMode', function (assert) {
var printer = through({ objectMode: true });
var objects = [];
printer.on('error', function (e) {
assert.fail(e);
});
var printer = through({ objectMode: true });
var objects = [];
printer.on('error', function (e) {
assert.fail(e);
});
printer.write = function (obj) {
objects.push(obj);
};
printer.end = function (obj) {
if (obj) { objects.push(obj); }
printer.write = function (obj) {
objects.push(obj);
};
printer.end = function (obj) {
if (obj) { objects.push(obj); }
assert.equal(objects.length, 3);
assert.deepEqual(objects, [
{
type: 'test',
name: 'test.comment',
id: 0,
skip: false,
todo: false
},
'message',
{ type: 'end', test: 0 }
]);
assert.end();
};
assert.equal(objects.length, 3);
assert.deepEqual(objects, [
{
type: 'test',
name: 'test.comment',
id: 0,
skip: false,
todo: false
},
'message',
{ type: 'end', test: 0 }
]);
assert.end();
};
tape.createStream({ objectMode: true }).pipe(printer);
tape.createStream({ objectMode: true }).pipe(printer);
tape('test.comment', function (test) {
test.comment('message');
test.end();
});
tape('test.comment', function (test) {
test.comment('message');
test.end();
});
});

@@ -13,12 +13,12 @@ 'use strict';

tap.test('on failure', { timeout: 1000 }, function (tt) {
tt.plan(1);
tt.plan(1);
tape('dummy test', function (t) {
t.fail();
t.end();
});
tape('dummy test', function (t) {
t.fail();
t.end();
});
tape.onFailure(function () {
tt.pass('tape ended');
});
tape.onFailure(function () {
tt.pass('tape ended');
});
});

@@ -7,9 +7,9 @@ 'use strict';

tap.test('on finish', { timeout: 1000 }, function (tt) {
tt.plan(1);
tape.onFinish(function () {
tt.pass('tape ended');
});
tape('dummy test', function (t) {
t.end();
});
tt.plan(1);
tape.onFinish(function () {
tt.pass('tape ended');
});
tape('dummy test', function (t) {
t.end();
});
});

@@ -7,17 +7,17 @@ 'use strict';

tap.test('only twice error', function (assert) {
var test = tape.createHarness({ exit: false });
var test = tape.createHarness({ exit: false });
test.only('first only', function (t) {
t.end();
});
test.only('first only', function (t) {
t.end();
});
assert['throws'](function () {
test.only('second only', function (t) {
t.end();
});
}, {
name: 'Error',
message: 'there can only be one only test'
});
assert.end();
assert['throws'](function () {
test.only('second only', function (t) {
t.end();
});
}, {
name: 'Error',
message: 'there can only be one only test'
});
assert.end();
});

@@ -8,41 +8,41 @@ 'use strict';

tap.test('tape only test', function (tt) {
var test = tape.createHarness({ exit: false });
var ran = [];
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]);
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();
};
tt.end();
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('never run fail', function (t) {
ran.push(1);
t.equal(true, false);
t.end();
});
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('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();
});
test.only('run success', function (t) {
ran.push(3);
t.ok(true, 'assert name');
t.end();
});
});

@@ -6,7 +6,7 @@ 'use strict';

test('only2 test 1', function (t) {
t.end();
t.end();
});
test.only('only2 test 2', function (t) {
t.end();
t.end();
});

@@ -6,13 +6,13 @@ 'use strict';

test('only3 test 1', function (t) {
t.fail('not 1');
t.end();
t.fail('not 1');
t.end();
});
test.only('only3 test 2', function (t) {
t.end();
t.end();
});
test('only3 test 3', function (t) {
t.fail('not 3');
t.end();
t.fail('not 3');
t.end();
});

@@ -6,8 +6,8 @@ 'use strict';

test('only4 duplicate test name', function (t) {
t.fail('not 1');
t.end();
t.fail('not 1');
t.end();
});
test.only('only4 duplicate test name', function (t) {
t.end();
t.end();
});

@@ -6,8 +6,8 @@ 'use strict';

test.only('only5 duplicate test name', function (t) {
t.end();
t.end();
});
test('only5 duplicate test name', function (t) {
t.fail('not 2');
t.end();
t.fail('not 2');
t.end();
});

@@ -7,14 +7,14 @@ 'use strict';

test(function (t) {
t.equal(current++, 0);
t.end();
t.equal(current++, 0);
t.end();
});
test(function (t) {
t.plan(1);
setTimeout(function () {
t.equal(current++, 1);
}, 100);
t.plan(1);
setTimeout(function () {
t.equal(current++, 1);
}, 100);
});
test(function (t) {
t.equal(current++, 2);
t.end();
t.equal(current++, 2);
t.end();
});

@@ -6,13 +6,13 @@ 'use strict';

test('plan should be optional', function (t) {
t.pass('no plan here');
t.end();
t.pass('no plan here');
t.end();
});
test('no plan async', function (t) {
setTimeout(function () {
t.pass('ok');
t.end();
}, 100);
setTimeout(function () {
t.pass('ok');
t.end();
}, 100);
});
// vim: set softtabstop=4 shiftwidth=4:

@@ -7,65 +7,65 @@ 'use strict';

function tape(args) {
var bin = __dirname + '/../bin/tape';
return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname });
}
tap.test('requiring a single module', function (t) {
t.plan(2);
t.plan(2);
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# module-a',
'ok 1 loaded module a',
'# 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 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);
});
var ps = tape('-r ./require/a require/test-a.js');
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});
tap.test('requiring multiple modules', function (t) {
t.plan(2);
t.plan(2);
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# module-a',
'ok 1 loaded module a',
'# module-b',
'ok 2 loaded module b',
'# test-a',
'ok 3 module-a loaded in same context',
'ok 4 test ran after module-a was loaded',
'# test-b',
'ok 5 module-b loaded in same context',
'ok 6 test ran after module-b was loaded',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok'
].join('\n') + '\n\n');
};
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# module-a',
'ok 1 loaded module a',
'# module-b',
'ok 2 loaded module b',
'# test-a',
'ok 3 module-a loaded in same context',
'ok 4 test ran after module-a was loaded',
'# test-b',
'ok 5 module-b loaded in same context',
'ok 6 test ran after module-b was loaded',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok'
].join('\n') + '\n\n');
};
var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js');
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js');
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});
function tape(args) {
var bin = __dirname + '/../bin/tape';
return spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname });
}

@@ -6,6 +6,6 @@ 'use strict';

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;

@@ -6,6 +6,6 @@ 'use strict';

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;

@@ -6,5 +6,5 @@ 'use strict';

tape.test('test-a', function (t) {
t.ok(global.module_a, 'module-a loaded in same context');
t.pass('test ran after module-a was loaded');
t.end();
t.ok(global.module_a, 'module-a loaded in same context');
t.pass('test ran after module-a was loaded');
t.end();
});

@@ -6,5 +6,5 @@ 'use strict';

tape.test('test-b', function (t) {
t.ok(global.module_b, 'module-b loaded in same context');
t.pass('test ran after module-b was loaded');
t.end();
t.ok(global.module_b, 'module-b loaded in same context');
t.pass('test ran after module-b was loaded');
t.end();
});

@@ -9,78 +9,78 @@ 'use strict';

tap.test('test skip explanations', function (assert) {
assert.plan(1);
assert.plan(1);
var verify = function (output) {
assert.same(stripFullStack(output.toString('utf8')), [
'TAP version 13',
'# SKIP (this skips)',
'# some tests might skip',
'ok 1 this runs',
'ok 2 failing assert is skipped # SKIP',
'ok 3 this runs',
'# incomplete test',
'ok 4 run sh',
'ok 5 run openssl # SKIP',
'# incomplete test with explanation',
'ok 6 run sh (conditional skip) # SKIP',
'ok 7 run openssl # SKIP can\'t run on windows platforms',
'ok 8 this runs',
'# too much explanation',
'ok 9 run openssl # SKIP Installer cannot work on windows and fails to add to PATH Err: (2401) denied',
'',
'1..9',
'# tests 9',
'# pass 9',
'',
'# ok',
''
]);
};
var verify = function (output) {
assert.same(stripFullStack(output.toString('utf8')), [
'TAP version 13',
'# SKIP (this skips)',
'# some tests might skip',
'ok 1 this runs',
'ok 2 failing assert is skipped # SKIP',
'ok 3 this runs',
'# incomplete test',
'ok 4 run sh',
'ok 5 run openssl # SKIP',
'# incomplete test with explanation',
'ok 6 run sh (conditional skip) # SKIP',
'ok 7 run openssl # SKIP can\'t run on windows platforms',
'ok 8 this runs',
'# too much explanation',
'ok 9 run openssl # SKIP Installer cannot work on windows and fails to add to PATH Err: (2401) denied',
'',
'1..9',
'# tests 9',
'# pass 9',
'',
'# ok',
''
]);
};
var tapeTest = test.createHarness();
tapeTest.createStream().pipe(concat(verify));
var tapeTest = test.createHarness();
tapeTest.createStream().pipe(concat(verify));
tapeTest('(this skips)', { skip: true }, function (t) {
t.fail('doesn\'t run');
t.fail('this doesn\'t run too', { skip: false });
t.end();
});
tapeTest('(this skips)', { skip: true }, function (t) {
t.fail('doesn\'t run');
t.fail('this doesn\'t run too', { skip: false });
t.end();
});
tapeTest('some tests might skip', function (t) {
t.pass('this runs');
t.fail('failing assert is skipped', { skip: true });
t.pass('this runs');
t.end();
});
tapeTest('some tests might skip', function (t) {
t.pass('this runs');
t.fail('failing assert is skipped', { skip: true });
t.pass('this runs');
t.end();
});
tapeTest('incomplete test', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
tapeTest('incomplete test', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
t.pass('run sh', { skip: platform !== 'win32' });
t.pass('run openssl', { skip: platform === 'win32' });
t.end();
});
t.pass('run sh', { skip: platform !== 'win32' });
t.pass('run openssl', { skip: platform === 'win32' });
t.end();
});
tapeTest('incomplete test with explanation', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
tapeTest('incomplete test with explanation', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
t.fail('run sh (conditional skip)', { skip: platform === 'win32' });
t.fail('run openssl', { skip: platform === 'win32' && 'can\'t run on windows platforms' });
t.pass('this runs');
t.end();
});
t.fail('run sh (conditional skip)', { skip: platform === 'win32' });
t.fail('run openssl', { skip: platform === 'win32' && 'can\'t run on windows platforms' });
t.pass('this runs');
t.end();
});
tapeTest('too much explanation', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
tapeTest('too much explanation', function (t) {
// var platform = process.platform; something like this needed
var platform = 'win32';
t.fail(
'run openssl',
{ skip: platform === 'win32' && 'Installer cannot work on windows\nand fails to add to PATH\n\n Err: (2401) denied' }
);
t.end();
});
t.fail(
'run openssl',
{ skip: platform === 'win32' && 'Installer cannot work on windows\nand fails to add to PATH\n\n Err: (2401) denied' }
);
t.end();
});
});
// vim: set softtabstop=4 shiftwidth=4:

@@ -9,43 +9,43 @@ 'use strict';

tap.test('test SKIP comment', function (assert) {
assert.plan(1);
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 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();
});
var tapeTest = test.createHarness();
tapeTest.createStream().pipe(concat(verify));
tapeTest('skipped', { skip: true }, function (t) {
t.end();
});
});
test('skip this', { skip: true }, function (t) {
t.fail('this should not even run');
t.end();
t.fail('this should not even run');
t.end();
});
test.skip('skip this too', function (t) {
t.fail('this should not even run');
t.end();
t.fail('this should not even run');
t.end();
});
test('skip subtest', function (t) {
t.test('skip this', { skip: true }, function (st) {
st.fail('this should not even run');
st.end();
});
t.end();
t.test('skip this', { skip: true }, function (st) {
st.fail('this should not even run');
st.end();
});
t.end();
});
// vim: set softtabstop=4 shiftwidth=4:

@@ -7,109 +7,113 @@ 'use strict';

var tapParser = require('tap-parser');
var yaml = require('js-yaml');
var common = require('./common');
var getDiag = common.getDiag;
function stripAt(body) {
return body.replace(/^\s*at:\s+Test.*$\n/m, '');
}
tap.test('preserves stack trace with newlines', function (tt) {
tt.plan(3);
tt.plan(3);
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var stackTrace = 'foo\n bar';
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var stackTrace = 'foo\n bar';
var inspected = 'cause' in Error.prototype ? '{ [Error: Preserve stack] [cause]: undefined }' : '[Error: Preserve stack]';
parser.once('assert', function (data) {
delete data.diag.at;
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'Error: Preserve stack',
diag: {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
}
});
});
parser.once('assert', function (data) {
delete data.diag.at;
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'Error: Preserve stack',
diag: {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: inspected
}
});
});
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.deepEqual(strippedBody.split('\n'), [].concat(
'TAP version 13',
'# multiline stack trace',
'not ok 1 Error: Preserve stack',
' ---',
' operator: error',
' expected: |-',
' undefined',
' actual: |-',
' [Error: Preserve stack]',
' stack: |-',
' foo',
' bar',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
));
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.equal(
strippedBody,
'TAP version 13\n'
+ '# multiline stack trace\n'
+ 'not ok 1 Error: Preserve stack\n'
+ ' ---\n'
+ ' operator: error\n'
+ ' expected: |-\n'
+ ' undefined\n'
+ ' actual: |-\n'
+ ' ' + inspected + '\n'
+ ' stack: |-\n'
+ ' foo\n'
+ ' bar\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
tt.deepEqual(getDiag(strippedBody, true), {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
});
}));
tt.deepEqual(getDiag(strippedBody), {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: inspected
});
}));
test('multiline stack trace', function (t) {
t.plan(1);
var err = new Error('Preserve stack');
err.stack = stackTrace;
t.error(err);
});
test('multiline stack trace', function (t) {
t.plan(1);
var err = new Error('Preserve stack');
err.stack = stackTrace;
t.error(err);
});
});
tap.test('parses function info from original stack', function (tt) {
tt.plan(4);
tt.plan(4);
var test = tape.createHarness();
test.createStream();
var test = tape.createHarness();
test.createStream();
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.testFunctionNameParsing', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.testFunctionNameParsing', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test('t.equal stack trace', function testFunctionNameParsing(t) {
t.equal(true, false, 'true should be false');
t.end();
});
test('t.equal stack trace', function testFunctionNameParsing(t) {
t.equal(true, false, 'true should be false');
t.end();
});
});
tap.test('parses function info from original stack for anonymous function', function (tt) {
tt.plan(4);
tt.plan(4);
var test = tape.createHarness();
test.createStream();
var test = tape.createHarness();
test.createStream();
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.<anonymous>', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.<anonymous>', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test('t.equal stack trace', function (t) {
t.equal(true, false, 'true should be false');
t.end();
});
test('t.equal stack trace', function (t) {
t.equal(true, false, 'true should be false');
t.end();
});
});

@@ -119,51 +123,51 @@

tap.test('parses function info from original stack for Promise scenario', function (tt) {
tt.plan(4);
tap.test('parses function info from original stack for Promise scenario', function (tt) {
tt.plan(4);
var test = tape.createHarness();
test.createStream();
var test = tape.createHarness();
test.createStream();
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('onfulfilled', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('onfulfilled', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test('t.equal stack trace', function testFunctionNameParsing(t) {
new Promise(function (resolve) {
resolve();
}).then(function onfulfilled() {
t.equal(true, false, 'true should be false');
t.end();
});
});
});
test('t.equal stack trace', function testFunctionNameParsing(t) {
new Promise(function (resolve) {
resolve();
}).then(function onfulfilled() {
t.equal(true, false, 'true should be false');
t.end();
});
});
});
tap.test('parses function info from original stack for Promise scenario with anonymous function', function (tt) {
tt.plan(4);
tap.test('parses function info from original stack for Promise scenario with anonymous function', function (tt) {
tt.plan(4);
var test = tape.createHarness();
test.createStream();
var test = tape.createHarness();
test.createStream();
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('<anonymous>', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('<anonymous>', res.functionName);
tt.match(res.file, /stackTrace.js/i);
tt.ok(Number(res.line) > 0);
tt.ok(Number(res.column) > 0);
});
};
test('t.equal stack trace', function testFunctionNameParsing(t) {
new Promise(function (resolve) {
resolve();
}).then(function () {
t.equal(true, false, 'true should be false');
t.end();
});
});
});
test('t.equal stack trace', function testFunctionNameParsing(t) {
new Promise(function (resolve) {
resolve();
}).then(function () {
t.equal(true, false, 'true should be false');
t.end();
});
});
});

@@ -173,147 +177,125 @@ }

tap.test('preserves stack trace for failed assertions', function (tt) {
tt.plan(6);
tt.plan(6);
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var stack = '';
parser.once('assert', function (data) {
tt.equal(typeof data.diag.at, 'string');
tt.equal(typeof data.diag.stack, 'string');
var at = data.diag.at || '';
stack = data.diag.stack || '';
tt.ok((/^Error: true should be false(\n {4}at .+)+/).exec(stack), 'stack should be a stack');
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'true should be false',
diag: {
at: at,
stack: stack,
operator: 'equal',
expected: false,
actual: true
}
});
});
var stack = '';
parser.once('assert', function (data) {
tt.equal(typeof data.diag.at, 'string');
tt.equal(typeof data.diag.stack, 'string');
var at = data.diag.at || '';
stack = data.diag.stack || '';
tt.ok((/^Error: true should be false(\n {4}at .+)+/).exec(stack), 'stack should be a stack');
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'true should be false',
diag: {
at: at,
stack: stack,
operator: 'equal',
expected: false,
actual: true
}
});
});
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.equal(
strippedBody,
'TAP version 13\n'
+ '# t.equal stack trace\n'
+ 'not ok 1 true should be false\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: false\n'
+ ' actual: true\n'
+ ' stack: |-\n'
+ ' '
+ stack.replace(/\n/g, '\n ')
+ '\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.deepEqual(strippedBody.split('\n'), [].concat(
'TAP version 13',
'# t.equal stack trace',
'not ok 1 true should be false',
' ---',
' operator: equal',
' expected: false',
' actual: true',
' stack: |-',
('\n' + stack).replace(/\n/g, '\n ').split('\n').slice(1),
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
));
tt.deepEqual(getDiag(strippedBody), {
stack: stack,
operator: 'equal',
expected: false,
actual: true
});
}));
tt.deepEqual(getDiag(strippedBody, true), {
stack: stack,
operator: 'equal',
expected: false,
actual: true
});
}));
test('t.equal stack trace', function (t) {
t.plan(1);
t.equal(true, false, 'true should be false');
});
test('t.equal stack trace', function (t) {
t.plan(1);
t.equal(true, false, 'true should be false');
});
});
tap.test('preserves stack trace for failed assertions where actual===falsy', function (tt) {
tt.plan(6);
tt.plan(6);
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var test = tape.createHarness();
var stream = test.createStream();
var parser = stream.pipe(tapParser());
var stack = '';
parser.once('assert', function (data) {
tt.equal(typeof data.diag.at, 'string');
tt.equal(typeof data.diag.stack, 'string');
var at = data.diag.at || '';
stack = data.diag.stack || '';
tt.ok((/^Error: false should be true(\n {4}at .+)+/).exec(stack), 'stack should be a stack');
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'false should be true',
diag: {
at: at,
stack: stack,
operator: 'equal',
expected: true,
actual: false
}
});
});
var stack = '';
parser.once('assert', function (data) {
tt.equal(typeof data.diag.at, 'string');
tt.equal(typeof data.diag.stack, 'string');
var at = data.diag.at || '';
stack = data.diag.stack || '';
tt.ok((/^Error: false should be true(\n {4}at .+)+/).exec(stack), 'stack should be a stack');
tt.deepEqual(data, {
ok: false,
id: 1,
name: 'false should be true',
diag: {
at: at,
stack: stack,
operator: 'equal',
expected: true,
actual: false
}
});
});
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.equal(
strippedBody,
'TAP version 13\n'
+ '# t.equal stack trace\n'
+ 'not ok 1 false should be true\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: true\n'
+ ' actual: false\n'
+ ' stack: |-\n'
+ ' '
+ stack.replace(/\n/g, '\n ')
+ '\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
stream.pipe(concat(function (body) {
var strippedBody = stripAt(body.toString('utf8'));
tt.deepEqual(strippedBody.split('\n'), [].concat(
'TAP version 13',
'# t.equal stack trace',
'not ok 1 false should be true',
' ---',
' operator: equal',
' expected: true',
' actual: false',
' stack: |-',
('\n' + stack).replace(/\n/g, '\n ').split('\n').slice(1),
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
));
tt.deepEqual(getDiag(strippedBody), {
stack: stack,
operator: 'equal',
expected: true,
actual: false
});
}));
tt.deepEqual(getDiag(strippedBody, true), {
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');
});
test('t.equal stack trace', function (t) {
t.plan(1);
t.equal(false, true, 'false should be true');
});
});
function getDiag(body) {
var yamlStart = body.indexOf(' ---');
var yamlEnd = body.indexOf(' ...\n');
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
return line.slice(2);
}).join('\n');
// Get rid of 'at' variable (which has a line number / path of its own that's
// difficult to check).
var withStack = yaml.safeLoad(diag);
delete withStack.at;
return withStack;
}
function stripAt(body) {
return body.replace(/^\s*at:\s+Test.*$\n/m, '');
}

@@ -6,12 +6,12 @@ 'use strict';

test('parent test', function (t) {
t.plan(2);
t.test('first child', function (st) {
st.plan(1);
st.pass('pass first child');
});
t.plan(2);
t.test('first child', function (st) {
st.plan(1);
st.pass('pass first child');
});
t.test(function (st) {
st.plan(1);
st.pass('pass second child');
});
t.test(function (st) {
st.plan(1);
st.pass('pass second child');
});
});

@@ -6,23 +6,23 @@ 'use strict';

var asyncFunction = function (callback) {
setTimeout(callback, Math.random * 50);
setTimeout(callback, Math.random * 50);
};
test('master test', function (t) {
t.test('subtest 1', function (st) {
st.pass('subtest 1 before async call');
asyncFunction(function () {
st.pass('subtest 1 in async callback');
st.end();
});
});
t.test('subtest 1', function (st) {
st.pass('subtest 1 before async call');
asyncFunction(function () {
st.pass('subtest 1 in async callback');
st.end();
});
});
t.test('subtest 2', function (st) {
st.pass('subtest 2 before async call');
asyncFunction(function () {
st.pass('subtest 2 in async callback');
st.end();
});
});
t.test('subtest 2', function (st) {
st.pass('subtest 2 before async call');
asyncFunction(function () {
st.pass('subtest 2 in async callback');
st.end();
});
});
t.end();
t.end();
});

@@ -6,19 +6,19 @@ 'use strict';

test('parent', function (t) {
t.plan(3);
t.plan(3);
var firstChildRan = false;
var firstChildRan = false;
t.pass('assertion in parent');
t.pass('assertion in parent');
t.test('first child', function (st) {
st.plan(1);
st.pass('pass first child');
firstChildRan = true;
});
t.test('first child', function (st) {
st.plan(1);
st.pass('pass first child');
firstChildRan = true;
});
t.test('second child', function (st) {
st.plan(2);
st.ok(firstChildRan, 'first child ran first');
st.pass('pass second child');
});
t.test('second child', function (st) {
st.plan(2);
st.ok(firstChildRan, 'first child ran first');
st.pass('pass second child');
});
});

@@ -14,257 +14,257 @@ 'use strict';

tap.test('teardowns', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [].concat(
'TAP version 13',
'# success',
'ok 1 should be truthy',
'# success teardown',
'# success teardown 2',
'# success (async)',
'ok 2 should be truthy',
'# success (async) teardown',
'# success (async) teardown 2',
'# nested teardowns',
'# nested success',
'ok 3 should be truthy',
'# nested teardown (nested success level)',
'# nested teardown (nested success level) 2',
'# nested failure',
'not ok 4 nested failure!',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: nested failure!',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# nested teardown (nested fail level)',
'# nested teardown (nested fail level) 2',
'# nested teardown (top level)',
'# nested teardown (top level) 2',
'# fail',
'not ok 5 failure!',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: failure!',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# failure teardown',
'# failure teardown 2',
'# teardown errors do not stop the next teardown fn from running',
'ok 6 should be truthy',
'not ok 7 SyntaxError: teardown error!',
' ---',
' operator: fail',
' stack: |-',
' Error: SyntaxError: teardown error!',
' [... stack stripped ...]',
' ...',
'not ok 8 plan != count',
' ---',
' operator: fail',
' expected: 1',
' actual: 2',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'# teardown runs after teardown error',
'# teardown given non-function fails the test',
'ok 9 should be truthy',
flatMap(v.nonFunctions, function (nonFunction, i) {
var offset = 10;
return [].concat(
'not ok ' + (offset + (i > 0 ? i + 1 : i)) + ' teardown: ' + inspect(nonFunction) + ' is not a function',
' ---',
' operator: fail',
' at: <anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: teardown: ' + inspect(nonFunction) + ' is not a function',
' [... stack stripped ...]',
' at $TEST/teardown.js:$LINE:$COL',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
i > 0 ? [] : [
'not ok ' + (offset + 1) + ' plan != count',
' ---',
' operator: fail',
' expected: 1',
' actual: 2',
' at: <anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' at $TEST/teardown.js:$LINE:$COL',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...'
]
);
}),
typeof Promise === 'function' ? [
'# success (promise)',
'ok ' + (11 + v.nonFunctions.length) + ' should be truthy',
'# success (promise) teardown: 1',
'# success (promise) teardown: 2',
'# success (promise) teardown: 3'
] : [
'# SKIP success (promise)'
],
[
'',
'1..' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length),
'# tests ' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length),
'# pass ' + ((typeof Promise === 'function' ? 1 : 0) + 5),
'# fail ' + (5 + v.nonFunctions.length),
''
]
));
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [].concat(
'TAP version 13',
'# success',
'ok 1 should be truthy',
'# success teardown',
'# success teardown 2',
'# success (async)',
'ok 2 should be truthy',
'# success (async) teardown',
'# success (async) teardown 2',
'# nested teardowns',
'# nested success',
'ok 3 should be truthy',
'# nested teardown (nested success level)',
'# nested teardown (nested success level) 2',
'# nested failure',
'not ok 4 nested failure!',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: nested failure!',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# nested teardown (nested fail level)',
'# nested teardown (nested fail level) 2',
'# nested teardown (top level)',
'# nested teardown (top level) 2',
'# fail',
'not ok 5 failure!',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: failure!',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# failure teardown',
'# failure teardown 2',
'# teardown errors do not stop the next teardown fn from running',
'ok 6 should be truthy',
'not ok 7 SyntaxError: teardown error!',
' ---',
' operator: fail',
' stack: |-',
' Error: SyntaxError: teardown error!',
' [... stack stripped ...]',
' ...',
'not ok 8 plan != count',
' ---',
' operator: fail',
' expected: 1',
' actual: 2',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' ...',
'# teardown runs after teardown error',
'# teardown given non-function fails the test',
'ok 9 should be truthy',
flatMap(v.nonFunctions, function (nonFunction, i) {
var offset = 10;
return [].concat(
'not ok ' + (offset + (i > 0 ? i + 1 : i)) + ' teardown: ' + inspect(nonFunction) + ' is not a function',
' ---',
' operator: fail',
' at: <anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: teardown: ' + inspect(nonFunction) + ' is not a function',
' [... stack stripped ...]',
' at $TEST/teardown.js:$LINE:$COL',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
i > 0 ? [] : [
'not ok ' + (offset + 1) + ' plan != count',
' ---',
' operator: fail',
' expected: 1',
' actual: 2',
' at: <anonymous> ($TEST/teardown.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' at $TEST/teardown.js:$LINE:$COL',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/teardown.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...'
]
);
}),
typeof Promise === 'function' ? [
'# success (promise)',
'ok ' + (11 + v.nonFunctions.length) + ' should be truthy',
'# success (promise) teardown: 1',
'# success (promise) teardown: 2',
'# success (promise) teardown: 3'
] : [
'# SKIP success (promise)'
],
[
'',
'1..' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length),
'# tests ' + ((typeof Promise === 'function' ? 1 : 0) + 10 + v.nonFunctions.length),
'# pass ' + ((typeof Promise === 'function' ? 1 : 0) + 5),
'# fail ' + (5 + v.nonFunctions.length),
''
]
));
}));
test('success', function (t) {
t.plan(1);
t.teardown(function () {
t.comment('success teardown');
});
t.teardown(function () {
t.comment('success teardown 2');
});
t.ok('success!');
});
test('success', function (t) {
t.plan(1);
t.teardown(function () {
t.comment('success teardown');
});
t.teardown(function () {
t.comment('success teardown 2');
});
t.ok('success!');
});
test('success (async)', function (t) {
t.plan(1);
t.teardown(function () {
t.comment('success (async) teardown');
});
t.teardown(function () {
t.comment('success (async) teardown 2');
});
setTimeout(function () {
t.ok('success!');
}, 10);
});
test('success (async)', function (t) {
t.plan(1);
t.teardown(function () {
t.comment('success (async) teardown');
});
t.teardown(function () {
t.comment('success (async) teardown 2');
});
setTimeout(function () {
t.ok('success!');
}, 10);
});
test('nested teardowns', function (t) {
t.plan(2);
test('nested teardowns', function (t) {
t.plan(2);
t.teardown(function () {
t.comment('nested teardown (top level)');
});
t.teardown(function () {
t.comment('nested teardown (top level) 2');
});
t.teardown(function () {
t.comment('nested teardown (top level)');
});
t.teardown(function () {
t.comment('nested teardown (top level) 2');
});
t.test('nested success', function (st) {
st.teardown(function () {
st.comment('nested teardown (nested success level)');
});
st.teardown(function () {
st.comment('nested teardown (nested success level) 2');
});
t.test('nested success', function (st) {
st.teardown(function () {
st.comment('nested teardown (nested success level)');
});
st.teardown(function () {
st.comment('nested teardown (nested success level) 2');
});
st.ok('nested success!');
st.end();
});
st.ok('nested success!');
st.end();
});
t.test('nested failure', function (st) {
st.plan(1);
t.test('nested failure', function (st) {
st.plan(1);
st.teardown(function () {
st.comment('nested teardown (nested fail level)');
});
st.teardown(function () {
st.comment('nested teardown (nested fail level) 2');
});
st.teardown(function () {
st.comment('nested teardown (nested fail level)');
});
st.teardown(function () {
st.comment('nested teardown (nested fail level) 2');
});
st.fail('nested failure!');
});
});
st.fail('nested failure!');
});
});
test('fail', function (t) {
t.plan(1);
test('fail', function (t) {
t.plan(1);
t.teardown(function () {
t.comment('failure teardown');
});
t.teardown(function () {
t.comment('failure teardown 2');
});
t.teardown(function () {
t.comment('failure teardown');
});
t.teardown(function () {
t.comment('failure teardown 2');
});
t.fail('failure!');
});
t.fail('failure!');
});
test('teardown errors do not stop the next teardown fn from running', function (t) {
t.plan(1);
test('teardown errors do not stop the next teardown fn from running', function (t) {
t.plan(1);
t.ok('teardown error test');
t.ok('teardown error test');
t.teardown(function () {
throw new SyntaxError('teardown error!');
});
t.teardown(function () {
t.comment('teardown runs after teardown error');
});
});
t.teardown(function () {
throw new SyntaxError('teardown error!');
});
t.teardown(function () {
t.comment('teardown runs after teardown error');
});
});
test('teardown given non-function fails the test', function (t) {
t.plan(1);
test('teardown given non-function fails the test', function (t) {
t.plan(1);
t.ok('non-function test');
t.ok('non-function test');
forEach(v.nonFunctions, function (nonFunction) {
t.teardown(nonFunction);
});
});
forEach(v.nonFunctions, function (nonFunction) {
t.teardown(nonFunction);
});
});
test('success (promise)', { skip: typeof Promise !== 'function' }, function (t) {
t.plan(1);
test('success (promise)', { skip: typeof Promise !== 'function' }, function (t) {
t.plan(1);
t.teardown(function () {
return new Promise(function (resolve) {
t.comment('success (promise) teardown: 1');
setTimeout(resolve, 10);
}).then(function () {
t.comment('success (promise) teardown: 2');
});
});
t.teardown(function () {
t.comment('success (promise) teardown: 3');
});
t.teardown(function () {
return new Promise(function (resolve) {
t.comment('success (promise) teardown: 1');
setTimeout(resolve, 10);
}).then(function () {
t.comment('success (promise) teardown: 2');
});
});
t.teardown(function () {
t.comment('success (promise) teardown: 3');
});
setTimeout(function () {
t.ok('success!');
}, 10);
});
setTimeout(function () {
t.ok('success!');
}, 10);
});
});
tap.test('teardown with promise', { skip: typeof Promise !== 'function', timeout: 1e3 }, function (tt) {
tt.plan(2);
tape('dummy test', function (t) {
var resolved = false;
t.teardown(function () {
tt.pass('tape teardown');
var p = Promise.resolve();
p.then(function () {
resolved = true;
});
return p;
});
t.on('end', function () {
tt.is(resolved, true);
});
t.end();
});
tt.plan(2);
tape('dummy test', function (t) {
var resolved = false;
t.teardown(function () {
tt.pass('tape teardown');
var p = Promise.resolve();
p.then(function () {
resolved = true;
});
return p;
});
t.on('end', function () {
tt.is(resolved, true);
});
t.end();
});
});

@@ -10,8 +10,8 @@ 'use strict';

function getNonFunctionMessage(fn) {
try {
fn();
} catch (e) {
return e.message;
}
return '';
try {
fn();
} catch (e) {
return e.message;
}
return '';
}

@@ -21,5 +21,5 @@

var messageGetterError = Object.defineProperty(
{ custom: 'error' },
'message',
{ configurable: true, enumerable: true, get: getter }
{ custom: 'error' },
'message',
{ configurable: true, enumerable: true, get: getter }
);

@@ -29,201 +29,199 @@ var thrower = function () { throw messageGetterError; };

tap.test('failures', function (tt) {
tt.plan(1);
tt.plan(1);
var maybeCause = 'cause' in Error.prototype ? '[cause]: undefined, ' : '';
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# non functions',
'not ok 1 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(undefined)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(null)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(true)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(false)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage('abc')),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(/a/g)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage([])),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage({})),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# function',
'not ok 9 should throw',
' ---',
' operator: throws',
' expected: undefined',
' actual: undefined',
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
' Error: should throw',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# custom error messages',
'ok 10 "message" is enumerable',
"ok 11 { custom: 'error', message: 'message' }",
'ok 12 getter is still the same',
'# throws null',
'ok 13 throws null',
'# wrong type of error',
'not ok 14 throws actual',
' ---',
' operator: throws',
' expected: |-',
' [Function: TypeError]',
' actual: |-',
" { [RangeError: actual!] message: 'actual!' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
' RangeError: actual!',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..14',
'# tests 14',
'# pass 4',
'# fail 10',
''
]);
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# non functions',
'not ok 1 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage() + '] ' + maybeCause + "message: '" + getNonFunctionMessage() + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(undefined)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(null) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(null) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(null)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(true) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(true) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(true)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(false) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(false) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(false)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage('abc') + '] ' + maybeCause + "message: '" + getNonFunctionMessage('abc') + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage('abc')),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage(/a/g) + '] ' + maybeCause + "message: '" + getNonFunctionMessage(/a/g) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage(/a/g)),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage([]) + '] ' + maybeCause + "message: '" + getNonFunctionMessage([]) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage([])),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 should throw',
' ---',
' operator: throws',
' expected: |-',
' undefined',
' actual: |-',
' { [TypeError: ' + getNonFunctionMessage({}) + '] ' + maybeCause + "message: '" + getNonFunctionMessage({}) + "' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
String(' TypeError: ' + getNonFunctionMessage({})),
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# function',
'not ok 9 should throw',
' ---',
' operator: throws',
' expected: undefined',
' actual: undefined',
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
' Error: should throw',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'# custom error messages',
'ok 10 "message" is enumerable',
"ok 11 { custom: 'error', message: 'message' }",
'ok 12 getter is still the same',
'# throws null',
'ok 13 throws null',
'# wrong type of error',
'not ok 14 throws actual',
' ---',
' operator: throws',
' expected: |-',
' [Function: TypeError]',
' actual: |-',
' { [RangeError: actual!] ' + maybeCause + "message: 'actual!' }",
' at: Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' stack: |-',
' RangeError: actual!',
' at Test.<anonymous> ($TEST/throws.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..14',
'# tests 14',
'# pass 4',
'# fail 10',
''
]);
}));
test('non functions', function (t) {
t.plan(8);
t['throws']();
t['throws'](null);
t['throws'](true);
t['throws'](false);
t['throws']('abc');
t['throws'](/a/g);
t['throws']([]);
t['throws']({});
});
test('non functions', function (t) {
t.plan(8);
t['throws']();
t['throws'](null);
t['throws'](true);
t['throws'](false);
t['throws']('abc');
t['throws'](/a/g);
t['throws']([]);
t['throws']({});
});
test('function', function (t) {
t.plan(1);
t['throws'](function () {});
});
test('function', function (t) {
t.plan(1);
t['throws'](function () {});
});
test('custom error messages', function (t) {
t.plan(3);
t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable');
t['throws'](thrower, "{ custom: 'error', message: 'message' }");
t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same');
});
test('custom error messages', function (t) {
t.plan(3);
t.equal(Object.prototype.propertyIsEnumerable.call(messageGetterError, 'message'), true, '"message" is enumerable');
t['throws'](thrower, "{ custom: 'error', message: 'message' }");
t.equal(Object.getOwnPropertyDescriptor(messageGetterError, 'message').get, getter, 'getter is still the same');
});
test('throws null', function (t) {
t.plan(1);
t['throws'](function () { throw null; }, 'throws null');
t.end();
});
test('throws null', function (t) {
t.plan(1);
t['throws'](function () { throw null; }, 'throws null');
t.end();
});
test('wrong type of error', function (t) {
t.plan(1);
var actual = new RangeError('actual!');
t['throws'](function () { throw actual; }, TypeError, 'throws actual');
t.end();
});
test('wrong type of error', function (t) {
t.plan(1);
var actual = new RangeError('actual!');
t['throws'](function () { throw actual; }, TypeError, 'throws actual');
t.end();
});
});

@@ -7,12 +7,12 @@ 'use strict';

test('timeout', function (t) {
t.pass('this should run');
ran++;
setTimeout(function () {
t.end();
}, 100);
t.pass('this should run');
ran++;
setTimeout(function () {
t.end();
}, 100);
});
test('should still run', { timeout: 50 }, function (t) {
t.equal(ran, 1);
t.end();
t.equal(ran, 1);
t.end();
});

@@ -10,31 +10,31 @@ 'use strict';

tap.test('timeoutAfter test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# timeoutAfter',
'not ok 1 timeoutAfter timed out after 1ms',
' ---',
' operator: fail',
' stack: |-',
' Error: timeoutAfter timed out after 1ms',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
var test = tape.createHarness();
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# timeoutAfter',
'not ok 1 timeoutAfter timed out after 1ms',
' ---',
' operator: fail',
' stack: |-',
' Error: timeoutAfter timed out after 1ms',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('timeoutAfter', function (t) {
t.plan(1);
t.timeoutAfter(1);
});
test('timeoutAfter', function (t) {
t.plan(1);
t.timeoutAfter(1);
});
});

@@ -11,61 +11,61 @@ 'use strict';

tap.test('tape todo test', { todo: process.versions.node.match(/0\.8\.\d+/) ? 'Fails on node 0.8' : false }, function (assert) {
var test = tape.createHarness({ exit: false });
assert.plan(1);
var test = tape.createHarness({ exit: false });
assert.plan(1);
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# success',
'ok 1 this test runs',
'# TODO incomplete test1',
'not ok 2 check output # TODO',
' ---',
' operator: equal',
' expected: false',
' actual: true',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'not ok 3 check vars output # TODO name conflict',
' ---',
' operator: equal',
' expected: 0',
' actual: 1',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'# incomplete test2',
'not ok 4 run openssl # TODO installer needs fix',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'# TODO passing test',
'',
'1..4',
'# tests 4',
'# pass 4',
'',
'# ok',
''
]);
}));
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# success',
'ok 1 this test runs',
'# TODO incomplete test1',
'not ok 2 check output # TODO',
' ---',
' operator: equal',
' expected: false',
' actual: true',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'not ok 3 check vars output # TODO name conflict',
' ---',
' operator: equal',
' expected: 0',
' actual: 1',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'# incomplete test2',
'not ok 4 run openssl # TODO installer needs fix',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/todo_explanation.js:$LINE:$COL)',
' ...',
'# TODO passing test',
'',
'1..4',
'# tests 4',
'# pass 4',
'',
'# ok',
''
]);
}));
test('success', function (t) {
t.equal(true, true, 'this test runs');
t.end();
});
test('success', function (t) {
t.equal(true, true, 'this test runs');
t.end();
});
test('incomplete test1', { todo: true }, function (t) {
t.equal(true, false, 'check output');
t.equal(1, 0, 'check vars output', { todo: 'name conflict' });
t.end();
});
test('incomplete test1', { todo: true }, function (t) {
t.equal(true, false, 'check output');
t.equal(1, 0, 'check vars output', { todo: 'name conflict' });
t.end();
});
test('incomplete test2', function (t) {
t.fail('run openssl', { todo: 'installer needs fix' });
t.end();
});
test('incomplete test2', function (t) {
t.fail('run openssl', { todo: 'installer needs fix' });
t.end();
});
test('passing test', { todo: 'yet incomplete' }, function (t) {
t.end();
});
test('passing test', { todo: 'yet incomplete' }, function (t) {
t.end();
});
});

@@ -11,30 +11,30 @@ 'use strict';

tap.test('tape todo test', function (assert) {
var test = tape.createHarness({ exit: false });
assert.plan(1);
var test = tape.createHarness({ exit: false });
assert.plan(1);
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# TODO failure',
'not ok 1 should be equal # TODO',
' ---',
' operator: equal',
' expected: false',
' actual: true',
' at: Test.<anonymous> ($TEST/todo_single.js:$LINE:$COL)',
' ...',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
''
]);
}));
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# TODO failure',
'not ok 1 should be equal # TODO',
' ---',
' operator: equal',
' expected: false',
' actual: true',
' at: Test.<anonymous> ($TEST/todo_single.js:$LINE:$COL)',
' ...',
'',
'1..1',
'# tests 1',
'# pass 1',
'',
'# ok',
''
]);
}));
test('failure', { todo: true }, function (t) {
t.equal(true, false);
t.end();
});
test('failure', { todo: true }, function (t) {
t.equal(true, false);
t.end();
});
});

@@ -11,35 +11,35 @@ 'use strict';

tap.test('tape todo test', function (assert) {
var test = tape.createHarness({ exit: false });
assert.plan(1);
var test = tape.createHarness({ exit: false });
assert.plan(1);
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# success',
'ok 1 this test runs',
'# TODO failure',
'not ok 2 should never happen # TODO',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/todo.js:$LINE:$COL)',
' ...',
'',
'1..2',
'# tests 2',
'# pass 2',
'',
'# ok',
''
]);
}));
test.createStream().pipe(concat(function (body) {
assert.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# success',
'ok 1 this test runs',
'# TODO failure',
'not ok 2 should never happen # TODO',
' ---',
' operator: fail',
' at: Test.<anonymous> ($TEST/todo.js:$LINE:$COL)',
' ...',
'',
'1..2',
'# tests 2',
'# pass 2',
'',
'# ok',
''
]);
}));
test('success', function (t) {
t.equal(true, true, 'this test runs');
t.end();
});
test('success', function (t) {
t.equal(true, true, 'this test runs');
t.end();
});
test('failure', { todo: true }, function (t) {
t.fail('should never happen');
t.end();
});
test('failure', { todo: true }, function (t) {
t.fail('should never happen');
t.end();
});
});

@@ -11,72 +11,72 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be 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',
' at: <anonymous> ($TEST/too_many.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' at $TEST/too_many.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/too_many.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/too_many.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/too_many.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 6 should be equivalent',
'',
'1..6',
'# tests 6',
'# pass 5',
'# fail 1',
''
]);
};
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be 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',
' at: <anonymous> ($TEST/too_many.js:$LINE:$COL)',
' stack: |-',
' Error: plan != count',
' [... stack stripped ...]',
' at $TEST/too_many.js:$LINE:$COL',
' at eval (eval at <anonymous> ($TEST/too_many.js:$LINE:$COL))',
' at eval (eval at <anonymous> ($TEST/too_many.js:$LINE:$COL))',
' at Test.<anonymous> ($TEST/too_many.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 6 should be equivalent',
'',
'1..6',
'# tests 6',
'# pass 5',
'# fail 1',
''
]);
};
test.createStream().pipe(concat(tc));
test.createStream().pipe(concat(tc));
test('array', function (t) {
t.plan(3);
test('array', function (t) {
t.plan(3);
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var src = '(' + function () {
var xs = [1, 2, [3, 4]];
var ys = [5, 6];
g([xs, ys]);
} + ')()';
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var output = falafel(src, function (node) {
if (node.type === 'ArrayExpression') {
node.update('fn(' + node.source() + ')');
}
});
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
var arrays = [
[3, 4],
[1, 2, [3, 4]],
[5, 6],
[[1, 2, [3, 4]], [5, 6]]
];
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});
Function(['fn', 'g'], output)(
function (xs) {
t.same(arrays.shift(), xs);
return xs;
},
function (xs) {
t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
}
);
});
});

@@ -10,36 +10,36 @@ 'use strict';

tap.test('array test', function (tt) {
tt.plan(1);
tt.plan(1);
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# undef',
'not ok 1 should be equivalent',
' ---',
' operator: deepEqual',
' expected: |-',
' { beep: undefined }',
' actual: |-',
' {}',
' at: Test.<anonymous> ($TEST/undef.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/undef.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# undef',
'not ok 1 should be equivalent',
' ---',
' operator: deepEqual',
' expected: |-',
' { beep: undefined }',
' actual: |-',
' {}',
' at: Test.<anonymous> ($TEST/undef.js:$LINE:$COL)',
' stack: |-',
' Error: should be equivalent',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/undef.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'',
'1..1',
'# tests 1',
'# pass 0',
'# fail 1',
''
]);
}));
test('undef', function (t) {
t.plan(1);
t.deepEqual({}, { beep: undefined });
});
test('undef', function (t) {
t.plan(1);
t.deepEqual({}, { beep: undefined });
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc