-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playwright): Upgrade to axe-core@4.3.2 (#334)
* feat(playwright): Upgrade to axe-core@4.3.2 * add test * fix test * fix coverage * changes requested * test coverage * Update packages/playwright/package.json Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com> Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
- Loading branch information
1 parent
f803c98
commit b94c75a
Showing
10 changed files
with
458 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../node_modules/axe-test-fixtures/fixtures/ | ||
../node_modules/axe-test-fixtures/fixtures/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as axe from 'axe-core'; | ||
/** | ||
* This class parallelizes the async calls to axe.runPartial. | ||
* | ||
* In this project, most async calls needs to block execution, such as | ||
* the axeGetFrameContext() and getChildFrame() and calls. | ||
* | ||
* Unlike those calls, axe.runPartial() calls must run in parallel, so that | ||
* frame tests don't wait for each other. This is necessary to minimize the time | ||
* between when axe-core finds a frame, and when it is tested. | ||
*/ | ||
|
||
type GetPartialResultsResponse = Parameters<typeof axe.finishRun>[0]; | ||
export default class AxePartialRunner { | ||
private partialPromise: Promise<axe.PartialResult>; | ||
private childRunners: Array<AxePartialRunner | null> = []; | ||
|
||
constructor( | ||
partialPromise: Promise<axe.PartialResult>, | ||
private initiator: boolean = false | ||
) { | ||
this.partialPromise = caught(partialPromise); | ||
} | ||
|
||
public addChildResults(childResultRunner: AxePartialRunner | null): void { | ||
this.childRunners.push(childResultRunner); | ||
} | ||
|
||
public async getPartials(): Promise<GetPartialResultsResponse> { | ||
try { | ||
const parentPartial = await this.partialPromise; | ||
const childPromises = this.childRunners.map(childRunner => { | ||
return childRunner ? caught(childRunner.getPartials()) : [null]; | ||
}); | ||
const childPartials = (await Promise.all(childPromises)).flat(1); | ||
return [parentPartial, ...childPartials]; | ||
} catch (e) { | ||
if (this.initiator) { | ||
throw e; | ||
} | ||
return [null]; | ||
} | ||
} | ||
} | ||
|
||
// Utility to tell NodeJS not to worry about catching promise errors async. | ||
// See: https://stackoverflow.com/questions/40920179/should-i-refrain-from-handling-promise-rejection-asynchronously | ||
export const caught = ((f: () => void) => { | ||
return <T>(p: Promise<T>): Promise<T> => (p.catch(f), p); | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
})(() => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* istanbul ignore file */ | ||
import type { | ||
GetFrameContextsParams, | ||
RunPartialParams, | ||
FinishRunParams, | ||
ShadowSelectParams | ||
} from './types'; | ||
import { FrameContext, AxeResults, PartialResult } from 'axe-core'; | ||
import * as axeCore from 'axe-core'; | ||
|
||
// Expect axe to be set up. | ||
// Tell Typescript that there should be a global variable called `axe` that follows | ||
// the shape given by the `axe-core` typings (the `run` and `configure` functions). | ||
declare global { | ||
interface Window { | ||
axe: typeof axeCore; | ||
} | ||
} | ||
export const axeGetFrameContexts = ({ | ||
context | ||
}: GetFrameContextsParams): FrameContext[] => { | ||
return window.axe.utils.getFrameContexts(context); | ||
}; | ||
|
||
export const axeShadowSelect = ({ | ||
frameSelector | ||
}: ShadowSelectParams): Element | null => { | ||
return window.axe.utils.shadowSelect(frameSelector); | ||
}; | ||
|
||
export const axeRunPartial = ({ | ||
context, | ||
options | ||
}: RunPartialParams): Promise<PartialResult> => { | ||
return window.axe.runPartial(context, options); | ||
}; | ||
|
||
export const axeFinishRun = ({ | ||
partialResults, | ||
options | ||
}: FinishRunParams): Promise<AxeResults> => { | ||
return window.axe.finishRun(partialResults, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.