diff --git a/lib/core/base/audit.js b/lib/core/base/audit.js index 1f5a09ff75..2cb572dd50 100644 --- a/lib/core/base/audit.js +++ b/lib/core/base/audit.js @@ -391,7 +391,10 @@ function getDefferedRule(rule, context, options) { description: 'An error occured while running this rule', message: err.message, stack: err.stack, - error: err + error: err, + // Add a serialized reference to the node the rule failed on for easier debugging. + // See https://github.com/dequelabs/axe-core/issues/1317. + errorNode: err.errorNode }); // resolve resolve(errResult); diff --git a/lib/core/base/check.js b/lib/core/base/check.js index 7ef4001038..306dfadff2 100644 --- a/lib/core/base/check.js +++ b/lib/core/base/check.js @@ -1,4 +1,4 @@ -/*global CheckResult */ +/*global CheckResult,DqElement */ function createExecutionContext(spec) { /*eslint no-eval:0 */ @@ -58,6 +58,7 @@ Check.prototype.enabled = true; * @param {Function} callback Function to fire when check is complete */ Check.prototype.run = function(node, options, context, resolve, reject) { + /* eslint max-statements: ["error", 17] */ 'use strict'; options = options || {}; var enabled = options.hasOwnProperty('enabled') @@ -84,6 +85,13 @@ Check.prototype.run = function(node, options, context, resolve, reject) { context ); } catch (e) { + // In the "Audit#run: should run all the rules" test, there is no `node` here. I do + // not know if this is intentional or not, so to be safe, we guard against the + // possible reference error. + if (node && node.actualNode) { + // Save a reference to the node we errored on for futher debugging. + e.errorNode = new DqElement(node.actualNode).toJSON(); + } reject(e); return; } diff --git a/test/core/base/audit.js b/test/core/base/audit.js index 405d85340b..4f31701fc6 100644 --- a/test/core/base/audit.js +++ b/test/core/base/audit.js @@ -1035,9 +1035,10 @@ describe('Audit', function() { throw err; } }); - + axe._tree = axe.utils.getFlattenedTree(fixture); + axe._selectorData = axe.utils.getSelectorData(axe._tree); a.run( - { include: [axe.utils.getFlattenedTree(fixture)[0]] }, + { include: [axe._tree[0]] }, { runOnly: { type: 'rule',