From e1d3592bb249a4f8a15f38ba75d023914ec0db50 Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Sun, 3 Jun 2018 17:41:51 -0700 Subject: [PATCH 1/2] Added axe-webdriverjs typings --- .../axe-webdriverjs/axe-webdriverjs-tests.ts | 0 types/axe-webdriverjs/index.d.ts | 79 +++++++++++++++++++ types/axe-webdriverjs/package.json | 7 ++ types/axe-webdriverjs/tsconfig.json | 22 ++++++ types/axe-webdriverjs/tslint.json | 1 + 5 files changed, 109 insertions(+) create mode 100644 types/axe-webdriverjs/axe-webdriverjs-tests.ts create mode 100644 types/axe-webdriverjs/index.d.ts create mode 100644 types/axe-webdriverjs/package.json create mode 100644 types/axe-webdriverjs/tsconfig.json create mode 100644 types/axe-webdriverjs/tslint.json diff --git a/types/axe-webdriverjs/axe-webdriverjs-tests.ts b/types/axe-webdriverjs/axe-webdriverjs-tests.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/types/axe-webdriverjs/index.d.ts b/types/axe-webdriverjs/index.d.ts new file mode 100644 index 0000000000..d8e3979145 --- /dev/null +++ b/types/axe-webdriverjs/index.d.ts @@ -0,0 +1,79 @@ +// Type definitions for axe-webdriverjs 2.0 +// Project: https://github.com/dequelabs/axe-webdriverjs#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Result, RunOptions, Spec } from "axe-core"; +import { WebDriver } from "selenium-webdriver"; + +export interface IAxeAnalysis { + inapplicable: Result[]; + incomplete: Result[]; + passes: Result[]; + timestamp: string; + url: string; + violations: Result[]; +} + +export interface AxeBuilder { + (driver: WebDriver): AxeBuilder; + new (driver: WebDriver): AxeBuilder; + + /** + * Includes a selector in analysis. + * + * @param selector CSS selector of the element to include. + */ + include(selector: string): this; + + /** + * Excludes a selector from analysis. + * + * @param selector CSS selector of the element to exclude. + */ + exclude(selector: string): this; + + /** + * Options to directly pass to `axe.run`. + * + * @param options aXe options object. + * @remarks Will override any other configured options, including calls to `withRules` and `withTags`. + */ + options(options: RunOptions): this; + + /** + * Limits analysis to only the specified rules. + * + * @param rules Array of rule IDs, or a single rule ID as a string. + * @remarks Cannot be used with `withTags`. + */ + withRules(rules: string | string[]): this; + + /** + * Limist analysis to only the specified tags. + * + * @param rules Array of tags, or a single tag as a string + * @remarks Cannot be used with `withRules`. + */ + withTags(tags: string | string[]): this; + + /** + * Set the list of rules to skip when running an analysis + * + * @param rules Array of rule IDs, or a single rule ID as a string + */ + disableRules(rules: string | string[]): this; + + /** + * Configures aXe before running analyze. + * + * @param config aXe Configuration spec to use in analysis. + */ + configure(config: Spec): this; + + /** + * Perform analysis and retrieve results. + * @param callback Function to execute when analysis completes. + */ + analyze(callback: (results: IAxeAnalysis) => void): Promise; +} diff --git a/types/axe-webdriverjs/package.json b/types/axe-webdriverjs/package.json new file mode 100644 index 0000000000..5d94289f3b --- /dev/null +++ b/types/axe-webdriverjs/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "dependencies": { + "@types/selenium-webdriver": "^3.0.0", + "axe-core": "^2.6.1" + } +} diff --git a/types/axe-webdriverjs/tsconfig.json b/types/axe-webdriverjs/tsconfig.json new file mode 100644 index 0000000000..efa6dfcf98 --- /dev/null +++ b/types/axe-webdriverjs/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "axe-webdriverjs-tests.ts" + ] +} diff --git a/types/axe-webdriverjs/tslint.json b/types/axe-webdriverjs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/axe-webdriverjs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 09831af230d8cda7def8214bdbf891ba90f0322f Mon Sep 17 00:00:00 2001 From: Joshua Goldberg Date: Tue, 5 Jun 2018 19:49:48 -0700 Subject: [PATCH 2/2] Added axe-webdriverjs typings with axe-core@3.0.3 --- notNeededPackages.json | 2 +- .../axe-webdriverjs/axe-webdriverjs-tests.ts | 31 +++++++++++++++++++ types/axe-webdriverjs/index.d.ts | 28 ++++++++++------- types/axe-webdriverjs/package.json | 3 +- types/axe-webdriverjs/tsconfig.json | 1 + types/jest-axe/package.json | 2 +- 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/notNeededPackages.json b/notNeededPackages.json index 4fb2ecedb3..a8c685e5e9 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -124,7 +124,7 @@ "libraryName": "axe-core", "typingsPackageName": "axe-core", "sourceRepoURL": "https://github.com/dequelabs/axe-core", - "asOfVersion": "2.0.7" + "asOfVersion": "3.0.3" }, { "libraryName": "axios", diff --git a/types/axe-webdriverjs/axe-webdriverjs-tests.ts b/types/axe-webdriverjs/axe-webdriverjs-tests.ts index e69de29bb2..47eeadc8c5 100644 --- a/types/axe-webdriverjs/axe-webdriverjs-tests.ts +++ b/types/axe-webdriverjs/axe-webdriverjs-tests.ts @@ -0,0 +1,31 @@ +import { Result, RunOptions, Spec } from "axe-core"; +import { AxeBuilder, AxeAnalysis } from "axe-webdriverjs"; +import { WebDriver } from "selenium-webdriver"; + +const inTest = async (webDriver: WebDriver) => { + const builderCalled: AxeBuilder = AxeBuilder(webDriver); + const builderNewed: AxeBuilder = new AxeBuilder(webDriver); + + const runOptions: RunOptions = {}; + const spec: Spec = {}; + + const analysis: AxeAnalysis = await AxeBuilder(webDriver) + .include("include") + .exclude("exclude") + .options(runOptions) + .withRules("rule") + .withRules(["rule", "rule"]) + .withTags("tag") + .withTags(["tag", "tag"]) + .disableRules("rule") + .disableRules(["rule", "rule"]) + .configure(spec) + .analyze((internalResults: AxeAnalysis) => {}); + + const inapplicable: Result[] = analysis.inapplicable; + const incomplete: Result[] = analysis.incomplete; + const passes: Result[] = analysis.passes; + const timestamp: string = analysis.timestamp; + const url: string = analysis.url; + const violations: Result[] = analysis.violations; +}; diff --git a/types/axe-webdriverjs/index.d.ts b/types/axe-webdriverjs/index.d.ts index d8e3979145..3c8ae27249 100644 --- a/types/axe-webdriverjs/index.d.ts +++ b/types/axe-webdriverjs/index.d.ts @@ -2,11 +2,12 @@ // Project: https://github.com/dequelabs/axe-webdriverjs#readme // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import { Result, RunOptions, Spec } from "axe-core"; import { WebDriver } from "selenium-webdriver"; -export interface IAxeAnalysis { +export interface AxeAnalysis { inapplicable: Result[]; incomplete: Result[]; passes: Result[]; @@ -16,9 +17,6 @@ export interface IAxeAnalysis { } export interface AxeBuilder { - (driver: WebDriver): AxeBuilder; - new (driver: WebDriver): AxeBuilder; - /** * Includes a selector in analysis. * @@ -38,21 +36,22 @@ export interface AxeBuilder { * * @param options aXe options object. * @remarks Will override any other configured options, including calls to `withRules` and `withTags`. + * @see https://github.com/dequelabs/axe-core/issues/937 */ options(options: RunOptions): this; /** * Limits analysis to only the specified rules. - * + * * @param rules Array of rule IDs, or a single rule ID as a string. * @remarks Cannot be used with `withTags`. */ withRules(rules: string | string[]): this; /** - * Limist analysis to only the specified tags. + * Limist analysis to only the specified tags. * - * @param rules Array of tags, or a single tag as a string + * @param rules Array of tags, or a single tag as a string. * @remarks Cannot be used with `withRules`. */ withTags(tags: string | string[]): this; @@ -60,7 +59,7 @@ export interface AxeBuilder { /** * Set the list of rules to skip when running an analysis * - * @param rules Array of rule IDs, or a single rule ID as a string + * @param rules Array of rule IDs, or a single rule ID as a string. */ disableRules(rules: string | string[]): this; @@ -72,8 +71,13 @@ export interface AxeBuilder { configure(config: Spec): this; /** - * Perform analysis and retrieve results. - * @param callback Function to execute when analysis completes. - */ - analyze(callback: (results: IAxeAnalysis) => void): Promise; + * Perform analysis and retrieve results. + * @param callback Function to execute when analysis completes. + */ + analyze(callback: (results: AxeAnalysis) => void): Promise; } + +export const AxeBuilder: { + (driver: WebDriver): AxeBuilder; + new (driver: WebDriver): AxeBuilder; +}; diff --git a/types/axe-webdriverjs/package.json b/types/axe-webdriverjs/package.json index 5d94289f3b..e4e88ef33a 100644 --- a/types/axe-webdriverjs/package.json +++ b/types/axe-webdriverjs/package.json @@ -1,7 +1,6 @@ { "private": true, "dependencies": { - "@types/selenium-webdriver": "^3.0.0", - "axe-core": "^2.6.1" + "axe-core": "^3.0.3" } } diff --git a/types/axe-webdriverjs/tsconfig.json b/types/axe-webdriverjs/tsconfig.json index efa6dfcf98..d8637d03e4 100644 --- a/types/axe-webdriverjs/tsconfig.json +++ b/types/axe-webdriverjs/tsconfig.json @@ -6,6 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, + "strictFunctionTypes": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ diff --git a/types/jest-axe/package.json b/types/jest-axe/package.json index d9427293a7..e4e88ef33a 100644 --- a/types/jest-axe/package.json +++ b/types/jest-axe/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "axe-core": "^2.6.1" + "axe-core": "^3.0.3" } }