Skip to content

Commit 8137ae2

Browse files
committed
Allow to pass the exact test filenames
1 parent 04d05e5 commit 8137ae2

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

packages/jest-cli/src/SearchSource.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {Glob, Path} from 'types/Config';
1313
import type {ResolveModuleConfig} from 'types/Resolve';
1414
import type {Test} from 'types/TestRunner';
1515

16+
import fs from 'fs';
1617
import path from 'path';
1718
import micromatch from 'micromatch';
1819
import DependencyResolver from 'jest-resolve-dependencies';
@@ -76,6 +77,15 @@ const toTests = (context, tests) =>
7677
path,
7778
}));
7879

80+
const fileExists = (filePath: string) => {
81+
try {
82+
fs.accessSync(filePath, fs.F_OK);
83+
return true;
84+
} catch (e) {
85+
return false;
86+
}
87+
};
88+
7989
class SearchSource {
8090
_context: Context;
8191
_options: ResolveModuleConfig;
@@ -230,12 +240,16 @@ class SearchSource {
230240
return Promise.resolve(
231241
this.findRelatedTestsFromPattern(testSelectionConfig.paths),
232242
);
233-
} else if (testSelectionConfig.testPathPattern != null) {
234-
return Promise.resolve(
235-
this.findMatchingTests(testSelectionConfig.testPathPattern),
236-
);
237243
} else {
238-
return Promise.resolve({tests: []});
244+
const validTestPaths = testSelectionConfig.paths && testSelectionConfig.paths.filter(fileExists);
245+
246+
if (validTestPaths && validTestPaths.length) {
247+
return Promise.resolve({tests: toTests(this._context, validTestPaths)});
248+
} else if (testSelectionConfig.testPathPattern != null) {
249+
return Promise.resolve(this.findMatchingTests(testSelectionConfig.testPathPattern));
250+
} else {
251+
return Promise.resolve({tests: []});
252+
}
239253
}
240254
}
241255
}

0 commit comments

Comments
 (0)