Skip to content

Commit 90bd611

Browse files
authored
feat: added support for consuming new rules (#683)
* feat: added support for consuming new rules
1 parent 276a8ff commit 90bd611

File tree

24 files changed

+3317
-108
lines changed

24 files changed

+3317
-108
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"packages/*"
1616
],
1717
"scripts": {
18-
"build": "tsc --build && yarn workspace @sa11y/browser-lib build",
18+
"build": "tsc --build && yarn workspace @sa11y/browser-lib build && lerna exec --scope @sa11y/preset-rules -- yarn copy-json",
1919
"build:ci": "yarn install --frozen-lockfile && yarn build",
2020
"build:clean": "tsc --build --clean && rimraf packages/**/dist && yarn build:ci",
2121
"build:watch": "tsc --build --watch",
@@ -76,6 +76,7 @@
7676
"chromedriver": "115.0.1",
7777
"commitizen": "4.3.0",
7878
"conventional-changelog-cli": "2.2.2",
79+
"cpx": "1.5.0",
7980
"cspell": "6.31.3",
8081
"depcheck": "1.4.3",
8182
"doctoc": "2.2.1",

packages/common/__tests__/helpers.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { useFilesToBeExempted, log, useCustomRules } from '../src/helpers';
8+
import path from 'path';
9+
import { useFilesToBeExempted, log, useCustomRules, processFiles } from '../src/helpers';
910

1011
describe('Your Module', () => {
1112
afterEach(() => {
@@ -85,4 +86,11 @@ describe('Your Module', () => {
8586
const result = useCustomRules();
8687
expect(result).toEqual(mockRules);
8788
});
89+
90+
it('should process only .json files and parse their content', () => {
91+
const targetArray: Array<{ key: string }> = [];
92+
const directoryPath = path.join(__dirname, '../testMocks/testProcessFiles');
93+
processFiles<{ key: string }>(directoryPath, targetArray, '.json', JSON.parse);
94+
expect(targetArray).toEqual([{ key: 'value' }]);
95+
});
8896
});

packages/common/src/helpers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
const sa11yAutoFilterListDefaultPackageName = 'sa11y-jest-automated-check-file-exclusion';
1313

1414
import * as fs from 'fs';
15+
import path from 'path';
1516
export function log(...args: unknown[]): void {
1617
// Probably not worth it to mock and test console logging for this helper util
1718
/* istanbul ignore next */
@@ -50,3 +51,20 @@ export function useCustomRules(): string[] {
5051
}
5152
return [];
5253
}
54+
55+
// Function to process files in a directory and push their content to a target array
56+
export const processFiles = <T>(
57+
dir: string,
58+
targetArray: T[],
59+
extension: string,
60+
parser: (data: string) => T
61+
): void => {
62+
const files = fs.readdirSync(dir);
63+
files.forEach((file) => {
64+
if (path.extname(file) === extension) {
65+
const filePath = path.join(dir, file);
66+
const fileData = parser(fs.readFileSync(filePath, 'utf8'));
67+
targetArray.push(fileData);
68+
}
69+
});
70+
};

packages/common/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
export { A11yConfig, AxeResults, axeRuntimeExceptionMsgPrefix, axeVersion, getAxeRules, getViolations } from './axe';
99
export { WdioAssertFunction, WdioOptions } from './wdio';
1010
export { errMsgHeader, ExceptionList } from './format';
11-
export { log, useFilesToBeExempted, useCustomRules } from './helpers';
11+
export { log, useFilesToBeExempted, useCustomRules, processFiles } from './helpers';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key": "value"
3+
}

packages/format/__tests__/__snapshots__/filter.test.ts.snap

Lines changed: 327 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/format/__tests__/__snapshots__/format.test.ts.snap

Lines changed: 87 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)