-
Notifications
You must be signed in to change notification settings - Fork 776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve perf of axe.run [WWD-1821] #1503
Changes from 11 commits
f513ee8
fde7556
9aecd10
a50b91e
0324acb
b6adc56
6698717
4286459
3d1db89
d30dc6c
dc8c4df
c01046f
3e28ae9
f2ba02e
f4f116b
52b22f1
ee98db4
cae9e26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Example Mocha Test</title> | ||
<link | ||
rel="stylesheet" | ||
href="../node_modules/mocha/mocha.css" | ||
type="text/css" | ||
charset="utf-8" | ||
/> | ||
</head> | ||
<body> | ||
<!-- Required for browser reporter --> | ||
<div id="mocha"></div> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Example Mocha Test</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" type="text/css" charset="utf-8" /> | ||
</head> | ||
<body> | ||
<!-- Required for browser reporter --> | ||
<div id="mocha"></div> | ||
|
||
<script | ||
src="../node_modules/mocha/mocha.js" | ||
type="text/javascript" | ||
charset="utf-8" | ||
></script> | ||
<script | ||
src="../node_modules/chai/chai.js" | ||
type="text/javascript" | ||
charset="utf-8" | ||
></script> | ||
<script | ||
src="../node_modules/axe-core/axe.min.js" | ||
type="text/javascript" | ||
charset="utf-8" | ||
></script> | ||
<script type="text/javascript" charset="utf-8"> | ||
mocha.setup('bdd'); | ||
var expect = chai.expect; | ||
</script> | ||
<script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script> | ||
<script src="../node_modules/chai/chai.js" type="text/javascript" charset="utf-8"></script> | ||
<script src="../node_modules/axe-core/axe.min.js" type="text/javascript" charset="utf-8"></script> | ||
<script type="text/javascript" charset="utf-8"> | ||
mocha.setup('bdd'); | ||
var expect = chai.expect; | ||
</script> | ||
|
||
<!-- Include axe --> | ||
<!-- Include axe --> | ||
|
||
<!-- Spec files --> | ||
<script src="a11y.js" type="text/javascript" charset="utf-8"></script> | ||
<div id="working"> | ||
<label for="labelfld">Label for this text field.</label> | ||
<input type="text" id="labelfld" /> | ||
</div> | ||
<div id="broken"> | ||
<p>Label for this text field.</p> | ||
<input type="text" id="nolabelfld" /> | ||
</div> | ||
</body> | ||
<!-- Spec files --> | ||
<script src="a11y.js" type="text/javascript" charset="utf-8"></script> | ||
<div id="working"> | ||
<label for="labelfld">Label for this text field.</label> | ||
<input type="text" id="labelfld"> | ||
</div> | ||
<div id="broken"> | ||
<p>Label for this text field.</p> | ||
<input type="text" id="nolabelfld"> | ||
</div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Basic Test Suite</title> | ||
<!-- Load local QUnit. --> | ||
<link | ||
rel="stylesheet" | ||
href="../node_modules/qunitjs/qunit/qunit.css" | ||
media="screen" | ||
/> | ||
<script src="../node_modules/qunitjs/qunit/qunit.js"></script> | ||
<!-- Load local lib and tests. --> | ||
<script src="../node_modules/axe-core/axe.min.js"></script> | ||
<script src="a11y.js"></script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
<div id="working"> | ||
<label for="labelfld">Label for this text field.</label> | ||
<input type="text" id="labelfld" /> | ||
</div> | ||
<div id="broken"> | ||
<p>Label for this text field.</p> | ||
<input type="text" id="nolabelfld" /> | ||
</div> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Basic Test Suite</title> | ||
<!-- Load local QUnit. --> | ||
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css" media="screen"> | ||
<script src="../node_modules/qunitjs/qunit/qunit.js"></script> | ||
<!-- Load local lib and tests. --> | ||
<script src="../node_modules/axe-core/axe.min.js"></script> | ||
<script src="a11y.js"></script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"> | ||
</div> | ||
<div id="working"> | ||
<label for="labelfld">Label for this text field.</label> | ||
<input type="text" id="labelfld"> | ||
</div> | ||
<div id="broken"> | ||
<p>Label for this text field.</p> | ||
<input type="text" id="nolabelfld"> | ||
</div> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,8 @@ function isClipped(clip) { | |
*/ | ||
dom.isVisible = function(el, screenReader, recursed) { | ||
'use strict'; | ||
var style, nodeName, parent; | ||
const node = axe.utils.getNodeFromTree(el); | ||
const cacheName = 'isVisible' + (screenReader ? 'ScreenReader' : ''); | ||
straker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 9 === Node.DOCUMENT | ||
if (el.nodeType === 9) { | ||
|
@@ -45,12 +46,16 @@ dom.isVisible = function(el, screenReader, recursed) { | |
el = el.host; // grab the host Node | ||
} | ||
|
||
style = window.getComputedStyle(el, null); | ||
if (node && typeof node[cacheName] !== 'undefined') { | ||
return node[cacheName]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add 2 tests:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to use this comment to group all the tests for caching comments. We already have code that tests that all of these functions are working as expected. Is there a particular reason you would like the unit tests to be tied to how the function was implemented internally? One of the nice things about these drastic code changes (especially for IMO, we shouldn't test the internals of a function as the internals can easily change, creating fragile tests. We should only test that the function returns an expected set of outputs for a given set of inputs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough :) |
||
} | ||
|
||
const style = window.getComputedStyle(el, null); | ||
if (style === null) { | ||
return false; | ||
} | ||
|
||
nodeName = el.nodeName.toUpperCase(); | ||
const nodeName = el.nodeName.toUpperCase(); | ||
|
||
if ( | ||
style.getPropertyValue('display') === 'none' || | ||
|
@@ -66,10 +71,15 @@ dom.isVisible = function(el, screenReader, recursed) { | |
return false; | ||
} | ||
|
||
parent = el.assignedSlot ? el.assignedSlot : el.parentNode; | ||
const parent = el.assignedSlot ? el.assignedSlot : el.parentNode; | ||
let isVisible = false; | ||
if (parent) { | ||
return dom.isVisible(parent, screenReader, true); | ||
isVisible = dom.isVisible(parent, screenReader, true); | ||
} | ||
|
||
return false; | ||
if (node) { | ||
node[cacheName] = isVisible; | ||
} | ||
|
||
return isVisible; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests for
axe._cache.idRefs
?