Skip to content

Commit

Permalink
[fix] Fix bug in functionName regex during stack parsing
Browse files Browse the repository at this point in the history
Previously, this line was splitting on the letter 's'; more likely, it was meant to split on spaces.
  • Loading branch information
marques-work authored and ljharb committed May 4, 2018
1 parent 7261ccc commit ec4a71d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Test.prototype._assert = function assert (ok, opts) {

// 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.functionName = callDescription.split(/\s+/)[0]
res.file = filePath;
res.line = Number(m[3]);
if (m[4]) res.column = Number(m[4]);
Expand Down
38 changes: 37 additions & 1 deletion test/stackTrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,42 @@ tap.test('preserves stack trace with newlines', function (tt) {
});
});

tap.test('parses function name from original stack', function (tt) {
tt.plan(1);

var test = tape.createHarness();
test.createStream();

test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.testFunctionNameParsing', res.functionName)
});
};

test('t.equal stack trace', function testFunctionNameParsing(t) {
t.equal(true, false, 'true should be false');
t.end();
});
});

tap.test('parses function name from original stack for anonymous function', function (tt) {
tt.plan(1);

var test = tape.createHarness();
test.createStream();

test._results._watch = function (t) {
t.on('result', function (res) {
tt.equal('Test.<anonymous>', res.functionName)
});
};

test('t.equal stack trace', function (t) {
t.equal(true, false, 'true should be false');
t.end();
});
});

tap.test('preserves stack trace for failed assertions', function (tt) {
tt.plan(6);

Expand Down Expand Up @@ -214,4 +250,4 @@ function getDiag (body) {

function stripAt (body) {
return body.replace(/^\s*at:\s+Test.*$\n/m, '');
}
}

0 comments on commit ec4a71d

Please sign in to comment.