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 b7b01ec commit f299759
Show file tree
Hide file tree
Showing 24 changed files with 900 additions and 839 deletions.
5 changes: 3 additions & 2 deletions test/anonymous-fn.js
Expand Up @@ -30,8 +30,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
48 changes: 24 additions & 24 deletions test/circular-things.js
Expand Up @@ -9,30 +9,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 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 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.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) {
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Expand Up @@ -65,5 +65,5 @@ 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');
};
144 changes: 72 additions & 72 deletions test/deep-equal-failure.js
Expand Up @@ -15,30 +15,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 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 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.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',
Expand Down Expand Up @@ -76,30 +76,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 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 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.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',
Expand Down Expand Up @@ -137,30 +137,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 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 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.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',
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',
'',
''
]);
}));
});
9 changes: 5 additions & 4 deletions test/double_end.js
Expand Up @@ -29,14 +29,13 @@ test(function (t) {
to._onTimeout();
}
catch (e) {
stackExpected = stripFullStack(e.stack).split('\n')[1];
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 stripped = stripFullStack(body.toString('utf8'));
t.equal(stripped, [
t.same(stripFullStack(body.toString('utf8')), [
'TAP version 13',
'# double end',
'ok 1 should be equal',
Expand All @@ -55,6 +54,8 @@ test(function (t) {
'# tests 2',
'# pass 1',
'# fail 1',
].join('\n') + '\n\n');
'',
''
]);
}));
});

0 comments on commit f299759

Please sign in to comment.