diff --git a/axe.d.ts b/axe.d.ts index 1b72075138..2ea753c1fe 100644 --- a/axe.d.ts +++ b/axe.d.ts @@ -13,6 +13,38 @@ declare namespace axe { type resultGroups = 'inapplicable' | 'passes' | 'incomplete' | 'violations'; + type AriaAttrsType = + | 'boolean' + | 'nmtoken' + | 'mntokens' + | 'idref' + | 'idrefs' + | 'string' + | 'decimal' + | 'int'; + + type AriaRolesType = 'abstract' | 'widget' | 'structure' | 'landmark'; + + type DpubRolesType = + | 'section' + | 'landmark' + | 'link' + | 'listitem' + | 'img' + | 'navigation' + | 'note' + | 'separator' + | 'none' + | 'sectionhead'; + + type HtmlContentTypes = + | 'flow' + | 'sectioning' + | 'heading' + | 'phrasing' + | 'embedded' + | 'interactive'; + type ContextObject = { include?: string[] | string[][]; exclude?: string[] | string[][]; @@ -40,17 +72,22 @@ declare namespace axe { type: RunOnlyType; values: TagValue[] | string[]; } + interface RuleObject { + [key: string]: { + enabled: boolean; + }; + } interface RunOptions { runOnly?: RunOnly | TagValue[] | string[]; - rules?: Object; - iframes?: boolean; - elementRef?: boolean; - selectors?: boolean; - resultTypes?: resultGroups[]; + rules?: RuleObject; reporter?: ReporterVersion; + resultTypes?: resultGroups[]; + selectors?: boolean; + ancestry?: boolean; xpath?: boolean; absolutePaths?: boolean; - restoreScroll?: boolean; + iframes?: boolean; + elementRef?: boolean; frameWaitTime?: number; preload?: boolean; performanceTimer?: boolean; @@ -81,6 +118,7 @@ declare namespace axe { impact?: ImpactValue; target: string[]; xpath?: string[]; + ancestry?: string[]; any: CheckResult[]; all: CheckResult[]; none: CheckResult[]; @@ -106,8 +144,8 @@ declare namespace axe { } interface CheckLocale { [key: string]: { - pass: string; - fail: string; + pass: string | { [key: string]: string }; + fail: string | { [key: string]: string }; incomplete: string | { [key: string]: string }; }; } @@ -116,6 +154,39 @@ declare namespace axe { rules?: RuleLocale; checks?: CheckLocale; } + interface AriaAttrs { + type: AriaAttrsType; + values?: string[]; + allowEmpty?: boolean; + global?: boolean; + unsupported?: boolean; + } + interface AriaRoles { + type: AriaRolesType | DpubRolesType; + requiredContext?: string[]; + requiredOwned?: string[]; + requiredAttrs?: string[]; + allowedAttrs?: string[]; + nameFromContent?: boolean; + unsupported?: boolean; + } + interface HtmlElmsVariant { + contentTypes?: HtmlContentTypes[]; + allowedRoles: boolean | string[]; + noAriaAttrs?: boolean; + shadowRoot?: boolean; + implicitAttrs?: { [key: string]: string }; + namingMethods?: string[]; + } + interface HtmlElms extends HtmlElmsVariant { + variant?: { [key: string]: HtmlElmsVariant }; + } + interface Standards { + ariaAttrs?: { [key: string]: AriaAttrs }; + ariaRoles?: { [key: string]: AriaRoles }; + htmlElms?: { [key: string]: HtmlElms }; + cssColors?: { [key: string]: number[] }; + } interface Spec { branding?: { brand?: string; @@ -124,6 +195,7 @@ declare namespace axe { reporter?: ReporterVersion; checks?: Check[]; rules?: Rule[]; + standards?: Standards; locale?: Locale; disableOtherRules?: boolean; axeVersion?: string; @@ -168,6 +240,7 @@ declare namespace axe { tags: string[]; } + let version: string; let plugins: any; /** diff --git a/typings/axe-core/axe-core-tests.ts b/typings/axe-core/axe-core-tests.ts index f2bb960950..6dd3970163 100644 --- a/typings/axe-core/axe-core-tests.ts +++ b/typings/axe-core/axe-core-tests.ts @@ -2,6 +2,7 @@ import * as axe from '../../axe'; var context: any = document; var $fixture: any = {}; +var options = { iframes: false, selectors: false, elementRef: false }; axe.run(context, {}, (error: Error, results: axe.AxeResults) => { if (error) { @@ -17,13 +18,9 @@ axe.run().then(function(done: any) { done(); }); // additional configuration options -axe.run( - context, - { iframes: false, selectors: false, elementRef: false }, - (error: Error, results: axe.AxeResults) => { - console.log(error || results.passes.length); - } -); +axe.run(context, options, (error: Error, results: axe.AxeResults) => { + console.log(error || results.passes.length); +}); // axe.run include/exclude axe.run( { include: [['#id1'], ['#id2']] }, @@ -40,13 +37,9 @@ axe.run( } ); // additional configuration options -axe.run( - context, - { iframes: false, selectors: false, elementRef: false }, - (error: Error, results: axe.AxeResults) => { - console.log(error || results.passes.length); - } -); +axe.run(context, options, (error: Error, results: axe.AxeResults) => { + console.log(error || results.passes.length); +}); var tagConfigRunOnly: axe.RunOnly = { type: 'tag', values: ['wcag2a'] @@ -90,14 +83,43 @@ axe.run( var someRulesConfig = { rules: { - 'color-contrast': { enabled: 'false' }, - 'heading-order': { enabled: 'true' } + 'color-contrast': { enabled: false }, + 'heading-order': { enabled: true } } }; axe.run(context, someRulesConfig, (error: Error, results: axe.AxeResults) => { console.log(error || results); }); +// just context +axe.run(context).then(function(done: any) { + done(); +}); +// just options +axe.run(options).then(function(done: any) { + done(); +}); +// just callback +axe.run((error: Error, results: axe.AxeResults) => { + console.log(error || results); +}); +// context and callback +axe.run(context, (error: Error, results: axe.AxeResults) => { + console.log(error || results); +}); +// options and callback +axe.run(options, (error: Error, results: axe.AxeResults) => { + console.log(error || results); +}); +// context and options +axe.run(context, options).then(function(done: any) { + done(); +}); +// context, options, and callback +axe.run(context, options, (error: Error, results: axe.AxeResults) => { + console.log(error || results); +}); + // axe.configure var spec: axe.Spec = { branding: { @@ -113,6 +135,28 @@ var spec: axe.Spec = { } } ], + standards: { + ariaRoles: { + 'custom-role': { + type: 'widget', + requiredAttrs: ['aria-label'] + } + }, + ariaAttrs: { + 'custom-attr': { + type: 'boolean' + } + }, + htmlElms: { + 'custom-elm': { + contentTypes: ['flow'], + allowedRoles: false + } + }, + cssColors: { + customColor: [0, 1, 2, 3] + } + }, rules: [ { id: 'custom-rule', @@ -123,6 +167,7 @@ var spec: axe.Spec = { axe.configure(spec); var source = axe.source; +var version = axe.version; axe.reset();