Skip to content

Commit

Permalink
fix(d.ts): RawNodesResult issues (#4229)
Browse files Browse the repository at this point in the history
* fix(d.ts): RawNodesResult issues

* Type tests

* More

* empty

* Fixed feedback
  • Loading branch information
WilcoFiers authored and straker committed Feb 7, 2024
1 parent 8c68546 commit f105266
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
25 changes: 19 additions & 6 deletions axe.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Type definitions for axe-core
// Project: https://github.com/dequelabs/axe-core
// Definitions by: Marcy Sutton <https://github.com/marcysutton>

declare namespace axe {
type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical' | null;
Expand Down Expand Up @@ -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';
Expand All @@ -351,16 +358,21 @@ declare namespace axe {
frameContext: FrameContextObject;
}

interface RawCheckResult extends Omit<CheckResult, 'relatedNodes'> {
relatedNodes?: Array<SerialDqElement | DqElement>;
}

interface RawNodeResult<T extends 'passed' | 'failed' | 'incomplete'> {
any: CheckResult[];
all: CheckResult[];
none: CheckResult[];
node: SerialDqElement | DqElement;
any: RawCheckResult[];
all: RawCheckResult[];
none: RawCheckResult[];
impact: ImpactValue | null;
result: T;
}

interface RawResult extends Omit<Result, 'nodes'> {
inapplicable: [];
inapplicable: Array<never>;
passes: RawNodeResult<'passed'>[];
incomplete: RawNodeResult<'incomplete'>[];
violations: RawNodeResult<'failed'>[];
Expand All @@ -383,6 +395,7 @@ declare namespace axe {
attr(attr: string): string | null;
hasAttr(attr: string): boolean;
props: { [key: string]: unknown };
boundingClientRect: DOMRect;
}

interface Utils {
Expand All @@ -396,7 +409,7 @@ declare namespace axe {
DqElement: new (
elm: Element,
options?: { absolutePaths?: boolean }
) => SerialDqElement;
) => DqElement;
uuid: (
options?: { random?: Uint8Array | Array<number> },
buf?: Uint8Array | Array<number>,
Expand Down
38 changes: 38 additions & 0 deletions typings/axe-core/axe-core-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down

0 comments on commit f105266

Please sign in to comment.