Skip to content

Commit

Permalink
fix: validate typescript declarations using tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeyyy authored Jul 28, 2018
1 parent b4936f7 commit b8a69a5
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 155 deletions.
183 changes: 94 additions & 89 deletions axe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,126 +2,125 @@
// Project: https://github.com/dequelabs/axe-core
// Definitions by: Marcy Sutton <https://github.com/marcysutton>

declare module axe {
declare namespace axe {
type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical';

type ImpactValue = "minor" | "moderate" | "serious" | "critical";
type TagValue = 'wcag2a' | 'wcag2aa' | 'section508' | 'best-practice';

type TagValue = "wcag2a" | "wcag2aa" | "section508" | "best-practice";
type ReporterVersion = 'v1' | 'v2';

type ReporterVersion = "v1" | "v2";
type RunOnlyType = 'rule' | 'rules' | 'tag' | 'tags';

type RunOnlyType = "rule" | "rules" | "tag" | "tags";

type resultGroups = "inapplicable" | "passes" | "incomplete" | "violations";
type resultGroups = 'inapplicable' | 'passes' | 'incomplete' | 'violations';

type RunOnlyObject = {
include?: string[] | string[][],
exclude?: string[] | string[][]
}
include?: string[] | string[][];
exclude?: string[] | string[][];
};

type RunCallback = (error: Error, results: AxeResults) => void;

type ElementContext = Node | string | RunOnlyObject;

interface RunOnly {
type: RunOnlyType,
values?: TagValue[] | string[]
type: RunOnlyType;
values?: TagValue[] | string[] | RunOnlyObject;
}
interface RunOptions {
runOnly?: RunOnly,
rules?: Object,
iframes?: boolean,
elementRef?: boolean,
selectors?: boolean,
resultTypes?: resultGroups[],
runOnly?: RunOnly;
rules?: Object;
iframes?: boolean;
elementRef?: boolean;
selectors?: boolean;
resultTypes?: resultGroups[];
}
interface AxeResults {
url: string,
timestamp: string,
passes: Result[],
violations: Result[],
incomplete: Result[],
inapplicable: Result[]
url: string;
timestamp: string;
passes: Result[];
violations: Result[];
incomplete: Result[];
inapplicable: Result[];
}
interface Result {
description: string,
help: string,
helpUrl: string,
id: string,
impact: ImpactValue,
tags: TagValue[],
nodes: NodeResult[]
description: string;
help: string;
helpUrl: string;
id: string;
impact: ImpactValue;
tags: TagValue[];
nodes: NodeResult[];
}
interface NodeResult {
html: string,
impact: ImpactValue,
target: string[],
any: CheckResult[],
all: CheckResult[],
none: CheckResult[],
failureSummary?: string
html: string;
impact: ImpactValue;
target: string[];
any: CheckResult[];
all: CheckResult[];
none: CheckResult[];
failureSummary?: string;
}
interface CheckResult {
id: string,
impact: string,
message: string,
data: any,
relatedNodes?: RelatedNode[]
id: string;
impact: string;
message: string;
data: any;
relatedNodes?: RelatedNode[];
}
interface RelatedNode {
target: string[],
html: string
target: string[];
html: string;
}
interface Spec {
branding?: {
brand: string,
application: string
},
reporter?: ReporterVersion,
checks?: Check[],
rules?: Rule[]
brand: string;
application: string;
};
reporter?: ReporterVersion;
checks?: Check[];
rules?: Rule[];
}
interface Check {
id: string,
evaluate: Function | string,
after?: Function | string,
options?: any,
matches?: string,
enabled?: boolean
id: string;
evaluate: Function | string;
after?: Function | string;
options?: any;
matches?: string;
enabled?: boolean;
}
interface Rule {
id: string,
selector?: string,
excludeHidden?: boolean,
enabled?: boolean,
pageLevel?: boolean,
any?: string[],
all?: string[],
none?: string[],
tags?: string[],
matches?: string
id: string;
selector?: string;
excludeHidden?: boolean;
enabled?: boolean;
pageLevel?: boolean;
any?: string[];
all?: string[];
none?: string[];
tags?: string[];
matches?: string;
}
interface AxePlugin {
id: string,
run(...args: any[]): any,
id: string;
run(...args: any[]): any;
commands: {
id: string,
callback(...args: any[]): void
}[],
cleanup?(callback: Function): void
id: string;
callback(...args: any[]): void;
}[];
cleanup?(callback: Function): void;
}

let plugins: any
let plugins: any;

/**
* Source string to use as an injected script in Selenium
*/
let source: string
let source: string;

/**
* Object for aXe Results
*/
var AxeResults: AxeResults
var AxeResults: AxeResults;

/**
* Runs a number of rules against the provided HTML page and returns the resulting issue list
Expand All @@ -131,44 +130,50 @@ declare module axe {
* @param {RunCallback} callback Optional The function to invoke when analysis is complete.
* @returns {Promise<AxeResults>|void} If the callback was not defined, aXe will return a Promise.
*/
function run(context?: ElementContext): Promise<AxeResults>
function run(options: RunOptions): Promise<AxeResults>
function run(callback: (error: Error, results: AxeResults) => void): void
function run(context: ElementContext, callback: RunCallback): void
function run(options: RunOptions, callback: RunCallback): void
function run(context: ElementContext, options: RunOptions): Promise<AxeResults>
function run(context: ElementContext, options: RunOptions, callback: RunCallback): void
function run(context?: ElementContext): Promise<AxeResults>;
function run(options: RunOptions): Promise<AxeResults>;
function run(callback: (error: Error, results: AxeResults) => void): void;
function run(context: ElementContext, callback: RunCallback): void;
function run(options: RunOptions, callback: RunCallback): void;
function run(
context: ElementContext,
options: RunOptions
): Promise<AxeResults>;
function run(
context: ElementContext,
options: RunOptions,
callback: RunCallback
): void;

/**
* 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
*/
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
*/
function getRules(tags?: string[]): Object[]
function getRules(tags?: string[]): Object[];

/**
* Restores the default axe configuration
*/
function reset(): void
function reset(): void;

/**
* Function to register a plugin configuration in document and its subframes
* @param {Object} plugin A plugin configuration object
*/
function registerPlugin(plugin: AxePlugin): void
function registerPlugin(plugin: AxePlugin): void;

/**
* Function to clean up plugin configuration in document and its subframes
*/
function cleanup(): void

function cleanup(): void;
}

export = axe;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@
},
"scripts": {
"build": "grunt",
"test": "grunt test",
"test-dts": "tsc",
"test": "npm run test-dts && grunt test",
"test-fast": "grunt test-fast",
"version": "echo \"use 'npm run release' to bump axe-core version\" && exit 1",
"prepublishOnly": "grunt build",
"postinstall": "node build/utils/postinstall.js",
"release": "standard-version -a",
"sri-update": "grunt build && node build/sri-update && git add sri-history.json",
"fmt": "prettier --write *.js '{build,doc,lib,test}/**/*.js'",
"fmt": "prettier --write *.js, **/*.ts '{build,doc,lib,test}/**/*.js'",
"precommit": "lint-staged"
},
"devDependencies": {
Expand Down Expand Up @@ -106,6 +107,7 @@
"selenium-webdriver": "~3.6.0",
"sri-toolbox": "^0.2.0",
"standard-version": "^4.2.0",
"typescript": "^2.9.2",
"uglify-js": "^3.4.4"
},
"dependencies": {},
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"noImplicitAny": true
},
"include": [
"typings/axe-core/axe-core-tests.ts"
],
"exclude": [
"node_modules"
]
}
Loading

0 comments on commit b8a69a5

Please sign in to comment.