From 146900f5d36691ab706aafee19e747a4de6cdd71 Mon Sep 17 00:00:00 2001 From: jwbay Date: Thu, 15 Feb 2018 04:23:58 -0500 Subject: [PATCH] Replace path sep for testRegex in should_instrument (#5560) * 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 --- CHANGELOG.md | 6 ++++++ integration-tests/__tests__/coverage_remapping.test.js | 3 --- packages/jest-cli/src/search_source.js | 6 ++---- packages/jest-config/src/normalize.js | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9aa036b0f0..bb25306b68a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/integration-tests/__tests__/coverage_remapping.test.js b/integration-tests/__tests__/coverage_remapping.test.js index 44cf0fd77a77..15d5f8b1a09a 100644 --- a/integration-tests/__tests__/coverage_remapping.test.js +++ b/integration-tests/__tests__/coverage_remapping.test.js @@ -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); }); diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index 6f153467be58..efb39ba054a0 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -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, @@ -36,8 +36,6 @@ export type TestSelectionConfig = {| watch?: boolean, |}; -const pathToRegex = p => replacePathSepForRegex(p); - const globsToMatcher = (globs: ?Array) => { if (globs == null || globs.length === 0) { return () => true; @@ -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); }; diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 8a7acc71e365..77f91ff48aa3 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -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': @@ -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':