Skip to content

Commit

Permalink
Replace path sep for testRegex in should_instrument (#5560)
Browse files Browse the repository at this point in the history
* Replace path sep for testRegex in should_instrument

so test files don't get instrumented on windows given a pattern like /__tests__/*.js

* move testRegex normalization to jest-config
  • Loading branch information
jwbay authored and cpojer committed Feb 15, 2018
1 parent 71795a5 commit 146900f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## master

### Fixes

* `[jest-runtime]` Align handling of testRegex on Windows between searching for
tests and instrumentation checks
([#5560](https://github.com/facebook/jest/pull/5560))

## jest 22.3.0

### Fixes
Expand Down
3 changes: 0 additions & 3 deletions integration-tests/__tests__/coverage_remapping.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@

const {readFileSync} = require('fs');
const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {cleanup, run} = require('../Utils');
const runJest = require('../runJest');

const dir = path.resolve(__dirname, '../coverage-remapping');
const coverageDir = path.join(dir, 'coverage');

SkipOnWindows.suite();

beforeAll(() => {
cleanup(coverageDir);
});
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-cli/src/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import path from 'path';
import micromatch from 'micromatch';
import DependencyResolver from 'jest-resolve-dependencies';
import testPathPatternToRegExp from './test_path_pattern_to_regexp';
import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';
import {escapePathForRegex} from 'jest-regex-util';

type SearchResult = {|
noSCM?: boolean,
Expand All @@ -36,8 +36,6 @@ export type TestSelectionConfig = {|
watch?: boolean,
|};

const pathToRegex = p => replacePathSepForRegex(p);

const globsToMatcher = (globs: ?Array<Glob>) => {
if (globs == null || globs.length === 0) {
return () => true;
Expand All @@ -52,7 +50,7 @@ const regexToMatcher = (testRegex: string) => {
return () => true;
}

const regex = new RegExp(pathToRegex(testRegex));
const regex = new RegExp(testRegex);
return path => regex.test(path);
};

Expand Down
4 changes: 3 additions & 1 deletion packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ export default function normalize(options: InitialOptions, argv: Argv) {
options[key],
);
break;
case 'testRegex':
value = options[key] && replacePathSepForRegex(options[key]);
break;
case 'automock':
case 'bail':
case 'browser':
Expand Down Expand Up @@ -506,7 +509,6 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'testFailureExitCode':
case 'testLocationInResults':
case 'testNamePattern':
case 'testRegex':
case 'testURL':
case 'timers':
case 'useStderr':
Expand Down

0 comments on commit 146900f

Please sign in to comment.