Skip to content

Commit

Permalink
refactor: convert regex match for auto files filter to a simple conta…
Browse files Browse the repository at this point in the history
…ins check
  • Loading branch information
mohanraj-r committed Nov 20, 2021
1 parent ee117ea commit b8e0092
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions packages/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ SA11Y_AUTO=1 SA11Y_CLEANUP=1 jest
- Invoking `jest` with environment variables as above will enable automatic checks with no changes required to `setup()`
- The environment variables can be used to set up parallel builds e.g., in a CI environment without code changes to `setup()` to opt-in to automatic checks
- Setting `SA11Y_DEBUG=1` will output verbose logging
- `SA11Y_AUTO_FILTER` can be used to specify a comma seperated list of test file paths to filter out from automatic checks
- When specified automatic checks are skipped for given files
- The file paths can be also be expressed as [regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet) if necessary
- `SA11Y_AUTO_FILTER` can be used to specify a comma seperated list of test file paths to filter out from automatic checks. When specified automatic checks are skipped for given files.

### Sa11y results processor

Expand Down
10 changes: 5 additions & 5 deletions packages/jest/__tests__/automatic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('automatic checks registration', () => {

describe('automatic checks call', () => {
const testPath = expect.getState().testPath;
const nonExistentFilePaths = ['foo', `/(?!${testPath})$`, `!${testPath}`];
const nonExistentFilePaths = ['foo', `foo${testPath}`, `${testPath}foo`];
// Note: cleanup required at end of each test to prevent dom being checked again
// after the test as part of the afterEach automatic check hook
beforeEach(beforeEachSetup);
Expand Down Expand Up @@ -163,11 +163,11 @@ describe('automatic checks call', () => {
['foo', undefined, false],
['foo', [], false],
['foo', ['foo'], true],
['foo', ['!foo'], false],
['foo', ['bar'], false],
['foo', ['!bar'], false],
['foo', ['Foo'], true],
['foo', ['foo', 'bar'], true],
['foo', ['foo', '(?!foo)', 'bar'], true],
['foo', ['bar'], false],
['foo', ['foobar'], false],
['foo', ['barfoo'], false],
])(
'should filter test file as expected with args # %#',
(testPath: string, filesFilter: string[] | undefined, expectedResult: boolean) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const defaultAutoCheckOpts: AutoCheckOpts = {
*/
export function skipTest(testPath: string, filesFilter?: string[]): boolean {
if (!filesFilter || !(filesFilter?.length > 0)) return false;
const skipTest = filesFilter.some((fileName) => RegExp(fileName).test(testPath));
const skipTest = filesFilter.some((fileName) => testPath.toLowerCase().includes(fileName.toLowerCase()));

if (skipTest) {
log(
Expand Down

0 comments on commit b8e0092

Please sign in to comment.