Skip to content
Permalink
Browse files
[fix] Fix bug in functionName regex during stack parsing
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 ec4a71d7c94a3692e5b42aa51d4a553d39fa8796
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
@@ -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]);
@@ -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);

@@ -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.