Add typing for pa11y (#43060)

Co-authored-by: Adam Zerella <adamzerella@users.noreply.github.com>
This commit is contained in:
Adam Zerella 2020-03-28 03:43:46 +10:30 committed by GitHub
parent 5ed7a06ce8
commit 83e40f8eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 0 deletions

72
types/pa11y/index.d.ts vendored Normal file
View File

@ -0,0 +1,72 @@
// Type definitions for pa11y 5.3
// Project: https://github.com/pa11y/pa11y
// Definitions by: Adam Zerella <https://github.com/adamzerella>
// 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<Results>;
declare namespace pa11y {
function isValidAction(action: string): boolean;
}
export = pa11y;

View File

@ -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');

26
types/pa11y/tsconfig.json Normal file
View File

@ -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"
]
}

3
types/pa11y/tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}