diff --git a/lib/test.js b/lib/test.js index 398a68e6..de302c33 100644 --- a/lib/test.js +++ b/lib/test.js @@ -267,15 +267,16 @@ Test.prototype._assert = function assert(ok, opts) { /((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/ */ - var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)/; - var m = re.exec(err[i]); + var re = /^(?:[^\s]*\s*\bat\s+)(?:(.*)\s+\()?((?:\/|[a-zA-Z]:\\)[^:\)]+:(\d+)(?::(\d+))?)\)$/; + var lineWithTokens = err[i].replace(process.cwd(), '/\$CWD').replace(__dirname, '/\$TEST'); + var m = re.exec(lineWithTokens); if (!m) { continue; } var callDescription = m[1] || ''; - var filePath = m[2]; + var filePath = m[2].replace('/$CWD', process.cwd()).replace('/$TEST', __dirname); if (filePath.slice(0, dir.length) === dir) { continue; diff --git a/test/anonymous-fn.js b/test/anonymous-fn.js index e05b967c..5b3b948a 100644 --- a/test/anonymous-fn.js +++ b/test/anonymous-fn.js @@ -14,8 +14,8 @@ tap.test('inside anonymous functions', function (tt) { // Handle stack trace variation in Node v0.8 body = body.replace( - 'at Test.module.exports', - 'at Test.' + /at(:?) Test\.module\.exports/g, + 'at$1 Test.' ); tt.same(body, [ @@ -24,7 +24,7 @@ tap.test('inside anonymous functions', function (tt) { 'not ok 1 fail', ' ---', ' operator: fail', - ' at: ($TEST/anonymous-fn.js:$LINE:$COL)', + ' at: Test. ($TEST/anonymous-fn/test-wrapper.js:$LINE:$COL)', ' stack: |-', ' Error: fail', ' [... stack stripped ...]', diff --git a/test/common.js b/test/common.js index 39b12400..dac41bf1 100644 --- a/test/common.js +++ b/test/common.js @@ -31,27 +31,25 @@ module.exports.getDiag = function (body) { // these changes are irrelevant to the tests themselves. To counter this, we // strip out all stack frames that aren't directly under our test directory, // and replace them with placeholders. + +var stripChangingData = function (line) { + var withoutTestDir = line.replace(__dirname, '$TEST'); + var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); + var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/'); + var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL'); + var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \:\$LINE:\$COL\)$/, ')'); + return withoutNestedLineNumbers; +}; + module.exports.stripFullStack = function (output) { var stripped = ' [... stack stripped ...]'; - var withDuplicates = output.split('\n').map(function (line) { + var withDuplicates = output.split('\n').map(stripChangingData).map(function (line) { var m = line.match(/[ ]{8}at .*\((.*)\)/); - var stripChangingData = function (line) { - var withoutTestDir = line.replace(__dirname, '$TEST'); - var withoutPackageDir = withoutTestDir.replace(path.dirname(__dirname), '$TAPE'); - var withoutPathSep = withoutPackageDir.replace(new RegExp('\\' + path.sep, 'g'), '/'); - var withoutLineNumbers = withoutPathSep.replace(/:\d+:\d+/g, ':$LINE:$COL'); - var withoutNestedLineNumbers = withoutLineNumbers.replace(/, \:\$LINE:\$COL\)$/, ')'); - return withoutNestedLineNumbers; - }; - - if (m) { - if (m[1].slice(0, __dirname.length) === __dirname) { - return stripChangingData(line); - } + if (m && m[1].slice(0, 5) !== '$TEST') { return stripped; } - return stripChangingData(line); + return line; }); var deduped = withDuplicates.filter(function (line, ix) { diff --git a/test/exit.js b/test/exit.js index 90bf3a8c..fba56b23 100644 --- a/test/exit.js +++ b/test/exit.js @@ -52,7 +52,7 @@ tap.test('exit fail', function (t) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: ($TEST/exit/fail.js:$LINE:$COL)', + ' at: Test. ($TEST/exit/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', diff --git a/test/fail.js b/test/fail.js index 133359ca..b1123c2c 100644 --- a/test/fail.js +++ b/test/fail.js @@ -22,7 +22,7 @@ tap.test('array test', function (tt) { ' operator: deepEqual', ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]', ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]', - ' at: ($TEST/fail.js:$LINE:$COL)', + ' at: Test. ($TEST/fail.js:$LINE:$COL)', ' stack: |-', ' Error: should be equivalent', ' [... stack stripped ...]', diff --git a/test/too_many.js b/test/too_many.js index 5c7e4b38..c62cb4c3 100644 --- a/test/too_many.js +++ b/test/too_many.js @@ -22,7 +22,7 @@ tap.test('array test', function (tt) { ' operator: fail', ' expected: 3', ' actual: 4', - ' at: ($TEST/too_many.js:$LINE:$COL)', + ' at: Test. ($TEST/too_many.js:$LINE:$COL)', ' stack: |-', ' Error: plan != count', ' [... stack stripped ...]',