diff --git a/packages/common/__tests__/helpers.test.ts b/packages/common/__tests__/helpers.test.ts index a5e6f6ec..92aec0ca 100644 --- a/packages/common/__tests__/helpers.test.ts +++ b/packages/common/__tests__/helpers.test.ts @@ -67,22 +67,22 @@ describe('Your Module', () => { delete process.env.SA11Y_AUTO_FILTER_LIST_PACKAGE_NAME; }); - it('should return empty array if SA11Y_CUSTOM_RULES env variable is not set', async () => { + it('should return empty array if SA11Y_CUSTOM_RULES env variable is not set', () => { process.env.SA11Y_CUSTOM_RULES = ''; - const result = await useCustomRules(); + const result = useCustomRules(); expect(result).toEqual([]); }); - it('should return empty array if reading file encounters an error', async () => { + it('should return empty array if reading file encounters an error', () => { process.env.SA11Y_CUSTOM_RULES = 'packages/common/testMocks/WrongFile.json'; - const result = await useCustomRules(); + const result = useCustomRules(); expect(result).toEqual([]); }); - it('should return rules array if file is read successfully', async () => { + it('should return rules array if file is read successfully', () => { process.env.SA11Y_CUSTOM_RULES = 'packages/common/testMocks/sa11y-custom-rules.json'; const mockRules = ['rule1', 'rule2']; - const result = await useCustomRules(); + const result = useCustomRules(); expect(result).toEqual(mockRules); }); }); diff --git a/packages/common/src/helpers.ts b/packages/common/src/helpers.ts index 9418d18b..23deb934 100644 --- a/packages/common/src/helpers.ts +++ b/packages/common/src/helpers.ts @@ -10,7 +10,7 @@ * Logging is enabled only when environment variable `SA11Y_DEBUG` is set. */ -import * as fs from 'fs/promises'; +import * as fs from 'fs'; export function log(...args: unknown[]): void { // Probably not worth it to mock and test console logging for this helper util /* istanbul ignore next */ @@ -34,12 +34,12 @@ export function useFilesToBeExempted(): string[] { return []; } -export async function useCustomRules(): Promise { +export function useCustomRules(): string[] { const filePath = process.env.SA11Y_CUSTOM_RULES ?? ''; if (filePath !== '') { try { // Read the file asynchronously - const data = await fs.readFile(filePath, 'utf-8'); + const data = fs.readFileSync(filePath, 'utf-8'); const { rules } = JSON.parse(data) as { rules: string[] }; // Access the rules array return rules; diff --git a/packages/jest/src/automatic.ts b/packages/jest/src/automatic.ts index 81879457..92570185 100644 --- a/packages/jest/src/automatic.ts +++ b/packages/jest/src/automatic.ts @@ -82,7 +82,7 @@ export async function automaticCheck(opts: AutoCheckOpts = defaultAutoCheckOpts) // Create a DOM walker filtering only elements (skipping text, comment nodes etc) const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT); let currNode = walker.firstChild(); - const customRules = await useCustomRules(); + const customRules = useCustomRules(); try { while (currNode !== null) { // TODO (spike): Use a logger lib with log levels selectable at runtime