Skip to content

Commit

Permalink
Fix test errors that pop up after adding full stack
Browse files Browse the repository at this point in the history
  • Loading branch information
AnIrishDuck committed Oct 17, 2016
1 parent c40119e commit 5b0aeb1
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 24 deletions.
6 changes: 5 additions & 1 deletion test/circular-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

tap.test('circular test', function (assert) {
var test = tape.createHarness({ exit : false });
assert.plan(1);

test.createStream().pipe(concat(function (body) {
assert.equal(
body.toString('utf8'),
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# circular\n'
+ 'not ok 1 should be equal\n'
Expand All @@ -18,6 +20,8 @@ tap.test('circular test', function (assert) {
+ ' {}\n'
+ ' actual: |-\n'
+ ' { circular: [Circular] }\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand Down
30 changes: 16 additions & 14 deletions test/deep-equal-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');
var tapParser = require('tap-parser');
var yaml = require('js-yaml');
var common = require('./common');

var getDiag = common.getDiag;
var stripFullStack = common.stripFullStack;

tap.test('deep equal failure', function (assert) {
var test = tape.createHarness({ exit : false });
Expand All @@ -13,7 +16,7 @@ tap.test('deep equal failure', function (assert) {
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
body.toString('utf8'),
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
Expand All @@ -23,6 +26,8 @@ tap.test('deep equal failure', function (assert) {
+ ' { b: 2 }\n'
+ ' actual: |-\n'
+ ' { a: 1 }\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -39,6 +44,7 @@ tap.test('deep equal failure', function (assert) {
}));

parser.once('assert', function (data) {
delete data.diag.stack;
assert.deepEqual(data, {
ok: false,
id: 1,
Expand Down Expand Up @@ -66,7 +72,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
body.toString('utf8'),
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
Expand All @@ -76,6 +82,8 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -92,6 +100,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
}));

parser.once('assert', function (data) {
delete data.diag.stack;
assert.deepEqual(data, {
ok: false,
id: 1,
Expand Down Expand Up @@ -119,7 +128,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
body.toString('utf8'),
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be equal\n'
Expand All @@ -129,6 +138,8 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' stack: |-\n'
+ ' Error: should be equal\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -145,6 +156,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
}));

parser.once('assert', function (data) {
delete data.diag.stack;
assert.deepEqual(data, {
ok: false,
id: 1,
Expand All @@ -162,13 +174,3 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
t.equal({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } });
});
})

function getDiag (body) {
var yamlStart = body.indexOf(' ---');
var yamlEnd = body.indexOf(' ...\n');
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
return line.slice(2);
}).join('\n');

return yaml.safeLoad(diag);
}
6 changes: 5 additions & 1 deletion test/double_end.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@ var path = require('path');
var concat = require('concat-stream');
var spawn = require('child_process').spawn;

var stripFullStack = require('./common').stripFullStack

test(function (t) {
t.plan(2);
var ps = spawn(process.execPath, [path.join(__dirname, 'double_end', 'double.js')]);
ps.on('exit', function (code) {
t.equal(code, 1);
});
ps.stdout.pipe(concat(function (body) {
t.equal(body.toString('utf8'), [
t.equal(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# double end',
'ok 1 should be equal',
'not ok 2 .end() called twice',
' ---',
' operator: fail',
' stack: |-',
' Error: .end() called twice',
' ...',
'',
'1..2',
Expand Down
14 changes: 11 additions & 3 deletions test/exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var path = require('path');
var spawn = require('child_process').spawn;
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

tap.test('exit ok', function (t) {
t.plan(2);

Expand Down Expand Up @@ -38,7 +40,7 @@ tap.test('exit fail', function (t) {
t.plan(2);

var tc = function (rows) {
t.same(rows.toString('utf8'), [
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be equivalent',
Expand All @@ -50,6 +52,8 @@ tap.test('exit fail', function (t) {
' operator: deepEqual',
' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
' stack: |-',
' Error: should be equivalent',
' ...',
'',
'1..5',
Expand All @@ -70,7 +74,7 @@ tap.test('too few exit', function (t) {
t.plan(2);

var tc = function (rows) {
t.same(rows.toString('utf8'), [
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be equivalent',
Expand All @@ -83,6 +87,8 @@ tap.test('too few exit', function (t) {
' operator: fail',
' expected: 6',
' actual: 5',
' stack: |-',
' Error: plan != count',
' ...',
'',
'1..6',
Expand All @@ -103,7 +109,7 @@ tap.test('more planned in a second test', function (t) {
t.plan(2);

var tc = function (rows) {
t.same(rows.toString('utf8'), [
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
Expand All @@ -114,6 +120,8 @@ tap.test('more planned in a second test', function (t) {
' operator: fail',
' expected: 2',
' actual: 1',
' stack: |-',
' Error: plan != count',
' ...',
'',
'1..3',
Expand Down
6 changes: 5 additions & 1 deletion test/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

tap.test('array test', function (tt) {
tt.plan(1);

var test = tape.createHarness({ exit : false });
var tc = function (rows) {
tt.same(rows.toString('utf8'), [
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be equivalent',
Expand All @@ -20,6 +22,8 @@ tap.test('array test', function (tt) {
' operator: deepEqual',
' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
' stack: |-',
' Error: should be equivalent',
' ...',
'',
'1..5',
Expand Down
22 changes: 21 additions & 1 deletion test/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

function fn() {
throw new TypeError('RegExp');
}
Expand All @@ -20,7 +22,7 @@ tap.test('failures', function (tt) {
var test = tape.createHarness();
test.createStream().pipe(concat(function (body) {
tt.equal(
body.toString('utf8'),
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# non functions\n'
+ 'not ok 1 should throw\n'
Expand All @@ -30,6 +32,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 2 should throw\n'
+ ' ---\n'
Expand All @@ -38,6 +42,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 3 should throw\n'
+ ' ---\n'
Expand All @@ -46,6 +52,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 4 should throw\n'
+ ' ---\n'
Expand All @@ -54,6 +62,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 5 should throw\n'
+ ' ---\n'
Expand All @@ -62,6 +72,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 6 should throw\n'
+ ' ---\n'
Expand All @@ -70,6 +82,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 7 should throw\n'
+ ' ---\n'
Expand All @@ -78,6 +92,8 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ 'not ok 8 should throw\n'
+ ' ---\n'
Expand All @@ -86,13 +102,17 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n"
+ ' stack: |-\n'
+ ' TypeError: ' + getNonFunctionMessage() + '\n'
+ ' ...\n'
+ '# function\n'
+ 'not ok 9 should throw\n'
+ ' ---\n'
+ ' operator: throws\n'
+ ' expected: undefined\n'
+ ' actual: undefined\n'
+ ' stack: |-\n'
+ ' Error: should throw\n'
+ ' ...\n'
+ '# custom error messages\n'
+ 'ok 10 "message" is enumerable\n'
Expand Down
6 changes: 5 additions & 1 deletion test/timeoutAfter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

tap.test('timeoutAfter test', function (tt) {
tt.plan(1);

var test = tape.createHarness();
var tc = function (rows) {
tt.same(rows.toString('utf8'), [
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# timeoutAfter',
'not ok 1 test timed out after 1ms',
' ---',
' operator: fail',
' stack: |-',
' Error: test timed out after 1ms',
' ...',
'',
'1..1',
Expand Down
6 changes: 5 additions & 1 deletion test/too_many.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');

var stripFullStack = require('./common').stripFullStack

tap.test('array test', function (tt) {
tt.plan(1);

var test = tape.createHarness({ exit : false });
var tc = function (rows) {
tt.same(rows.toString('utf8'), [
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# array',
'ok 1 should be equivalent',
Expand All @@ -20,6 +22,8 @@ tap.test('array test', function (tt) {
' operator: fail',
' expected: 3',
' actual: 4',
' stack: |-',
' Error: plan != count',
' ...',
'ok 6 should be equivalent',
'',
Expand Down
Loading

0 comments on commit 5b0aeb1

Please sign in to comment.