From ec4a71d7c94a3692e5b42aa51d4a553d39fa8796 Mon Sep 17 00:00:00 2001 From: Marques Lee Date: Fri, 4 May 2018 10:39:57 -0700 Subject: [PATCH] [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. --- lib/test.js | 2 +- test/stackTrace.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/test.js b/lib/test.js index ad1cbfb2..ab380310 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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]); diff --git a/test/stackTrace.js b/test/stackTrace.js index 14241ff6..1cab4ace 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -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.', 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, ''); -} \ No newline at end of file +}