diff --git a/packages/jest-cli/src/__tests__/search_source.test.js b/packages/jest-cli/src/__tests__/search_source.test.js index f611865a72d5..d42787540544 100644 --- a/packages/jest-cli/src/__tests__/search_source.test.js +++ b/packages/jest-cli/src/__tests__/search_source.test.js @@ -463,5 +463,24 @@ describe('SearchSource', () => { path.join(rootDir, '__testtests__', 'test.jsx'), ]); }); + + it('does not mistake roots folders with prefix names', async () => { + const config = normalize( + { + name, + rootDir: '.', + roots: ['/foo/bar/prefix'], + }, + {}, + ).options; + + searchSource = new SearchSource( + await Runtime.createContext(config, {maxWorkers}), + ); + + const input = ['/foo/bar/prefix-suffix/__tests__/my-test.test.js']; + const data = searchSource.findTestsByPaths(input); + expect(data.tests).toEqual([]); + }); }); }); diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index d20bb18ef264..6f153467be58 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -78,7 +78,7 @@ export default class SearchSource { const {config} = context; this._context = context; this._rootPattern = new RegExp( - config.roots.map(dir => escapePathForRegex(dir)).join('|'), + config.roots.map(dir => escapePathForRegex(dir + path.sep)).join('|'), ); const ignorePattern = config.testPathIgnorePatterns;