From d6605181ec942bcca46e3bfe889064b3781919ca Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Thu, 2 Nov 2023 14:17:48 +0100 Subject: [PATCH] fix(d.ts): RawNodesResult issues (#4229) * fix(d.ts): RawNodesResult issues * Type tests * More * empty * Fixed feedback --- axe.d.ts | 25 +++++++++++++++----- typings/axe-core/axe-core-tests.ts | 38 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/axe.d.ts b/axe.d.ts index 403e504873..7f33941d94 100644 --- a/axe.d.ts +++ b/axe.d.ts @@ -1,6 +1,5 @@ // Type definitions for axe-core // Project: https://github.com/dequelabs/axe-core -// Definitions by: Marcy Sutton declare namespace axe { type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical' | null; @@ -333,6 +332,14 @@ declare namespace axe { xpath: string[]; ancestry: UnlabelledFrameSelector; } + interface DqElement extends SerialDqElement { + element: Element; + toJSON(): SerialDqElement; + mergeSpecs( + childSpec: SerialDqElement, + parentSpec: SerialDqElement + ): SerialDqElement; + } interface PartialRuleResult { id: string; result: 'inapplicable'; @@ -351,16 +358,21 @@ declare namespace axe { frameContext: FrameContextObject; } + interface RawCheckResult extends Omit { + relatedNodes?: Array; + } + interface RawNodeResult { - any: CheckResult[]; - all: CheckResult[]; - none: CheckResult[]; + node: SerialDqElement | DqElement; + any: RawCheckResult[]; + all: RawCheckResult[]; + none: RawCheckResult[]; impact: ImpactValue | null; result: T; } interface RawResult extends Omit { - inapplicable: []; + inapplicable: Array; passes: RawNodeResult<'passed'>[]; incomplete: RawNodeResult<'incomplete'>[]; violations: RawNodeResult<'failed'>[]; @@ -383,6 +395,7 @@ declare namespace axe { attr(attr: string): string | null; hasAttr(attr: string): boolean; props: { [key: string]: unknown }; + boundingClientRect: DOMRect; } interface Utils { @@ -396,7 +409,7 @@ declare namespace axe { DqElement: new ( elm: Element, options?: { absolutePaths?: boolean } - ) => SerialDqElement; + ) => DqElement; uuid: ( options?: { random?: Uint8Array | Array }, buf?: Uint8Array | Array, diff --git a/typings/axe-core/axe-core-tests.ts b/typings/axe-core/axe-core-tests.ts index bff4ec46da..094b30d64c 100644 --- a/typings/axe-core/axe-core-tests.ts +++ b/typings/axe-core/axe-core-tests.ts @@ -344,6 +344,44 @@ axe.configure({ } }); +const results: axe.RawResult[] = [ + { + id: 'the-best-rule', + result: 'passed', + pageLevel: false, + impact: null, + tags: ['best-practice'], + description: 'Be cool', + help: 'No, cooler', + helpUrl: + 'https://dequeuniversity.com/rules/axe/4.8/the-best-rule?application=axeAPI', + inapplicable: [], + passes: [ + { + any: [ + { + id: 'the-best-check', + data: null, + impact: 'serious', + message: 'Element has sufficient color contrast of 21', + relatedNodes: [ + new axe.utils.DqElement(document.body), + new axe.utils.DqElement(document.body).toJSON() + ] + } + ], + all: [], + none: [], + impact: null, + result: 'passed', + node: new axe.utils.DqElement(document.body) + } + ], + incomplete: [], + violations: [] + } +]; + // Reporters let fooReporter = ( results: axe.RawResult[],