diff --git a/lib/assert.js b/lib/assert.js index 17291f4..12dc9cc 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -16,6 +16,7 @@ class AssertionError extends Error { this.name = 'AssertionError'; this.assertion = opts.assertion; + this.fixedSource = opts.fixedSource; this.operator = opts.operator; this.values = opts.values || []; diff --git a/lib/serialize-error.js b/lib/serialize-error.js index a0053ac..2d2fe00 100644 --- a/lib/serialize-error.js +++ b/lib/serialize-error.js @@ -15,13 +15,15 @@ function filter(propertyName, isRoot) { } const stackUtils = new StackUtils(); -function buildSource(stack) { +function extractSource(stack) { if (!stack) { return null; } const firstStackLine = extractStack(stack).split('\n')[0]; - const source = stackUtils.parseLine(firstStackLine); + return stackUtils.parseLine(firstStackLine); +} +function buildSource(source) { if (!source) { return null; } @@ -49,10 +51,10 @@ module.exports = error => { const stack = typeof error.stack === 'string' ? beautifyStack(error.stack) : null; - const source = buildSource(stack); + const retval = { avaAssertionError: isAvaAssertionError(error), - source + source: buildSource(extractSource(stack)) }; if (stack) { retval.stack = stack; @@ -64,6 +66,13 @@ module.exports = error => { retval.statements = error.statements; retval.values = error.values; + if (error.fixedSource) { + const source = buildSource(error.fixedSource); + if (source) { + retval.source = source; + } + } + if (error.assertion) { retval.assertion = error.assertion; }