Browse Source

Allow error source to be fixed when assertion errors are created

If the source is known through other means it doesn't have to be derived
from the assertion error's stack trace.
master
Mark Wubben 8 years ago
parent
commit
e848898404
  1. 1
      lib/assert.js
  2. 17
      lib/serialize-error.js

1
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 || [];

17
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;
}

Loading…
Cancel
Save