Skip to content

Commit

Permalink
Verify passed test path is a file before resolving (#5317)
Browse files Browse the repository at this point in the history
* Verify passed test path is a file before resolving

* Update CHANGELOG

* Cut one FS operation with try-catch

* Remove jest version number in CHANGELOG
  • Loading branch information
LINKIWI authored and cpojer committed Jan 15, 2018
1 parent 8b46fa8 commit d73328f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## master

### Fixes

* `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.
([#5317](https://github.com/facebook/jest/pull/5317))

## jest 22.1.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exports[`CLI accepts exact filenames 2`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js/i.
Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js|.\\\\/foo/i.
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test('CLI accepts exact filenames', () => {
'--forceExit',
'./bar.js',
'./foo/baz.js',
'./foo',
]);
const {rest, summary} = extractSummary(stderr);
expect(status).toBe(0);
Expand Down
10 changes: 9 additions & 1 deletion packages/jest-cli/src/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ export default class SearchSource {
} else if (globalConfig.findRelatedTests && paths && paths.length) {
return Promise.resolve(this.findRelatedTestsFromPattern(paths));
} else {
const validTestPaths = paths && paths.filter(fs.existsSync);
const validTestPaths =
paths &&
paths.filter(name => {
try {
return fs.lstatSync(name).isFile();
} catch (e) {
return false;
}
});

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

0 comments on commit d73328f

Please sign in to comment.