Skip to content

Commit

Permalink
fix(finishRun): handle null for failed iframe results (#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jul 26, 2021
1 parent 90f0b27 commit 8947099
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/core/public/finish-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export default function finishRun(partialResults, options = {}) {
function setFrameSpec(partialResults) {
const frameStack = [];
for (const partialResult of partialResults) {
partialResult.frameSpec = frameStack.shift() ?? null;
const frameSpec = frameStack.shift();
if (!partialResult) {
continue;
}

partialResult.frameSpec = frameSpec ?? null;
const frameSpecs = getMergedFrameSpecs(partialResult);
frameStack.unshift(...frameSpecs);
}
Expand Down
29 changes: 29 additions & 0 deletions test/core/public/finish-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,35 @@ describe('axe.finishRun', function() {
})
.catch(done);
});

it('should handle null results and set target correctly', function(done) {
var windows = [window];
fixture.innerHTML = '<h1></h1>';
createIframe('<h2></h2>')
.then(function(frameWin) {
windows.push(frameWin);
return createIframe('<h3></h3>');
})
.then(function(nestedWin) {
windows.push(nestedWin);
var promisedResults = windows.map(function(win) {
return win.axe.runPartial({ runOnly: 'empty-heading' });
});
return Promise.all(promisedResults);
})
.then(function(partialResults) {
partialResults[1] = null;
return partialResults;
})
.then(axe.finishRun)
.then(function(results) {
var nodes = results.violations[0].nodes;
assert.deepEqual(nodes[0].target, ['h1']);
assert.deepEqual(nodes[1].target, ['iframe:nth-child(3)', 'h3']);
done();
})
.catch(done);
});
});

describe('calling audit.after', function() {
Expand Down

0 comments on commit 8947099

Please sign in to comment.