Skip to content

Commit 298cb80

Browse files
committed
[Tests] stackTrace: use the common getDiag utility
1 parent 2151e06 commit 298cb80

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

test/common.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var spawn = require('child_process').spawn;
55
var concat = require('concat-stream');
66
var yaml = require('js-yaml');
77

8-
module.exports.getDiag = function (body) {
8+
module.exports.getDiag = function (body, includeStack) {
99
var yamlStart = body.indexOf(' ---');
1010
var yamlEnd = body.indexOf(' ...\n');
1111
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
@@ -15,7 +15,9 @@ module.exports.getDiag = function (body) {
1515
// The stack trace and at variable will vary depending on where the code
1616
// is run, so just strip it out.
1717
var withStack = yaml.safeLoad(diag);
18-
delete withStack.stack;
18+
if (!includeStack) {
19+
delete withStack.stack;
20+
}
1921
delete withStack.at;
2022
return withStack;
2123
};

test/stackTrace.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ var tape = require('../');
44
var tap = require('tap');
55
var concat = require('concat-stream');
66
var tapParser = require('tap-parser');
7-
var yaml = require('js-yaml');
7+
var common = require('./common');
8+
9+
var getDiag = common.getDiag;
810

911
tap.test('preserves stack trace with newlines', function (tt) {
1012
tt.plan(3);
@@ -47,7 +49,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
4749
''
4850
]);
4951

50-
tt.deepEqual(getDiag(strippedBody), {
52+
tt.deepEqual(getDiag(strippedBody, true), {
5153
stack: stackTrace,
5254
operator: 'error'
5355
});
@@ -206,7 +208,7 @@ tap.test('preserves stack trace for failed assertions', function (tt) {
206208
''
207209
));
208210

209-
tt.deepEqual(getDiag(strippedBody), {
211+
tt.deepEqual(getDiag(strippedBody, true), {
210212
stack: stack,
211213
operator: 'equal',
212214
expected: false,
@@ -269,7 +271,7 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun
269271
''
270272
));
271273

272-
tt.deepEqual(getDiag(strippedBody), {
274+
tt.deepEqual(getDiag(strippedBody, true), {
273275
stack: stack,
274276
operator: 'equal',
275277
expected: true,
@@ -283,19 +285,6 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun
283285
});
284286
});
285287

286-
function getDiag(body) {
287-
var yamlStart = body.indexOf(' ---');
288-
var yamlEnd = body.indexOf(' ...\n');
289-
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) {
290-
return line.slice(2);
291-
}).join('\n');
292-
293-
// Get rid of 'at' variable (which has a line number / path of its own that's difficult to check).
294-
var withStack = yaml.safeLoad(diag);
295-
delete withStack.at;
296-
return withStack;
297-
}
298-
299288
function stripAt(body) {
300289
return body.replace(/^\s*at:\s+Test.*$\n/m, '');
301290
}

0 commit comments

Comments
 (0)