forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect-results-from-frames.js
More file actions
47 lines (42 loc) · 1.46 KB
/
Copy pathcollect-results-from-frames.js
File metadata and controls
47 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import queue from './queue';
import sendCommandToFrame from './send-command-to-frame';
import mergeResults from './merge-results';
/**
* Sends a message to axe running in frames to start analysis and collate results (via `mergeResults`)
* @private
* @param {Context} parentContent The resolved Context object
* @param {Object} options Options object (as passed to `runRules`)
* @param {string} command Command sent to all frames
* @param {Array} parameter Array of values to be passed along side the command
* @param {Function} callback Function to call when results from all frames have returned
*/
export default function collectResultsFromFrames(
parentContent,
options,
command,
parameter,
resolve,
reject
) {
// elementRefs can't be passed across frame boundaries
options = { ...options, elementRef: false };
const q = queue();
const frames = parentContent.frames;
// Tell each axe running in each frame to collect results
frames.forEach(({ node: frameElement, ...context }) => {
q.defer((res, rej) => {
const params = { options, command, parameter, context };
function callback(results) {
if (!results) {
return res(null);
}
return res({ results, frameElement });
}
sendCommandToFrame(frameElement, params, callback, rej);
});
});
// Combine results from all frames and give it back
q.then(data => {
resolve(mergeResults(data, options));
}).catch(reject);
}