( urls: string[], ruleIds: string[], timeout: number, setupScript?: string, )
| 13 | |
| 14 | /** Creates a runner function that executes Axe accessibility audits for given URLs. */ |
| 15 | export function createRunnerFunction( |
| 16 | urls: string[], |
| 17 | ruleIds: string[], |
| 18 | timeout: number, |
| 19 | setupScript?: string, |
| 20 | ): RunnerFunction { |
| 21 | return async (): Promise<AuditOutputs> => { |
| 22 | const runner = new AxeRunner(); |
| 23 | const urlsCount = urls.length; |
| 24 | |
| 25 | logger.info( |
| 26 | `Running Axe accessibility checks for ${pluralizeToken('URL', urlsCount)} ...`, |
| 27 | ); |
| 28 | |
| 29 | try { |
| 30 | if (setupScript) { |
| 31 | const setupFn = await loadSetupScript(setupScript); |
| 32 | await runner.captureAuthState(setupFn, timeout); |
| 33 | } |
| 34 | |
| 35 | const results = await asyncSequential( |
| 36 | urls, |
| 37 | async (url, urlIndex): Promise<AxeUrlResult | null> => |
| 38 | runForUrl(runner, { urlsCount, ruleIds, timeout, url, urlIndex }), |
| 39 | ); |
| 40 | |
| 41 | const collectedResults = results.filter(res => res != null); |
| 42 | const auditOutputs = collectedResults.flatMap(res => res.auditOutputs); |
| 43 | if (collectedResults.length === 0) { |
| 44 | throw new Error( |
| 45 | shouldExpandForUrls(urlsCount) |
| 46 | ? 'Axe failed to produce results for all URLs.' |
| 47 | : 'Axe did not produce any results.', |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | logResultsForAllUrls(collectedResults); |
| 52 | |
| 53 | return auditOutputs; |
| 54 | } finally { |
| 55 | await runner.close(); |
| 56 | } |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | async function runForUrl( |
| 61 | runner: AxeRunner, |
nothing calls this directly
no test coverage detected