Skip to content

Commit

Permalink
Fixes bug jestjs#13222
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocabral88 committed Sep 25, 2022
1 parent 35e8b6a commit 1a864f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 1 addition & 3 deletions packages/jest-core/src/SearchSource.ts
Expand Up @@ -340,9 +340,7 @@ export default class SearchSource {
);
}

const filteredSet = new Set(
filterResult.filtered.map(result => result.test),
);
const filteredSet = new Set(filterResult.filtered);

return {
...searchResult,
Expand Down
35 changes: 30 additions & 5 deletions packages/jest-core/src/__tests__/SearchSource.test.ts
Expand Up @@ -11,7 +11,8 @@ import type {Test} from '@jest/test-result';
import type {Config} from '@jest/types';
import {normalize} from 'jest-config';
import Runtime from 'jest-runtime';
import SearchSource, {SearchResult} from '../SearchSource';
import SearchSource from '../SearchSource';
import type {Filter} from '../types';

jest.setTimeout(15000);

Expand Down Expand Up @@ -103,11 +104,18 @@ describe('SearchSource', () => {
});

describe('getTestPaths', () => {
const getTestPaths = async (initialOptions: Config.InitialOptions) => {
const getTestPaths = async (
initialOptions: Config.InitialOptions,
filter?: Filter,
) => {
const searchSource = await initSearchSource(initialOptions);
const {tests: paths} = await searchSource.getTestPaths({
testPathPattern: '',
});
const {tests: paths} = await searchSource.getTestPaths(
{
testPathPattern: '',
},
null,
filter,
);
return paths.map(({path: p}) => path.relative(rootDir, p)).sort();
};

Expand Down Expand Up @@ -288,6 +296,23 @@ describe('SearchSource', () => {
path.normalize('__testtests__/test.jsx'),
]);
});

it('filter tests based on an optional filter method', async () => {
const filterFunction = (testPaths: Array<string>) =>
Promise.resolve({
filtered: testPaths.filter(testPath => testPath.includes('test.jsx')),
});
const paths = await getTestPaths(
{
id,
rootDir,
},
filterFunction,
);

expect(paths).toHaveLength(1);
expect(paths[0]).toStrictEqual(path.normalize('__testtests__/test.jsx'));
});
});

describe('filterPathsWin32', () => {
Expand Down
7 changes: 1 addition & 6 deletions packages/jest-core/src/types.ts
Expand Up @@ -34,11 +34,6 @@ export type TestPathCasesWithPathPattern = TestPathCases & {
testPathPattern: (path: string) => boolean;
};

export type FilterResult = {
test: string;
message: string;
};

export type Filter = (testPaths: Array<string>) => Promise<{
filtered: Array<FilterResult>;
filtered: Array<string>;
}>;

0 comments on commit 1a864f2

Please sign in to comment.