From 8137ae230d46c503049c5be39cf1a7e4a556f804 Mon Sep 17 00:00:00 2001 From: Valery Bugakov Date: Tue, 20 Jun 2017 13:02:31 +0400 Subject: [PATCH] Allow to pass the exact test filenames --- packages/jest-cli/src/SearchSource.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index c71b2456e90b..83d62b067360 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -13,6 +13,7 @@ import type {Glob, Path} from 'types/Config'; import type {ResolveModuleConfig} from 'types/Resolve'; import type {Test} from 'types/TestRunner'; +import fs from 'fs'; import path from 'path'; import micromatch from 'micromatch'; import DependencyResolver from 'jest-resolve-dependencies'; @@ -76,6 +77,15 @@ const toTests = (context, tests) => path, })); +const fileExists = (filePath: string) => { + try { + fs.accessSync(filePath, fs.F_OK); + return true; + } catch (e) { + return false; + } +}; + class SearchSource { _context: Context; _options: ResolveModuleConfig; @@ -230,12 +240,16 @@ class SearchSource { return Promise.resolve( this.findRelatedTestsFromPattern(testSelectionConfig.paths), ); - } else if (testSelectionConfig.testPathPattern != null) { - return Promise.resolve( - this.findMatchingTests(testSelectionConfig.testPathPattern), - ); } else { - return Promise.resolve({tests: []}); + const validTestPaths = testSelectionConfig.paths && testSelectionConfig.paths.filter(fileExists); + + if (validTestPaths && validTestPaths.length) { + return Promise.resolve({tests: toTests(this._context, validTestPaths)}); + } else if (testSelectionConfig.testPathPattern != null) { + return Promise.resolve(this.findMatchingTests(testSelectionConfig.testPathPattern)); + } else { + return Promise.resolve({tests: []}); + } } } }