diff --git a/lib/assert/error.js b/lib/assert/error.js index cb1d67b..5087805 100644 --- a/lib/assert/error.js +++ b/lib/assert/error.js @@ -75,6 +75,11 @@ function errorDiff(err, type) { }).join(''); } +function extractPathFromStack(stack) { + var regex = /\((.*?[a-zA-Z0-9._-]+\.(?:js|coffee))(:\d+):\d+\)/; + return stack.match(regex); +} + /* Do not override .toString() when this.stack is used, otherwise this will end in an endless recursive call... @@ -85,7 +90,7 @@ require('assert').AssertionError.prototype.toStringEx = function () { source; if (this.stack) { - source = this.stack.match(/([a-zA-Z0-9._-]+\.(?:js|coffee))(:\d+):\d+/); + source = extractPathFromStack(this.stack); } function parse(str) { diff --git a/test/assert-test.js b/test/assert-test.js index fb30eb2..c79f1ff 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -130,7 +130,21 @@ vows.describe('vows/assert').addBatch({ assert.notIncludes([1, 2, 3], 4); assert.notIncludes({"red": 1, "blue": 2}, "green"); } - } + }, + + 'An AssertionError': { + topic: function generateAssertionError() { + try { + assert.isFalse(true); + } catch (e) { + return e.toString(); + } + }, + 'should have full path in stack trace': function(topic) { + var regexp = new RegExp("// " + __filename + ":\\d+"); + assert.isTrue(regexp.test(topic)); + } + }, }).export(module); function assertError(assertion, args, fail) {