Skip to content

Commit 8cca67d

Browse files
kentaromiuraFacebook Github Bot 1
authored andcommitted
Directly run the test if the pattern directly resolves to a file
Summary:Directly run a test when passing path to a file instead of treating it as a pattern. Also avoid sorting the paths if there's only a single path, as we were doing a lot of things in the `_sortTests` method. Closes jestjs#810 Differential Revision: D3063643 fb-gh-sync-id: 4c9abd1c5b630e8e68641bf515b9ea1f2ce9fab2 fbshipit-source-id: 4c9abd1c5b630e8e68641bf515b9ea1f2ce9fab2
1 parent c5babf4 commit 8cca67d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/TestRunner.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,14 @@ class TestRunner {
214214
}
215215

216216
promiseTestPathsMatching(pathPattern) {
217-
return this._getAllTestPaths()
218-
.then(paths => paths.filter(path => pathPattern.test(path)));
217+
try {
218+
const maybeFile = path.resolve(process.cwd(), pathPattern);
219+
fs.accessSync(maybeFile);
220+
return Promise.resolve([pathPattern].filter(this._isTestFilePath));
221+
} catch (e) {
222+
return this._getAllTestPaths()
223+
.then(paths => paths.filter(path => new RegExp(pathPattern).test(path)));
224+
}
219225
}
220226

221227
_getTestPerformanceCachePath() {

src/jest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function getTestPaths(testRunner, config, patternInfo) {
4747
if (patternInfo.onlyChanged) {
4848
return findOnlyChangedTestPaths(testRunner, config);
4949
} else {
50-
return testRunner.promiseTestPathsMatching(new RegExp(patternInfo.pattern));
50+
return testRunner.promiseTestPathsMatching(patternInfo.pattern);
5151
}
5252
}
5353

0 commit comments

Comments
 (0)