Skip to content

Commit

Permalink
chore: Ensure relatedNodes fallback uses arrays (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Nov 14, 2022
1 parent 1ba58eb commit a37db59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lib/core/reporters/helpers/process-aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function normalizeRelatedNodes(node, options) {
res.element = relatedNode?.element ?? null;
}
if (options.selectors !== false || relatedNode?.fromFrame) {
res.target = relatedNode?.selector ?? ':root';
res.target = relatedNode?.selector ?? [':root'];
}
if (options.ancestry) {
res.ancestry = relatedNode?.ancestry ?? ':root';
res.ancestry = relatedNode?.ancestry ?? [':root'];
}
if (options.xpath) {
res.xpath = relatedNode?.xpath ?? '/';
res.xpath = relatedNode?.xpath ?? ['/'];
}
return res;
});
Expand Down
55 changes: 28 additions & 27 deletions test/core/reporters/helpers/process-aggregate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe('helpers.processAggregate', function () {
'use strict';
var results, options;
const helpers = axe._thisWillBeDeletedDoNotUse.helpers;

beforeEach(function () {
results = [
Expand All @@ -11,21 +12,21 @@ describe('helpers.processAggregate', function () {
result: 'passed',
node: {
element: document.createElement('div'),
selector: 'header > .thing',
selector: ['header > .thing'],
source: '<div class="thing">Thing</div>',
xpath: '/header/div[@class="thing"]',
ancestry: 'html > body > header > div'
xpath: ['/header/div[@class="thing"]'],
ancestry: ['html > body > header > div']
},
any: [
{
id: 'passed-rule',
relatedNodes: [
{
element: document.createElement('div'),
selector: 'footer > .thing',
selector: ['footer > .thing'],
source: '<div class="thing">Thing</div>',
xpath: '/footer/div[@class="thing"]',
ancestry: 'html > body > footer > div'
xpath: ['/footer/div[@class="thing"]'],
ancestry: ['html > body > footer > div']
}
]
}
Expand All @@ -37,21 +38,21 @@ describe('helpers.processAggregate', function () {
result: 'passed',
node: {
element: document.createElement('div'),
selector: 'main > .thing',
selector: ['main > .thing'],
source: '<div class="thing">Thing</div>',
xpath: '/main/div[@class="thing"]',
ancestry: 'html > body > main > div'
xpath: ['/main/div[@class="thing"]'],
ancestry: ['html > body > main > div']
},
any: [
{
id: 'passed-rule',
relatedNodes: [
{
element: document.createElement('div'),
selector: 'footer > .thing',
selector: ['footer > .thing'],
source: '<div class="thing">Thing</div>',
xpath: '/footer/div[@class="thing"]',
ancestry: 'html > body > footer > div'
xpath: ['/footer/div[@class="thing"]'],
ancestry: ['html > body > footer > div']
}
]
}
Expand All @@ -70,10 +71,10 @@ describe('helpers.processAggregate', function () {
{
result: 'failed',
node: {
selector: '#dopel',
source: '<input id="dopel"/>',
selector: ['#dopel'],
source: ['<input id="dopel"/>'],
xpath: '/main/input[@id="dopel"]',
ancestry: 'html > body > main > input:nth-child(1)',
ancestry: ['html > body > main > input:nth-child(1)'],
fromFrame: true
},
any: [
Expand All @@ -83,9 +84,9 @@ describe('helpers.processAggregate', function () {
{
element: document.createElement('input'),
selector: '#dopel',
source: '<input id="dopel"/>',
xpath: '/main/input[@id="dopel"]',
ancestry: 'html > body > main > input:nth-child(2)',
source: ['<input id="dopel"/>'],
xpath: ['/main/input[@id="dopel"]'],
ancestry: ['html > body > main > input:nth-child(2)'],
fromFrame: true
}
]
Expand All @@ -97,10 +98,10 @@ describe('helpers.processAggregate', function () {
{
result: 'failed',
node: {
selector: '#dopell',
selector: ['#dopell'],
source: '<input id="dopell"/>',
xpath: '/header/input[@id="dopell"]',
ancestry: 'html > body > main > input:nth-child(1)',
xpath: ['/header/input[@id="dopell"]'],
ancestry: ['html > body > main > input:nth-child(1)'],
fromFrame: true
},
any: [
Expand All @@ -109,10 +110,10 @@ describe('helpers.processAggregate', function () {
relatedNodes: [
{
element: document.createElement('input'),
selector: '#dopell',
selector: ['#dopell'],
source: '<input id="dopell"/>',
xpath: '/header/input[@id="dopell"]',
ancestry: 'html > body > main > input:nth-child(2)',
xpath: ['/header/input[@id="dopell"]'],
ancestry: ['html > body > main > input:nth-child(2)'],
fromFrame: true
}
]
Expand Down Expand Up @@ -168,9 +169,9 @@ describe('helpers.processAggregate', function () {
const { relatedNodes } = resultObject.violations[0].nodes[0].any[0];
assert.deepEqual(relatedNodes[0], {
html: 'Undefined',
target: ':root',
ancestry: ':root',
xpath: '/',
target: [':root'],
ancestry: [':root'],
xpath: ['/'],
element: null
});
});
Expand Down

0 comments on commit a37db59

Please sign in to comment.