Skip to content

Commit

Permalink
fix(typings): update types file (#2425)
Browse files Browse the repository at this point in the history
* fix(typings): update types file

* standards
  • Loading branch information
straker authored Jul 28, 2020
1 parent 3ccb781 commit 0aab922
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 24 deletions.
89 changes: 81 additions & 8 deletions axe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +118,7 @@ declare namespace axe {
impact?: ImpactValue;
target: string[];
xpath?: string[];
ancestry?: string[];
any: CheckResult[];
all: CheckResult[];
none: CheckResult[];
Expand All @@ -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 };
};
}
Expand All @@ -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;
Expand All @@ -124,6 +195,7 @@ declare namespace axe {
reporter?: ReporterVersion;
checks?: Check[];
rules?: Rule[];
standards?: Standards;
locale?: Locale;
disableOtherRules?: boolean;
axeVersion?: string;
Expand Down Expand Up @@ -168,6 +240,7 @@ declare namespace axe {
tags: string[];
}

let version: string;
let plugins: any;

/**
Expand Down
77 changes: 61 additions & 16 deletions typings/axe-core/axe-core-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']] },
Expand All @@ -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']
Expand Down Expand Up @@ -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: {
Expand All @@ -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',
Expand All @@ -123,6 +167,7 @@ var spec: axe.Spec = {
axe.configure(spec);

var source = axe.source;
var version = axe.version;

axe.reset();

Expand Down

0 comments on commit 0aab922

Please sign in to comment.