Skip to content

Commit

Permalink
[Tests] make stripFullStack output an array of lines, for better fa…
Browse files Browse the repository at this point in the history
…ilure messages
  • Loading branch information
ljharb committed Jan 3, 2021
1 parent d505cdf commit 0743333
Show file tree
Hide file tree
Showing 27 changed files with 814 additions and 792 deletions.
5 changes: 3 additions & 2 deletions test/anonymous-fn.js
Expand Up @@ -32,8 +32,9 @@ tap.test('inside anonymous functions', function (tt) {
'1..1',
'# tests 1',
'# pass 0',
'# fail 1'
].join('\n') + '\n');
'# fail 1',
''
]);
};

test.createStream().pipe(concat(tc));
Expand Down
34 changes: 19 additions & 15 deletions test/async-await.js
Expand Up @@ -35,13 +35,11 @@ tap.test('async1', function (t) {
tap.test('async2', function (t) {
runProgram('async-await', 'async2.js', function (r) {
var stdout = r.stdout.toString('utf8');
var lines = stdout.split('\n');
lines = lines.filter(function (line) {
var lines = stdout.split('\n').filter(function (line) {
return !/^(\s+)at(\s+)<anonymous>$/.test(line);
});
stdout = lines.join('\n');

t.same(stripFullStack(stdout), [
t.same(stripFullStack(lines.join('\n')), [
'TAP version 13',
'# async2',
'ok 1 before await',
Expand All @@ -60,8 +58,10 @@ tap.test('async2', function (t) {
'1..2',
'# tests 2',
'# pass 1',
'# fail 1'
].join('\n') + '\n\n');
'# fail 1',
'',
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.end();
Expand Down Expand Up @@ -107,8 +107,10 @@ tap.test('async4', function (t) {
'1..2',
'# tests 2',
'# pass 1',
'# fail 1'
].join('\n') + '\n\n');
'# fail 1',
'',
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.end();
Expand Down Expand Up @@ -159,8 +161,10 @@ tap.test('async5', function (t) {
'1..8',
'# tests 8',
'# pass 5',
'# fail 3'
].join('\n') + '\n\n');
'# fail 3',
'',
''
]);
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
t.end();
Expand All @@ -174,7 +178,7 @@ tap.test('sync-error', function (t) {
'# sync-error',
'ok 1 before throw',
''
].join('\n'));
]);
t.same(r.exitCode, 1);

var stderr = r.stderr.toString('utf8');
Expand All @@ -197,7 +201,7 @@ tap.test('sync-error', function (t) {
' at Test.run ($TAPE/lib/test.js:$LINE:$COL)',
' at Test.bound [as run] ($TAPE/lib/test.js:$LINE:$COL)',
''
].join('\n'));
]);
t.end();
});
});
Expand All @@ -211,7 +215,7 @@ tap.test('async-error', function (t) {
});
stdout = lines.join('\n');

t.same(stripFullStack(stdout.toString('utf8')), [
t.same(stripFullStack(stdout), [
'TAP version 13',
'# async-error',
'ok 1 before throw',
Expand All @@ -230,7 +234,7 @@ tap.test('async-error', function (t) {
'# fail 1',
'',
'',
].join('\n'));
]);
t.same(r.exitCode, 1);

var stderr = r.stderr.toString('utf8');
Expand Down Expand Up @@ -276,7 +280,7 @@ tap.test('async-bug', function (t) {
'# fail 1',
'',
'',
].join('\n'));
]);
t.same(r.exitCode, 1);

var stderr = r.stderr.toString('utf8');
Expand Down
48 changes: 24 additions & 24 deletions test/circular-things.js
Expand Up @@ -11,30 +11,30 @@ tap.test('circular test', function (assert) {
assert.plan(1);

test.createStream().pipe(concat(function (body) {
assert.equal(
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# circular\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
+ ' {}\n'
+ ' actual: |-\n'
+ ' { circular: [Circular] }\n'
+ ' at: Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
assert.deepEqual(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# circular',
'not ok 1 should be strictly equal',
' ---',
' operator: equal',
' expected: |-',
' {}',
' actual: |-',
' { circular: [Circular] }',
' at: Test.<anonymous> ($TEST/circular-things.js:$LINE:$COL)',
' stack: |-',
' Error: should be strictly 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) {
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Expand Up @@ -69,7 +69,7 @@ module.exports.stripFullStack = function (output) {
// Handle stack trace variation in Node v0.8
/at(:?) Test\.(?:module\.exports|tap\.test\.err\.code)/g,
'at$1 Test.<anonymous>'
);
).split('\n');
};

module.exports.runProgram = function (folderName, fileName, cb) {
Expand Down
144 changes: 72 additions & 72 deletions test/deep-equal-failure.js
Expand Up @@ -17,30 +17,30 @@ tap.test('deep equal failure', function (assert) {

stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
+ ' { b: 2 }\n'
+ ' actual: |-\n'
+ ' { a: 1 }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
assert.deepEqual(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be strictly equal',
' ---',
' operator: equal',
' expected: |-',
' { b: 2 }',
' actual: |-',
' { a: 1 }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be strictly 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',
Expand Down Expand Up @@ -78,30 +78,30 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {

stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
assert.deepEqual(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be strictly equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be strictly 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',
Expand Down Expand Up @@ -139,30 +139,30 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {

stream.pipe(parser);
stream.pipe(concat(function (body) {
assert.equal(
stripFullStack(body.toString('utf8')),
'TAP version 13\n'
+ '# deep equal\n'
+ 'not ok 1 should be strictly equal\n'
+ ' ---\n'
+ ' operator: equal\n'
+ ' expected: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' stack: |-\n'
+ ' Error: should be strictly equal\n'
+ ' [... stack stripped ...]\n'
+ ' at Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)\n'
+ ' [... stack stripped ...]\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
+ '# tests 1\n'
+ '# pass 0\n'
+ '# fail 1\n'
);
assert.deepEqual(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# deep equal',
'not ok 1 should be strictly equal',
' ---',
' operator: equal',
' expected: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' actual: |-',
' { a: { a1: { a2: { a3: { a4: [Object] } } } } }',
' at: Test.<anonymous> ($TEST/deep-equal-failure.js:$LINE:$COL)',
' stack: |-',
' Error: should be strictly 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',
Expand Down
7 changes: 4 additions & 3 deletions test/default-messages.js
Expand Up @@ -13,7 +13,6 @@ tap.test('default messages', function (t) {
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',
Expand Down Expand Up @@ -44,7 +43,9 @@ tap.test('default messages', function (t) {
'1..12',
'# tests 12',
'# pass 11',
'# fail 1'
].join('\n') + '\n\n');
'# fail 1',
'',
''
]);
}));
});

0 comments on commit 0743333

Please sign in to comment.