Skip to content

Commit 733a683

Browse files
committed
fix a couple more type errors
1 parent 7b38a4a commit 733a683

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

packages/jest-core/src/SearchSource.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ type FilterResult = {
4343
type TestPathCases = {
4444
roots: (path: Config.Path) => boolean;
4545
testMatch: (path: Config.Path) => boolean;
46-
testRegex: (path: Config.Path) => boolean;
4746
testPathIgnorePatterns: (path: Config.Path) => boolean;
48-
testPathPattern?: (path: Config.Path) => boolean;
47+
testRegex: (path: Config.Path) => boolean;
48+
};
49+
50+
type TestPathCasesWithPathPattern = TestPathCases & {
51+
testPathPattern: (path: Config.Path) => boolean;
4952
};
5053

5154
const globsToMatcher = (globs?: Array<Config.Glob> | null) => {
@@ -105,27 +108,38 @@ export default class SearchSource {
105108
testPathPattern?: string,
106109
): SearchResult {
107110
const data: {
108-
stats: {[key in keyof TestPathCases]: number};
111+
stats: {
112+
[key in keyof (TestPathCases | TestPathCasesWithPathPattern)]: number
113+
};
109114
tests: Array<Test>;
110115
total: number;
111116
} = {
112-
stats: {},
117+
stats: {
118+
roots: 0,
119+
testMatch: 0,
120+
testPathIgnorePatterns: 0,
121+
testRegex: 0,
122+
},
113123
tests: [],
114124
total: allPaths.length,
115125
};
116126

117127
const testCases = Object.assign({}, this._testPathCases);
118128
if (testPathPattern) {
119129
const regex = testPathPatternToRegExp(testPathPattern);
120-
testCases.testPathPattern = (path: Config.Path) => regex.test(path);
130+
(testCases as TestPathCasesWithPathPattern).testPathPattern = (
131+
path: Config.Path,
132+
) => regex.test(path);
121133
}
122134

123-
const testCasesKeys = Object.keys(testCases) as Array<keyof TestPathCases>;
135+
const testCasesKeys = Object.keys(testCases) as Array<
136+
keyof (TestPathCases | TestPathCasesWithPathPattern)
137+
>;
124138
data.tests = allPaths.filter(test =>
125139
testCasesKeys.reduce((flag, key) => {
126140
if (testCases[key](test.path)) {
127141
if (data.stats[key] === undefined) {
128-
data.stats[key] = 1;
142+
data.stats[key] = 0;
129143
}
130144
++data.stats[key]!;
131145
return flag && true;
@@ -135,6 +149,13 @@ export default class SearchSource {
135149
}, true),
136150
);
137151

152+
// TODO: Is this necessary? Done to keep the object the same as before the TS migration
153+
testCasesKeys.forEach(key => {
154+
if (data.stats[key] === 0) {
155+
delete data.stats[key];
156+
}
157+
});
158+
138159
return data;
139160
}
140161

0 commit comments

Comments
 (0)