diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2910f80a7..52ec07bd5b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -109,7 +109,7 @@ grunt build ### aXe Development -The TypeScript definition file for axe-core is distributed with this module [axe.d.ts](./axe.d.ts). It currently supports TypeScript 2.0+. +The TypeScript definition file for axe-core is distributed with this module and can be found in [axe.d.ts](./axe.d.ts). It currently supports TypeScript 2.0+. To maintain aXe support for TypeScript you must first install it (globally recommended): ``` @@ -135,4 +135,4 @@ describe('Module', () => { }); }); }); -``` \ No newline at end of file +``` diff --git a/axe.d.ts b/axe.d.ts index 7c5ea81be5..87e563fa92 100644 --- a/axe.d.ts +++ b/axe.d.ts @@ -1,24 +1,24 @@ -// Type definitions for axe-core 2.0.8 +// Type definitions for axe-core 2.1.x // Project: https://github.com/dequelabs/axe-core // Definitions by: Marcy Sutton declare module axe { - export type ImpactValue = "minor" | "moderate" | "serious" | "critical"; + type ImpactValue = "minor" | "moderate" | "serious" | "critical"; - export type TagValue = "wcag2a" | "wcag2aa" | "section508" | "best-practice"; + type TagValue = "wcag2a" | "wcag2aa" | "section508" | "best-practice"; - export type ReporterVersion = "v1" | "v2"; + type ReporterVersion = "v1" | "v2"; - export type RunOnlyType = "rule" | "rules" | "tag" | "tags"; + type RunOnlyType = "rule" | "rules" | "tag" | "tags"; - export interface ElementContext { + interface ElementContext { node?: Object, selector?: string, include?: any[], exclude?: any[] } - export interface RunOnly { + interface RunOnly { type: RunOnlyType, value?: { include?: string[], @@ -26,13 +26,15 @@ declare module axe { } values?: TagValue[] } - export interface AxeResults { + interface AxeResults { url: string, timestamp: string, - passes: Pass[], - violations: Violation[] + passes: Result[], + violations: Result[], + incomplete: Result[], + inapplicable: Result[] } - export interface Pass { + interface Result { description: string, help: string, helpUrl: string, @@ -41,16 +43,7 @@ declare module axe { tags: TagValue[], nodes: NodeResult[] } - export interface Violation { - description: string, - help: string, - helpUrl: string, - id: string, - impact: ImpactValue, - tags: TagValue[], - nodes: NodeResult[] - } - export interface NodeResult { + interface NodeResult { html: string, impact: ImpactValue, target: string[], @@ -58,18 +51,18 @@ declare module axe { all: CheckResult[], none: CheckResult[] } - export interface CheckResult { + interface CheckResult { id: string, impact: string, message: string, data: any, relatedNodes?: RelatedNode[] } - export interface RelatedNode { + interface RelatedNode { target: string[], html: string } - export interface Spec { + interface Spec { branding?: { brand: string, application: string @@ -78,7 +71,7 @@ declare module axe { checks?: Check[], rules?: Rule[] } - export interface Check { + interface Check { id: string, evaluate: Function, after?: Function, @@ -86,7 +79,7 @@ declare module axe { matches?: string, enabled?: boolean } - export interface Rule { + interface Rule { id: string, selector?: string, excludeHidden?: boolean, @@ -98,7 +91,7 @@ declare module axe { tags?: string[], matches?: string } - export interface AxePlugin { + interface AxePlugin { id: string, run(...args:any[]): any, commands: { @@ -108,17 +101,27 @@ declare module axe { cleanup?(callback:Function): void } - export let plugins: any + let plugins: any /** * Source string to use as an injected script in Selenium */ - export let source: string + let source: string /** * Object for aXe Results */ - export var AxeResults: AxeResults + var AxeResults: AxeResults + + /** + * Runs a number of rules against the provided HTML page and returns the resulting issue list + * + * @param {Object} context Optional The `Context` specification object @see Context + * @param {Array} options Optional Options passed into rules or checks, temporarily modifying them. + * @param {Function} callback Optional The function to invoke when analysis is complete. + * @returns {any} results If the callback was not defined, aXe will return a Promise instead. + */ + function run(context?: ElementContext, options?: {runOnly?: RunOnly, rules?: Object}, callback?: (error: Error, results:AxeResults) => void): any /** * Starts analysis on the current document and its subframes @@ -128,37 +131,37 @@ declare module axe { * @param {Function} callback The function to invoke when analysis is complete. * @returns {Object} results The aXe results object */ - export function a11yCheck(context: ElementContext, options: {runOnly?: RunOnly, rules?: Object}, callback: (results:AxeResults) => void): AxeResults + function a11yCheck(context: ElementContext, options: {runOnly?: RunOnly, rules?: Object}, callback: (results:AxeResults) => void): AxeResults /** * Method for configuring the data format used by aXe. Helpful for adding new * rules, which must be registered with the library to execute. * @param {Spec} Spec Object with valid `branding`, `reporter`, `checks` and `rules` data */ - export function configure(spec: Spec): void + function configure(spec: Spec): void /** * Searches and returns rules that contain a tag in the list of tags. * @param {Array} tags Optional array of tags * @return {Array} Array of rules */ - export function getRules(tags?: string[]): Object[] + function getRules(tags?: string[]): Object[] /** * Restores the default axe configuration */ - export function reset(): void + function reset(): void /** * Function to register a plugin configuration in document and its subframes * @param {Object} plugin A plugin configuration object */ - export function registerPlugin(plugin: AxePlugin): void + function registerPlugin(plugin: AxePlugin): void /** * Function to clean up plugin configuration in document and its subframes */ - export function cleanup(): void + function cleanup(): void } diff --git a/package.json b/package.json index 9059bbaf18..e1a7e7fb6a 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "aXe" ], "main": "axe.js", - "typings": "axe.d.ts", + "typings": "axe.d.ts", "scripts": { "build": "grunt", "test": "grunt test" diff --git a/typings/axe-core/axe-core-tests.ts b/typings/axe-core/axe-core-tests.ts index 1889b37dea..27833be4d2 100644 --- a/typings/axe-core/axe-core-tests.ts +++ b/typings/axe-core/axe-core-tests.ts @@ -3,6 +3,20 @@ import * as axe from '../../axe' var context:any = document var $fixture:any = {} +axe.run(context, {}, (error: Error, results: axe.AxeResults) => { + if (error) { + console.log(error); + } + console.log(results.passes.length); + console.log(results.incomplete.length); + console.log(results.inapplicable.length); + console.log(results.violations.length); +}); + +axe.run().then(function(done) { + done(); +}); + // axe.a11yCheck config axe.a11yCheck(context, {}, (results: axe.AxeResults) => { // axe's results object diff --git a/typings/axe-core/axe-core.d.ts b/typings/axe-core/axe-core.d.ts deleted file mode 100644 index 98818e75cc..0000000000 --- a/typings/axe-core/axe-core.d.ts +++ /dev/null @@ -1,159 +0,0 @@ -// Type definitions for axe-core 2.0.5 -// Project: https://github.com/dequelabs/axe-core -// Definitions by: Marcy Sutton -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace axe { - - export type ImpactValue = "minor" | "moderate" | "serious" | "critical"; - - export type TagValue = "wcag2a" | "wcag2aa" | "section508" | "best-practice"; - - export type ReporterVersion = "v1" | "v2"; - - export type RunOnlyType = "rule" | "rules" | "tag" | "tags"; - - export interface ElementContext { - node?: Object, - selector?: string, - include?: any[], - exclude?: any[] - } - export interface RunOnly { - type: RunOnlyType, - value?: { - include?: string[], - exclude?: string[] - } - values?: TagValue[] - } - export interface AxeResults { - url: string, - timestamp: string, - passes: Pass[], - violations: Violation[] - } - export interface Pass { - description: string, - help: string, - helpUrl: string, - id: string, - impact: ImpactValue, - tags: TagValue[], - nodes: NodeResult[] - } - export interface Violation { - description: string, - help: string, - helpUrl: string, - id: string, - impact: ImpactValue, - tags: TagValue[], - nodes: NodeResult[] - } - export interface NodeResult { - html: string, - impact: ImpactValue, - target: string[], - any: CheckResult[], - all: CheckResult[], - none: CheckResult[] - } - export interface CheckResult { - id: string, - impact: string, - message: string, - data: any, - relatedNodes?: RelatedNode[] - } - export interface RelatedNode { - target: string[], - html: string - } - export interface Spec { - branding?: { - brand: string, - application: string - }, - reporter?: ReporterVersion, - checks?: Check[], - rules?: Rule[] - } - export interface Check { - id: string, - evaluate: Function, - after?: Function, - options?: any, - matches?: string, - enabled?: boolean - } - export interface Rule { - id: string, - selector?: string, - excludeHidden?: boolean, - enabled?: boolean, - pageLevel?: boolean, - any?: string[], - all?: string[], - none?: string[], - tags?: string[], - matches?: string - } - export interface AxePlugin { - id: string, - run(...args:any[]): any, - commands: { - id: string, - callback(...args:any[]): void - }[], - cleanup?(callback:Function): void - } - - export let plugins: any - - /** - * Starts analysis on the current document and its subframes - * - * @param {Object} context The `Context` specification object @see Context - * @param {Array} options Options passed into rules or checks, temporarily modifyint them. - * @param {Function} callback The function to invoke when analysis is complete. - * @returns {Object} results The aXe results object - */ - export function a11yCheck(context: ElementContext, options: {runOnly?: RunOnly, rules?: Object}, callback: (results:AxeResults) => void): AxeResults - - /** - * Method for configuring the data format used by aXe. Helpful for adding new - * rules, which must be registered with the library to execute. - * @param {Spec} Spec Object with valid `branding`, `reporter`, `checks` and `rules` data - */ - export function configure(spec: Spec): void - - /** - * Searches and returns rules that contain a tag in the list of tags. - * @param {Array} tags Optional array of tags - * @return {Array} Array of rules - */ - export function getRules(tags?: string[]): Object[] - - /** - * Restores the default axe configuration - */ - export function reset(): void - - /** - * Function to register a plugin configuration in document and its subframes - * @param {Object} plugin A plugin configuration object - */ - export function registerPlugin(plugin: AxePlugin): void - - /** - * Function to clean up plugin configuration in document and its subframes - */ - export function cleanup(): void - -} - -// axe is also available as a module -declare module "axe-core" { - export = axe; -}