diff --git a/lib/test.js b/lib/test.js index a82d3100..59f62d5c 100644 --- a/lib/test.js +++ b/lib/test.js @@ -482,7 +482,7 @@ Test.prototype._assert = function assert(ok, opts) { if (!ok) { var e = new Error('exception'); var err = $split(e.stack || '', '\n'); - var dir = __dirname + path.sep; + var tapeDir = __dirname + path.sep; for (var i = 0; i < err.length; i++) { /* @@ -521,7 +521,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 lineWithTokens = $replace($replace(err[i], process.cwd(), '/$CWD'), __dirname, '/$TEST'); + // first tokenize the PWD, then tokenize tape + var lineWithTokens = $replace( + $replace( + err[i], + process.cwd(), + path.sep + '$CWD' + ), + tapeDir, + path.sep + '$TEST' + path.sep + ); var m = re.exec(lineWithTokens); if (!m) { @@ -529,9 +538,18 @@ Test.prototype._assert = function assert(ok, opts) { } var callDescription = m[1] || ''; - var filePath = $replace($replace(m[2], '/$CWD', process.cwd()), '/$TEST', __dirname); - - if ($strSlice(filePath, 0, dir.length) === dir) { + // first untokenize tape, and then untokenize the PWD, then strip the line/column + var filePath = $replace( + $replace( + $replace(m[2], path.sep + '$TEST' + path.sep, tapeDir), + path.sep + '$CWD', + process.cwd() + ), + /:\d+:\d+$/, + '' + ); + + if ($strSlice(filePath, 0, tapeDir.length) === tapeDir) { continue; } @@ -542,7 +560,7 @@ Test.prototype._assert = function assert(ok, opts) { res.line = Number(m[3]); if (m[4]) { res.column = Number(m[4]); } - res.at = callDescription + ' (' + filePath + ')'; + res.at = callDescription + ' (' + filePath + ':' + res.line + (res.column ? ':' + res.column : '') + ')'; break; } }