diff --git a/.gitignore b/.gitignore index 5538cb11cd25..e0e4665a3698 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,6 @@ .eslintcache *.swp *~ -.idea -*.iml /examples/*/node_modules/ /integration_tests/*/node_modules /integration_tests/transform/*/coverage diff --git a/integration_tests/__tests__/config-test.js b/integration_tests/__tests__/config-test.js index ddbf852542c9..405d64c005b7 100644 --- a/integration_tests/__tests__/config-test.js +++ b/integration_tests/__tests__/config-test.js @@ -18,7 +18,7 @@ test('config as JSON', () => { const result = runJest('verbose_reporter', [ '--config=' + JSON.stringify({ testEnvironment: 'node', - testRegex: 'banana strawbery kiwi', + testGlob: ['banana strawbery kiwi'], }), ]); const stdout = result.stdout.toString(); diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 4c851d7094a6..0f6d6f812ee3 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -15,7 +15,7 @@ import type {HasteContext} from 'types/HasteMap'; import type {Glob, Path} from 'types/Config'; import type {ResolveModuleConfig} from 'jest-resolve'; -const mm = require('micromatch'); +const micromatch = require('micromatch'); const DependencyResolver = require('jest-resolve-dependencies'); @@ -78,13 +78,13 @@ const globsToMatcher = (globs: ?Array) => { return () => true; } - const matchers = globs.map(each => mm.matcher(each)); + const matchers = globs.map(each => micromatch.matcher(each)); return (path: Path) => matchers.some(each => each(path)); }; const regexToMatcher = (testRegex: string) => { - if (!testRegex.length) { + if (!testRegex) { return () => true; } diff --git a/packages/jest-cli/src/__tests__/SearchSource-test.js b/packages/jest-cli/src/__tests__/SearchSource-test.js index f1fa2bfdddc9..fdfcb7ed1a00 100644 --- a/packages/jest-cli/src/__tests__/SearchSource-test.js +++ b/packages/jest-cli/src/__tests__/SearchSource-test.js @@ -59,7 +59,7 @@ describe('SearchSource', () => { config = normalizeConfig({ name, rootDir: '.', - testGlob: [], + testGlob: null, testPathDirs: [], testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', }); @@ -100,7 +100,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx', 'txt'], name, rootDir, - testGlob: [], + testGlob: null, testRegex: 'not-really-a-test', }); return findMatchingTests(config).then(data => { @@ -136,7 +136,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx'], name, rootDir, - testGlob: [], + testGlob: null, testRegex: 'test\.jsx?', }); return findMatchingTests(config).then(data => { @@ -173,7 +173,7 @@ describe('SearchSource', () => { const config = normalizeConfig({ name, rootDir, - testGlob: [], + testGlob: null, testRegex, }); return findMatchingTests(config).then(data => { @@ -261,7 +261,7 @@ describe('SearchSource', () => { const config = normalizeConfig({ name, rootDir, - testGlob: [], + testGlob: null, testRegex, }); return findMatchingTests(config).then(data => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 727ab5d6ab0b..8d0b25671b58 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -319,11 +319,6 @@ function normalize(config: InitialConfig, argv: Object = {}) { case 'unmockedModulePathPatterns': value = normalizeUnmockedModulePathPatterns(config, key); break; - - case 'testRegex': - value = config[key]; - break; - case 'automock': case 'bail': case 'browser': @@ -352,6 +347,7 @@ function normalize(config: InitialConfig, argv: Object = {}) { case 'rootDir': case 'testGlob': case 'testEnvironment': + case 'testRegex': case 'testReporter': case 'testRunner': case 'testURL': @@ -376,8 +372,9 @@ function normalize(config: InitialConfig, argv: Object = {}) { } } - if (config.testRegex && (!config.testGlob || config.testGlob.length === 0)) { - // Prevent default glob conflicting with any explicit `testRegex` value + if (config.testRegex && (!config.testGlob)) { + // Prevent the default testGlob conflicting with any explicitly + // configured `testRegex` value newConfig.testGlob = []; } diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index ae5b8db50f09..584cbe0278dd 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -30,7 +30,6 @@ const {jestChildProcessWithArgs} = require('./Process'); type Glob = string; type ConfigRepresentation = { - testRegex: string, testGlob: Array } @@ -51,7 +50,6 @@ module.exports = class Settings extends EventEmitter { '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)', ], - testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', }; } diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index 1380de8cdf1d..ecd98e1b4321 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -23,8 +23,10 @@ const shouldInstrument = (filename: Path, config: Config): boolean => { return false; } - if (config.testGlob && config.testGlob.length - && micromatch.any(filename, config.testGlob)) { + if ( + config.testGlob && + config.testGlob.length && + micromatch.any(filename, config.testGlob)) { return false; } diff --git a/packages/jest-util/src/messages.js b/packages/jest-util/src/messages.js index a7b9fe9d3e9c..56676efeda70 100644 --- a/packages/jest-util/src/messages.js +++ b/packages/jest-util/src/messages.js @@ -13,7 +13,7 @@ import type {Config, Glob, Path} from 'types/Config'; import type {AssertionResult, TestResult} from 'types/TestResult'; const chalk = require('chalk'); -const mm = require('micromatch'); +const micromatch = require('micromatch'); const path = require('path'); const separateMessageFromStack = require('./separateMessageFromStack'); @@ -121,7 +121,7 @@ const formatPaths = ( // highlight paths from the current test file if ( (config.testGlob && config.testGlob.length - && mm(filePath, config.testGlob)) || + && micromatch(filePath, config.testGlob)) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath);