Skip to content

Commit

Permalink
Revert "feat: added the ability to report AxeError (#653)" (#658)
Browse files Browse the repository at this point in the history
This reverts commit 6ed0d12.
  • Loading branch information
jaig-0911 authored Mar 5, 2024
1 parent 5f57cd7 commit 4a977f8
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 86 deletions.
17 changes: 0 additions & 17 deletions packages/format/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ const defaultOptions: Options = {
/**
* Custom error object to represent a11y violations
*/

export class AxeError extends Error {
/**
* Throw error with Axe error
*/

constructor(message: string) {
super(message);
this.name = AxeError.name;
this.message = message;
}

static throwAxeError(e: Error): void {
throw new AxeError(`${e.message}`);
}
}

export class A11yError extends Error {
/**
* Throw error with formatted a11y violations
Expand Down
2 changes: 1 addition & 1 deletion packages/format/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

export { A11yError, AxeError, Options } from './format';
export { A11yError, Options } from './format';
export { exceptionListFilter, exceptionListFilterSelectorKeywords } from './filter';
export { A11yResult, A11yResults, appendWcag } from './result';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions packages/jest/__tests__/automatic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import {
domWithNoA11yIssuesChildCount,
domWithDescendancyA11yIssues,
customRulesFilePath,
customRulesFilePathInvalid,
} from '@sa11y/test-utils';
import * as Sa11yCommon from '@sa11y/common';

import { expect, jest } from '@jest/globals';

describe('automatic checks registration', () => {
Expand Down Expand Up @@ -206,6 +204,7 @@ describe('automatic checks call', () => {
document.body.innerHTML = domWithA11yIssues;
await expect(automaticCheck({ filesFilter: nonExistentFilePaths })).rejects.toThrow();
});

it('should take only custom rules if specified', async () => {
document.body.innerHTML = domWithA11yIssues;
process.env.SA11Y_CUSTOM_RULES = customRulesFilePath;
Expand All @@ -219,13 +218,4 @@ describe('automatic checks call', () => {
await expect(automaticCheck({ filesFilter: nonExistentFilePaths })).rejects.toThrow();
delete process.env.SELECTOR_FILTER_KEYWORDS;
});
it('should throw an Axe error for axe related issues', async () => {
document.body.innerHTML = domWithNoA11yIssues;
// expect(document).toBeAccessible();
process.env.SA11Y_CUSTOM_RULES = customRulesFilePathInvalid;
await expect(automaticCheck({ cleanupAfterEach: true })).rejects.toThrow(
'Error running accessibility checks using axe'
);
delete process.env.SA11Y_CUSTOM_RULES;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { A11yError, A11yResult } from '@sa11y/format';
import { getA11yError } from '@sa11y/format/__tests__/format.test';
import { domWithVisualA11yIssues } from '@sa11y/test-utils';
import { expect } from '@jest/globals';
import { AxeError } from '@sa11y/format/src';

const a11yResults: A11yResult[] = [];
const aggregatedResults = makeEmptyAggregatedTestResult();
Expand Down Expand Up @@ -45,8 +44,6 @@ beforeAll(async () => {
addTestFailure(testSuite, new A11yError(combinedViolations, a11yResults));
// Add non-a11y test failure
addTestFailure(testSuite, new Error('foo'));
addTestFailure(testSuite, new AxeError('Axe is running'));

testSuite.testFilePath = '/test/data/sa11y-auto-checks.js';
addResult(aggregatedResults, testSuite);
});
Expand Down
4 changes: 1 addition & 3 deletions packages/jest/src/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { AxeResults, log, useCustomRules } from '@sa11y/common';
import { getViolationsJSDOM } from '@sa11y/assert';
import { A11yError, AxeError, exceptionListFilterSelectorKeywords } from '@sa11y/format';
import { A11yError, exceptionListFilterSelectorKeywords } from '@sa11y/format';
import { isTestUsingFakeTimer } from './matcher';
import { expect } from '@jest/globals';
import { adaptA11yConfig, adaptA11yConfigCustomRules } from './setup';
Expand Down Expand Up @@ -100,8 +100,6 @@ export async function automaticCheck(opts: AutoCheckOpts = defaultAutoCheckOpts)
);
currNode = walker.nextSibling();
}
} catch (e) {
AxeError.throwAxeError(e as Error);
} finally {
setOriginalDocumentBodyHtml(null);
document.body.innerHTML = currentDocumentHtml;
Expand Down
36 changes: 12 additions & 24 deletions packages/jest/src/groupViolationResultsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
*/
import { AggregatedResult, AssertionResult, TestResult } from '@jest/test-result';
import { log } from '@sa11y/common';
import { A11yError, AxeError } from '@sa11y/format';
import { A11yError } from '@sa11y/format';

type a11yFailureDetail = {
type FailureDetail = {
error?: A11yError;
};
type axeFailureDetail = {
error?: AxeError;
};

type ErrorElement = {
html: string;
selectors: string;
Expand Down Expand Up @@ -61,21 +59,19 @@ function createA11yRuleViolation(a11yRule: A11yViolation, ruleIndex: number) {
* Convert any a11y errors from test failures into their own test suite, results
*/
function processA11yErrors(results: AggregatedResult, testSuite: TestResult, testResult: AssertionResult) {
const a11yFailureDetails: a11yFailureDetail[] = [];
const axeFailureDetails: axeFailureDetail[] = [];
const a11yFailureDetails: FailureDetail[] = [];
const a11yFailureMessages: string[] = [];
const axeFailureMessages: string[] = [];
let a11yAxeErrorsExist = false;
let a11yErrorsExist = false;

testResult.failureDetails.forEach((failure) => {
let error = (failure as a11yFailureDetail).error;
let error = (failure as FailureDetail).error;
// If using circus test runner https://github.com/facebook/jest/issues/11405#issuecomment-843549606
// TODO (code cov): Add test data covering the case for circus test runner
/* istanbul ignore next */
if (error === undefined) error = failure as A11yError;
if (error.name === A11yError.name) {
a11yAxeErrorsExist = true;
a11yFailureDetails.push({ ...(failure as a11yFailureDetail) } as a11yFailureDetail);
a11yErrorsExist = true;
a11yFailureDetails.push({ ...(failure as FailureDetail) } as FailureDetail);
const a11yRuleViolations: { [key: string]: A11yViolation } = {};
let a11yRuleViolationsCount = 0;
let a11yErrorElementsCount = 0;
Expand Down Expand Up @@ -114,24 +110,16 @@ function processA11yErrors(results: AggregatedResult, testSuite: TestResult, tes
`;
a11yFailureMessages.push(a11yFailureMessage);
}
if (error.name === AxeError.name) {
a11yAxeErrorsExist = true;
axeFailureDetails.push({ ...(failure as axeFailureDetail) } as axeFailureDetail);
axeFailureMessages.push(`
The test has failed to execute the accessibility check.
Please contact our Sa11y team: http://sfdc.co/sa11y-users
`);
}
});
if (!a11yAxeErrorsExist) {
if (!a11yErrorsExist) {
testSuite.numFailingTests -= 1;
results.numFailedTests -= 1;
if (testSuite.numFailingTests === 0) results.numFailedTestSuites -= 1;
}

testResult.failureDetails = [...a11yFailureDetails, ...axeFailureDetails];
testResult.failureMessages = [...a11yFailureMessages, ...axeFailureMessages];
testResult.status = testResult.failureDetails.length === 0 ? 'passed' : testResult.status;
testResult.failureDetails = [...a11yFailureDetails];
testResult.failureMessages = [...a11yFailureMessages];
testResult.status = a11yFailureDetails.length === 0 ? 'passed' : testResult.status;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions packages/test-utils/__data__/sa11y-custom-rules-invalid.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ export {
shadowDomID,
videoURL,
customRulesFilePath,
customRulesFilePathInvalid,
} from './test-data';
export { beforeEachSetup, cartesianProduct } from './utils';
2 changes: 0 additions & 2 deletions packages/test-utils/src/test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const dataDir = path.resolve(__dirname, '../__data__/');
export const domWithA11yIssuesBodyID = 'dom-with-issues';
const fileWithA11yIssues = path.resolve(dataDir, 'a11yIssues.html');
export const customRulesFilePath = path.resolve(dataDir, 'sa11y-custom-rules.json');
export const customRulesFilePathInvalid = path.resolve(dataDir, 'sa11y-custom-rules-invalid.json');

const fileWithDescendancyA11yIssues = path.resolve(dataDir, 'descendancyA11yIssues.html');
export const htmlFileWithA11yIssues = 'file:///' + fileWithA11yIssues;
export const domWithA11yIssues = fs.readFileSync(fileWithA11yIssues).toString();
Expand Down

0 comments on commit 4a977f8

Please sign in to comment.