Skip to content

Commit d73328f

Browse files
LINKIWIcpojer
authored andcommitted
Verify passed test path is a file before resolving (#5317)
* Verify passed test path is a file before resolving * Update CHANGELOG * Cut one FS operation with try-catch * Remove jest version number in CHANGELOG
1 parent 8b46fa8 commit d73328f

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## master
22

3+
### Fixes
4+
5+
* `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.
6+
([#5317](https://github.com/facebook/jest/pull/5317))
7+
38
## jest 22.1.0
49

510
### Features

integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports[`CLI accepts exact filenames 2`] = `
2222
Tests: 2 passed, 2 total
2323
Snapshots: 0 total
2424
Time: <<REPLACED>>
25-
Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js/i.
25+
Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js|.\\\\/foo/i.
2626
"
2727
`;
2828

integration-tests/__tests__/cli-accepts-exact-filenames.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test('CLI accepts exact filenames', () => {
3838
'--forceExit',
3939
'./bar.js',
4040
'./foo/baz.js',
41+
'./foo',
4142
]);
4243
const {rest, summary} = extractSummary(stderr);
4344
expect(status).toBe(0);

packages/jest-cli/src/search_source.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,15 @@ export default class SearchSource {
209209
} else if (globalConfig.findRelatedTests && paths && paths.length) {
210210
return Promise.resolve(this.findRelatedTestsFromPattern(paths));
211211
} else {
212-
const validTestPaths = paths && paths.filter(fs.existsSync);
212+
const validTestPaths =
213+
paths &&
214+
paths.filter(name => {
215+
try {
216+
return fs.lstatSync(name).isFile();
217+
} catch (e) {
218+
return false;
219+
}
220+
});
213221

214222
if (validTestPaths && validTestPaths.length) {
215223
return Promise.resolve({tests: toTests(this._context, validTestPaths)});

0 commit comments

Comments
 (0)