accessibility-checker
Version:
An automated testing tools for accessibility testing using Puppeteer, Selenium, or Zombie
170 lines (166 loc) • 7.34 kB
TypeScript
/******************************************************************************
Copyright:: 2023- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
import { IAbstractAPI } from "../api-ext/IAbstractAPI.js";
import { IConfigInternal, eAssertResult } from "../config/IConfig.js";
import { IBaselineReport } from "../engine/IReport.js";
export type RefactorMap = {
[oldRuleId: string]: {
id: string;
refactor: {
[ruleId: string]: {
[reasonId: string]: string;
};
};
};
};
/**
* This interface is responsible for aChecker baselines and comparing scans to baselines
*/
export declare class BaselineManager {
private static baselineIssueList;
private static config;
private static diffResults;
private static absAPI;
private static refactorMap;
static initialize(config: IConfigInternal, absAPI: IAbstractAPI, refactorMap: RefactorMap): void;
static getBaseline(label: string): IBaselineReport | null;
/**
* This function is responsible for comparing the scan results with baseline or checking that there are
* no violations which fall into the failsLevels levels. In the case a baseline is found then baseline will
* be used to perform the check, in the case no baseline is provided then we comply with only failing if
* there is a sinble violation which falls into failLevels.
*
* @param {Object} actual - the actual results object provided by the user, this object should follow the
* same format as outlined in the return of aChecker.buildReport function.
*
* @return {int} - return 0 in the case actual matches baseline or no violations fall into failsLevels,
* return 1 in the case actual results does not match baseline results,
* return 2 in the case that there is a failure based on failLevels (this means no baseline found).
* return -1 in the case that there is an exception that occured in the results object which came from the scan engine.
*
* PUBLIC API
*
* @memberOf this
*/
static assertCompliance(actualResults: IBaselineReport): eAssertResult;
/**
* This function is responsible for comparing actual with expected and returning all the differences as an array.
*
* @param {Object} actual - Provide the actual object to be used for compare
* @param {Object} expected - Provide the expected object to be used for compare
* @param {boolean} clean - Provide a boolean if both the actual and expected objects need to be cleaned
* cleaning refers to converting the objects to match with a basic compliance
* compare of xpath and ruleId.
*
* @return {Object} differences - return an array of diff objects that were found, following is the format of the object:
* [
* {
* "kind": "E",
* "path": [
* "reports",
* 0,
* "issues",
* 10,
* "xpath"
* ],
* "lhs": "/html[1]/body[1]/div[2]/table[5]",
* "rhs": "/html[1]/body[1]/div[2]/table[5]d",
* },
* {
* "kind": "E",
* "path": [
* "label"
* ],
* "lhs": "Table-layoutMultiple",
* "rhs": "dependencies/tools-rules-html/v2/a11y/test/g471/Table-layoutMultiple.html",
* }
* ]
*
* PUBLIC API
*
* @memberOf this
*/
static diffResultsWithExpected(actual: any, expected: any, clean: any): any;
/**
* This function is responsible for checking if any of the issues reported have any level that falls
* into the failsLevel array.
*
* @param {Object} results - Provide the scan results, object which would be in the
* the same format as outlined in the return of aChecker.buildReport function.
*
* @return {int} - return 1 in the case a single issue was found which is in the failsLevel array.
* return -1 in the case that there is an exception that occured in the results object which came from the scan engine.
*
* PRIVATE METHOD
*
* @memberOf this
*/
static compareBasedOnFailLevels(report: any): 0 | 1 | -1;
/**
* This function is responsible for cleaning up the compliance baseline or actual results, based on
* a pre-defined set of criterias, such as the following:
* 1. No need to compare summary object
* 2. Only need to compare the ruleId and xpath in for each of the issues
*
* @param {Object} objectToClean - Provide either an baseline or actual results object which would be in the
* the same format as outlined in the return of aChecker.buildReport function.
*
* @return {Object} objectToClean - return an object that was cleaned to only contain the information that is
* needed for compare. Following is a sample of how the cleaned object will look like:
* {
* "label": "unitTestContent",
* "reports": [
* {
* "frameIdx": "0",
* "frameTitle": "Frame 0",
* "issues": [
* {
* "ruleId": "1",
* "xpath": "/html[1]/head[1]/style[1]"
* }
* ....
* ]
* },
* {
* "frameIdx": "1",
* "frameTitle": "Frame 1",
* "issues": [
* {
* "ruleId": "471",
* "xpath": "/html[1]/body[1]/div[2]/table[3]"
* }
* ....
* ]
* }
* ]
* }
*
* PRIVATE METHOD
*
* @memberOf this
*/
static cleanComplianceObjectBeforeCompare(objectToClean: any): any;
/**
* This function is responsible for getting the diff results based on label for a scan that was already performed.
*
* @param {String} label - Provide a lable for which to get the diff results for.
*
* @return {Object} - return the diff results object from global space based on label provided, the object will be
* in the same format as outlined in the return of aChecker.diffResultsWithExpected function.
*
* PUBLIC API
*
* @memberOf this
*/
static getDiffResults(label: string): any;
}