Skip to content

Commit

Permalink
escape testPathDirs before constructing regexes (#1379)
Browse files Browse the repository at this point in the history
* escape testPathDirs before constructing regexes

* check for failed path parsing

* remove extraneous argument from test call

* assert that tests have been found and have passed
  • Loading branch information
rimunroe authored and cpojer committed Aug 9, 2016
1 parent 98fa963 commit b56e368
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions integration_tests/__tests__/regex-(char-in-path-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

const runJest = require('../runJest');

describe('Regex Char In Path', () => {
it('parses paths containing regex chars correctly', () => {
const {json} = runJest.json('regex-(char-in-path', []);

expect(json.numTotalTests).toBe(1);
expect(json.numPassedTests).toBe(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

'use strict';

it('runs this', () => {
expect(true).toBe(true);
});
1 change: 1 addition & 0 deletions integration_tests/regex-(char-in-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 3 additions & 1 deletion packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class SearchSource {
this._options = options || {};

this._testPathDirPattern =
new RegExp(config.testPathDirs.map(dir => pathToRegex(dir)).join('|'));
new RegExp(config.testPathDirs.map(dir => {
return pathToRegex(utils.escapeStrForRegex(dir));
}).join('|'));
this._testRegex = new RegExp(pathToRegex(config.testRegex));
const ignorePattern = config.testPathIgnorePatterns;
this._testIgnorePattern =
Expand Down

0 comments on commit b56e368

Please sign in to comment.