Skip to content
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

fix: get shadow DOM tests all passing #457

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Audit.prototype.run = function (context, options, resolve, reject) {
'use strict';
this.validateOptions(options);

axe._tree = axe.utils.getFlattenedTree(document.body); //cache the flattened tree
axe._tree = axe.utils.getFlattenedTree(document.documentElement); //cache the flattened tree
var q = axe.utils.queue();
this.rules.forEach(function (rule) {
if (axe.utils.ruleShouldRun(rule, context, options)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ axe.utils.getFlattenedTree = function (node, shadowId) {
axe.utils.getNodeFromTree = function (vNode, node) {
var found;

if (vNode.actualNode === node) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm still trying to keep these straight in my head, can you elaborate on what problem this solves?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes the additional test pass - specifically when some of our utilities look for the 'html' node in the vrtual tree, it was not being found.

return vNode;
}
vNode.children.forEach((candidate) => {
var retVal;

Expand Down
2 changes: 1 addition & 1 deletion test/checks/navigation/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('region', function () {
});

it('ignores native landmark elements with an overwriting role', function () {
var checkArgs = checkSetup('<div id="target"><header role="banner"></header><main role="none"></main></div>');
var checkArgs = checkSetup('<div id="target"><header role="heading" level="1"></header><main role="none">Content</main></div>');

assert.isFalse(checks.region.evaluate.apply(checkContext, checkArgs));
assert.lengthOf(checkContext._relatedNodes, 1);
Expand Down
2 changes: 1 addition & 1 deletion test/commons/dom/is-in-text-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('dom.isInTextBlock', function () {
assert.isFalse(axe.commons.dom.isInTextBlock(link));
});

(shadowSupport ? it : xit)('can reach outside a shadow tree', function () {
(shadowSupport.v1 ? it : xit)('can reach outside a shadow tree', function () {
var div = document.createElement('div');
div.innerHTML = 'Some paragraph with text <span></span> ';
var shadow = div.querySelector('span').attachShadow({ mode: 'open' });
Expand Down
6 changes: 6 additions & 0 deletions test/core/utils/flattened-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ if (shadowSupport.v1) {
assert.equal(node, vNode.actualNode);
assert.equal(vNode.actualNode.textContent, '1');
});
it('should find the virtual node if it is the very top of the tree', function () {
var virtualDOM = axe.utils.getFlattenedTree(fixture);
var vNode = axe.utils.getNodeFromTree(virtualDOM[0], virtualDOM[0].actualNode);
assert.isDefined(vNode);
assert.equal(virtualDOM[0].actualNode, vNode.actualNode);
});
});
}

Expand Down