From 83e40f8eb3481c6de7bb81edf41ef49dbf862833 Mon Sep 17 00:00:00 2001 From: Adam Zerella Date: Sat, 28 Mar 2020 03:43:46 +1030 Subject: [PATCH] Add typing for pa11y (#43060) Co-authored-by: Adam Zerella --- types/pa11y/index.d.ts | 72 ++++++++++++++++++++++++++++++++++++++ types/pa11y/pa11y-tests.ts | 29 +++++++++++++++ types/pa11y/tsconfig.json | 26 ++++++++++++++ types/pa11y/tslint.json | 3 ++ 4 files changed, 130 insertions(+) create mode 100644 types/pa11y/index.d.ts create mode 100644 types/pa11y/pa11y-tests.ts create mode 100644 types/pa11y/tsconfig.json create mode 100644 types/pa11y/tslint.json diff --git a/types/pa11y/index.d.ts b/types/pa11y/index.d.ts new file mode 100644 index 0000000000..b824e2e2b0 --- /dev/null +++ b/types/pa11y/index.d.ts @@ -0,0 +1,72 @@ +// Type definitions for pa11y 5.3 +// Project: https://github.com/pa11y/pa11y +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +import { Browser, Page, } from "puppeteer"; +import { Viewport } from "puppeteer/DeviceDescriptors"; + +type AccessibilityStandard = "Section508" | "WCAG2A" | "WCAG2AA" | "WCAG2AAA"; + +interface LaunchConfig { + executablePath: string; + ignoreHTTPSErrors: boolean; +} + +interface LogConfig { + debug?: () => void; + error?: () => void; + info?: () => void; +} + +interface ResultIssue { + code: string; + context: string; + message: string; + selector: string; + type: string; + typeCode: number; +} + +interface Results { + documentTitle: string; + pageUrl: string; + issues: ResultIssue[]; +} + +interface Options { + actions?: string[]; + browser?: Browser; + pages?: Page[]; + chromeLaunchConfig?: LaunchConfig; + headers?: object; + hideElements?: string; + ignore?: string[]; + ignoreUrl?: boolean; + includeNotices?: boolean; + includeWarnings?: boolean; + level?: string; + log?: LogConfig; + method?: string; + postData?: string; + reporter?: string; + rootElement?: string; + runners?: string[]; + rules?: string[]; + screenCapture?: string; + standard?: AccessibilityStandard; + threshold?: number; + timeout?: number; + userAgent?: string; + viewport?: Viewport; + wait?: number; +} + +declare function pa11y(url: string, options?: Options): Promise; + +declare namespace pa11y { + function isValidAction(action: string): boolean; +} + +export = pa11y; diff --git a/types/pa11y/pa11y-tests.ts b/types/pa11y/pa11y-tests.ts new file mode 100644 index 0000000000..1ef97a06f9 --- /dev/null +++ b/types/pa11y/pa11y-tests.ts @@ -0,0 +1,29 @@ +import pa11y = require('pa11y'); + +pa11y('http://example.com/'); + +pa11y('http://example.com/', { + log: { + debug: console.log, + error: console.error, + info: console.info + } +}); + +pa11y('http://example.com/', { + actions: [ + 'set field #username to exampleUser', + 'wait for url to be http://example.com/myaccount' + ], + log: { + debug: console.log, + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + method: 'POST', + postData: 'foo=bar&bar=baz', + rootElement: '#main' +}); + +pa11y.isValidAction('open the pod bay doors'); diff --git a/types/pa11y/tsconfig.json b/types/pa11y/tsconfig.json new file mode 100644 index 0000000000..722f1dec33 --- /dev/null +++ b/types/pa11y/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pa11y-tests.ts" + ] +} diff --git a/types/pa11y/tslint.json b/types/pa11y/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/pa11y/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file