Skip to content

Commit

Permalink
Replace path sep for testRegex in should_instrument
Browse files Browse the repository at this point in the history
so test files don't get instrumented on windows given a pattern like /__tests__/*.js
  • Loading branch information
jwbay committed Feb 14, 2018
1 parent c5fbd30 commit 3c753bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 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]` Replace path sep for testRegex in should_instrument so test
files don't get instrumented on windows given a pattern like /__tests__/*.js
([#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
7 changes: 5 additions & 2 deletions packages/jest-runtime/src/should_instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {Path, ProjectConfig} from 'types/Config';
import type {Options} from './script_transformer';

import path from 'path';
import {escapePathForRegex} from 'jest-regex-util';
import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';
import micromatch from 'micromatch';

const MOCKS_PATTERN = new RegExp(
Expand All @@ -35,7 +35,10 @@ export default function shouldInstrument(
return true;
}

if (config.testRegex && filename.match(config.testRegex)) {
if (
config.testRegex &&
new RegExp(replacePathSepForRegex(config.testRegex)).test(filename)
) {
return false;
}

Expand Down

0 comments on commit 3c753bf

Please sign in to comment.