From 7e9bacf1ecb8c53404fac3eeed087e370e2a9cfa Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Fri, 1 Nov 2024 11:38:47 +0100 Subject: [PATCH] fix(core): measure perf for async checks (#4609) Performance of async checks isn't measured correctly. No tests, since we don't generally test perf timer stuff. --- lib/core/base/rule.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/core/base/rule.js b/lib/core/base/rule.js index 37b59904fe..2955cce29c 100644 --- a/lib/core/base/rule.js +++ b/lib/core/base/rule.js @@ -284,15 +284,21 @@ Rule.prototype.run = function run(context, options = {}, resolve, reject) { }); }); - // Defer the rule's execution to prevent "unresponsive script" warnings. - // See https://github.com/dequelabs/axe-core/pull/1172 for discussion and details. - q.defer(res => setTimeout(res, 0)); - - if (options.performanceTimer) { - this._logRulePerformance(); - } - - q.then(() => resolve(ruleResult)).catch(error => reject(error)); + q.then(() => { + if (options.performanceTimer) { + this._logRulePerformance(); + } + // Defer the rule's execution to prevent "unresponsive script" warnings. + // See https://github.com/dequelabs/axe-core/pull/1172 for discussion and details. + setTimeout(() => { + resolve(ruleResult); + }, 0); + }).catch(error => { + if (options.performanceTimer) { + this._logRulePerformance(); + } + reject(error); + }); }; /**