Skip to content

Commit

Permalink
Allow to pass the exact test filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
valerybugakov committed Jun 24, 2017
1 parent 04d05e5 commit 8137ae2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: []});
}
}
}
}
Expand Down

0 comments on commit 8137ae2

Please sign in to comment.