From 0a4ab897a475fc1242a98834b92577e89745fad3 Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Mon, 15 Jan 2018 10:04:39 -0600 Subject: [PATCH 1/4] Verify passed test path is a file before resolving --- .../__snapshots__/cli-accepts-exact-filenames.test.js.snap | 2 +- .../__tests__/cli-accepts-exact-filenames.test.js | 1 + packages/jest-cli/src/search_source.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap b/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap index 6c75b05c0a40..14f0f7d5b8bc 100644 --- a/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/cli-accepts-exact-filenames.test.js.snap @@ -22,7 +22,7 @@ exports[`CLI accepts exact filenames 2`] = ` Tests: 2 passed, 2 total Snapshots: 0 total Time: <> -Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js/i. +Ran all test suites matching /.\\\\/bar.js|.\\\\/foo\\\\/baz.js|.\\\\/foo/i. " `; diff --git a/integration-tests/__tests__/cli-accepts-exact-filenames.test.js b/integration-tests/__tests__/cli-accepts-exact-filenames.test.js index 9b5aee992b1a..0ef90d7da4fd 100644 --- a/integration-tests/__tests__/cli-accepts-exact-filenames.test.js +++ b/integration-tests/__tests__/cli-accepts-exact-filenames.test.js @@ -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); diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index d27d3b83a603..456edb4a5866 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -209,7 +209,9 @@ 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(fs.existsSync).filter(name => fs.lstatSync(name).isFile()); if (validTestPaths && validTestPaths.length) { return Promise.resolve({tests: toTests(this._context, validTestPaths)}); From 1395d87bcfa60e55abfa45aaa79a28684e4f9ff2 Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Mon, 15 Jan 2018 10:07:25 -0600 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a4ea35d2b2..2bee263f98a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## master +## jest 22.1.1 + +### 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 From 62911f45203e59bbd6b94a0f8e2cbb05f73e7f2b Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Mon, 15 Jan 2018 10:54:04 -0600 Subject: [PATCH 3/4] Cut one FS operation with try-catch --- packages/jest-cli/src/search_source.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index 456edb4a5866..b49fbae44ee1 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -211,7 +211,13 @@ export default class SearchSource { } else { const validTestPaths = paths && - paths.filter(fs.existsSync).filter(name => fs.lstatSync(name).isFile()); + 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)}); From 281a589c6bea0ce432f75ac98d5af6662d7312a5 Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Mon, 15 Jan 2018 11:00:13 -0600 Subject: [PATCH 4/4] Remove jest version number in CHANGELOG --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bee263f98a3..36682127615e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,5 @@ ## master -## jest 22.1.1 - ### Fixes * `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.