From d7006506cdc13c57c7d696bb10b29853ad9f5271 Mon Sep 17 00:00:00 2001 From: Rory Hunter Date: Tue, 24 Jan 2017 11:05:33 +0000 Subject: [PATCH] Rename testGlob to testMatch, and remove testMatch deprecation --- docs/Configuration.md | 17 ++++++++-- examples/typescript/package.json | 2 +- integration_tests/__tests__/config-test.js | 2 +- .../typescript-coverage/package.json | 2 +- package.json | 2 +- packages/jest-cli/src/SearchSource.js | 6 ++-- .../src/__tests__/SearchSource-test.js | 32 +++++++++---------- .../__snapshots__/normalize-test.js.snap | 12 ------- .../src/__tests__/normalize-test.js | 24 +++----------- packages/jest-config/src/defaults.js | 2 +- packages/jest-config/src/deprecated.js | 5 --- packages/jest-config/src/normalize.js | 8 ++--- packages/jest-config/src/validConfig.js | 2 +- packages/jest-editor-support/src/Settings.js | 6 ++-- packages/jest-matchers/src/toThrowMatchers.js | 2 +- packages/jest-runtime/src/shouldInstrument.js | 6 ++-- packages/jest-runtime/src/transform.js | 2 +- packages/jest-util/src/messages.js | 6 ++-- types/Config.js | 6 ++-- 19 files changed, 64 insertions(+), 80 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 292974bf4677..1508a28b57f7 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -63,9 +63,10 @@ These options let you control Jest's behavior in your `package.json` file. The J - [`setupTestFrameworkScriptFile` [string]](#setuptestframeworkscriptfile-string) - [`snapshotSerializers` [array]](#snapshotserializers-array-string) - [`testEnvironment` [string]](#testenvironment-string) - - [`testGlob` [string]](#testglob-string-or-array) + - [`testMatch` [array]](#testglob-array-string) - [`testPathDirs` [array]](#testpathdirs-array-string) - [`testPathIgnorePatterns` [array]](#testpathignorepatterns-array-string) + - [`testRegex` [string]](#testregex-string) - [`testResultsProcessor` [string]](#testresultsprocessor-string) - [`testRunner` [string]](#testrunner-string) - [`testURL` [string]](#testurl-string) @@ -347,7 +348,7 @@ Pretty foo: Object { The test environment that will be used for testing. The default environment in Jest is a browser-like environment through [jsdom](https://github.com/tmpvar/jsdom). If you are building a node service, you can use the `node` option to use a node-like environment instead. -### `testGlob` [array] +### `testMatch` [array] (default: `[ '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)' ]`) The glob patterns Jest uses to detect test files. By default it looks for `.js` and `.jsx` files @@ -358,6 +359,9 @@ or `spec.js`. See the [micromatch](https://github.com/jonschlinkert/micromatch) package for details of the patterns you can specify. +See also [`testRegex` [string]](#testregex-string), but note that you +cannot specify both options. + ### `testPathDirs` [array] (default: `[""]`) @@ -372,6 +376,15 @@ An array of regexp pattern strings that are matched against all test paths befor These pattern strings match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/build/", "/node_modules/"]`. +### `testRegex` [string] +(default: `(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$`) + +The pattern Jest uses to detect test files. By default it looks for `.js` and `.jsx` files +inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` +(e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` +or `spec.js`. See also [array]](#testglob-array-string), but note +that you cannot specify both options. + ### `testResultsProcessor` [string] (default: `undefined`) diff --git a/examples/typescript/package.json b/examples/typescript/package.json index d2d8185a6d91..6348d70a2207 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -16,6 +16,6 @@ "transform": { "^.+\\.(ts|tsx)$": "/preprocessor.js" }, - "testGlob": ["**/__tests__/*.(ts|tsx|js)"] + "testMatch": ["**/__tests__/*.(ts|tsx|js)"] } } diff --git a/integration_tests/__tests__/config-test.js b/integration_tests/__tests__/config-test.js index 405d64c005b7..5014d2083549 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', - testGlob: ['banana strawbery kiwi'], + testMatch: ['banana strawbery kiwi'], }), ]); const stdout = result.stdout.toString(); diff --git a/integration_tests/typescript-coverage/package.json b/integration_tests/typescript-coverage/package.json index f45b0522c4d0..38d2afc377cc 100644 --- a/integration_tests/typescript-coverage/package.json +++ b/integration_tests/typescript-coverage/package.json @@ -4,7 +4,7 @@ "transform": { "^.+\\.(ts|js)$": "/typescript-preprocessor.js" }, - "testGlob": ["**/__tests__/*.(ts|tsx|js)"], + "testMatch": ["**/__tests__/*.(ts|tsx|js)"], "testEnvironment": "node", "moduleFileExtensions": [ "ts", diff --git a/package.json b/package.json index 193419831101..5a0759c0f475 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,6 @@ "\\.snap$", "/packages/.*/build" ], - "testGlob": ["**/*-test.js"] + "testMatch": ["**/*-test.js"] } } diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 0f6d6f812ee3..16f15b2c07a9 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -29,7 +29,7 @@ const { } = require('jest-util'); type SearchSourceConfig = { - testGlob: Array, + testMatch: Array, testPathDirs: Array, testRegex: string, testPathIgnorePatterns: Array, @@ -99,7 +99,7 @@ class SearchSource { _testPathDirPattern: RegExp; _testIgnorePattern: ?RegExp; _testPathCases: { - testGlob: (path: Path) => boolean, + testMatch: (path: Path) => boolean, testPathDirs: (path: Path) => boolean, testRegex: (path: Path) => boolean, testPathIgnorePatterns: (path: Path) => boolean, @@ -126,7 +126,7 @@ class SearchSource { ignorePattern.length ? new RegExp(ignorePattern.join('|')) : null; this._testPathCases = { - testGlob: globsToMatcher(config.testGlob), + testMatch: globsToMatcher(config.testMatch), testPathDirs: path => this._testPathDirPattern.test(path), testPathIgnorePatterns: path => ( !this._testIgnorePattern || diff --git a/packages/jest-cli/src/__tests__/SearchSource-test.js b/packages/jest-cli/src/__tests__/SearchSource-test.js index fdfcb7ed1a00..a85d256027d3 100644 --- a/packages/jest-cli/src/__tests__/SearchSource-test.js +++ b/packages/jest-cli/src/__tests__/SearchSource-test.js @@ -16,7 +16,7 @@ const skipOnWindows = require('skipOnWindows'); const rootDir = path.resolve(__dirname, 'test_root'); const testRegex = path.sep + '__testtests__' + path.sep; -const testGlob = ['**/__testtests__/**/*']; +const testMatch = ['**/__testtests__/**/*']; const maxWorkers = 1; let findMatchingTests; @@ -59,7 +59,7 @@ describe('SearchSource', () => { config = normalizeConfig({ name, rootDir: '.', - testGlob: null, + testMatch: null, testPathDirs: [], testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', }); @@ -100,7 +100,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx', 'txt'], name, rootDir, - testGlob: null, + testMatch: null, testRegex: 'not-really-a-test', }); return findMatchingTests(config).then(data => { @@ -113,12 +113,12 @@ describe('SearchSource', () => { }); }); - it('finds tests matching a pattern via testGlob', () => { + it('finds tests matching a pattern via testMatch', () => { const config = normalizeConfig({ moduleFileExtensions: ['js', 'jsx', 'txt'], name, rootDir, - testGlob: ['**/not-really-a-test.txt'], + testMatch: ['**/not-really-a-test.txt'], testRegex: '', }); return findMatchingTests(config).then(data => { @@ -136,7 +136,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx'], name, rootDir, - testGlob: null, + testMatch: null, testRegex: 'test\.jsx?', }); return findMatchingTests(config).then(data => { @@ -155,7 +155,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx'], name, rootDir, - testGlob: ['**/test.js?(x)'], + testMatch: ['**/test.js?(x)'], testRegex: '', }); return findMatchingTests(config).then(data => { @@ -173,7 +173,7 @@ describe('SearchSource', () => { const config = normalizeConfig({ name, rootDir, - testGlob: null, + testMatch: null, testRegex, }); return findMatchingTests(config).then(data => { @@ -187,11 +187,11 @@ describe('SearchSource', () => { }); }); - it('finds tests with default file extensions using testGlob', () => { + it('finds tests with default file extensions using testMatch', () => { const config = normalizeConfig({ name, rootDir, - testGlob, + testMatch, testRegex: '', }); return findMatchingTests(config).then(data => { @@ -210,7 +210,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['jsx'], name, rootDir, - testGlob, + testMatch, }); return findMatchingTests(config).then(data => { const relPaths = data.paths.map(absPath => ( @@ -227,7 +227,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['foobar'], name, rootDir, - testGlob, + testMatch, }); return findMatchingTests(config).then(data => { const relPaths = data.paths.map(absPath => ( @@ -244,7 +244,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx'], name, rootDir, - testGlob, + testMatch, }); return findMatchingTests(config).then(data => { const relPaths = data.paths.map(absPath => ( @@ -261,7 +261,7 @@ describe('SearchSource', () => { const config = normalizeConfig({ name, rootDir, - testGlob: null, + testMatch: null, testRegex, }); return findMatchingTests(config).then(data => { @@ -279,7 +279,7 @@ describe('SearchSource', () => { const config = normalizeConfig({ name, rootDir, - testGlob, + testMatch, testRegex: '', }); return findMatchingTests(config).then(data => { @@ -343,7 +343,7 @@ describe('SearchSource', () => { moduleFileExtensions: ['js', 'jsx', 'foobar'], name, rootDir, - testGlob, + testMatch, }); Runtime.createHasteContext(config, {maxWorkers}).then(hasteMap => { searchSource = new SearchSource(hasteMap, config); diff --git a/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap b/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap index cbe23f0f8d1e..c6c180c9a974 100644 --- a/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap +++ b/packages/jest-config/src/__tests__/__snapshots__/normalize-test.js.snap @@ -15,18 +15,6 @@ exports[`Upgrade help logs a warning when \`scriptPreprocessor\` and/or \`prepro " `; -exports[`Upgrade help logs a warning when \`testRegex\` is used 1`] = ` -"● Deprecation Warning: - - Option testRegex was replaced by testGlob. - - Please update your configuration. - - Configuration Documentation: - https://facebook.github.io/jest/docs/configuration.html -" -`; - exports[`preset throws when preset not found 1`] = ` "● Validation Error: diff --git a/packages/jest-config/src/__tests__/normalize-test.js b/packages/jest-config/src/__tests__/normalize-test.js index dfb68268d6a0..76438ac43437 100644 --- a/packages/jest-config/src/__tests__/normalize-test.js +++ b/packages/jest-config/src/__tests__/normalize-test.js @@ -569,36 +569,22 @@ describe('Upgrade help', () => { expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); }); - - it('logs a warning when `testRegex` is used', () => { - const config = normalize({ - rootDir: '/root/path/foo', - testGlob: [], - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', - }); - - expect(config.testGlob).toEqual([]); - expect(config.testRegex) - .toEqual('(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$'); - - expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); - }); }); -describe('testGlob', () => { - it('testGlob default not applied if testRegex is set', () => { +describe('testMatch', () => { + it('testMatch default not applied if testRegex is set', () => { const config = normalize({ rootDir: '/root', testRegex: '.*', }); - expect(config.testGlob.length).toBe(0); + expect(config.testMatch.length).toBe(0); }); - it('testRegex default not applied if testGlob is set', () => { + it('testRegex default not applied if testMatch is set', () => { const config = normalize({ rootDir: '/root', - testGlob: ['**/*.js'], + testMatch: ['**/*.js'], }); expect(config.testRegex).toBe(''); diff --git a/packages/jest-config/src/defaults.js b/packages/jest-config/src/defaults.js index 1484b5cf3b95..5985647540dd 100644 --- a/packages/jest-config/src/defaults.js +++ b/packages/jest-config/src/defaults.js @@ -48,7 +48,7 @@ module.exports = ({ resetModules: false, snapshotSerializers: [], testEnvironment: 'jest-environment-jsdom', - testGlob: [ + testMatch: [ '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)', ], diff --git a/packages/jest-config/src/deprecated.js b/packages/jest-config/src/deprecated.js index ce659f1b87c6..245fb09a6488 100644 --- a/packages/jest-config/src/deprecated.js +++ b/packages/jest-config/src/deprecated.js @@ -34,11 +34,6 @@ const deprecatedOptions = { } Please update your configuration.`, - - testRegex: (config: Object) => - ` Option ${chalk.bold('testRegex')} was replaced by ${chalk.bold('testGlob')}. - - Please update your configuration.`, }; /* eslint-enable max-len */ diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 8d0b25671b58..ff596aee0be3 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -345,7 +345,7 @@ function normalize(config: InitialConfig, argv: Object = {}) { case 'resetMocks': case 'resetModules': case 'rootDir': - case 'testGlob': + case 'testMatch': case 'testEnvironment': case 'testRegex': case 'testReporter': @@ -372,10 +372,10 @@ function normalize(config: InitialConfig, argv: Object = {}) { } } - if (config.testRegex && (!config.testGlob)) { - // Prevent the default testGlob conflicting with any explicitly + if (config.testRegex && (!config.testMatch)) { + // Prevent the default testMatch conflicting with any explicitly // configured `testRegex` value - newConfig.testGlob = []; + newConfig.testMatch = []; } // If argv.json is set, coverageReporters shouldn't print a text report. diff --git a/packages/jest-config/src/validConfig.js b/packages/jest-config/src/validConfig.js index 7abc46cdc883..3a62fc23cfae 100644 --- a/packages/jest-config/src/validConfig.js +++ b/packages/jest-config/src/validConfig.js @@ -65,7 +65,7 @@ module.exports = ({ silent: true, snapshotSerializers: ['my-serializer-module'], testEnvironment: 'jest-environment-jsdom', - testGlob: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], + testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], testNamePattern: 'test signature', testPathDirs: [''], testPathIgnorePatterns: [NODE_MODULES_REGEXP], diff --git a/packages/jest-editor-support/src/Settings.js b/packages/jest-editor-support/src/Settings.js index 584cbe0278dd..cf4089b0d0d1 100644 --- a/packages/jest-editor-support/src/Settings.js +++ b/packages/jest-editor-support/src/Settings.js @@ -30,7 +30,8 @@ const {jestChildProcessWithArgs} = require('./Process'); type Glob = string; type ConfigRepresentation = { - testGlob: Array + testRegex: string, + testMatch: Array } module.exports = class Settings extends EventEmitter { @@ -46,10 +47,11 @@ module.exports = class Settings extends EventEmitter { // Defaults for a Jest project this.settings = { - testGlob: [ + testMatch: [ '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)', ], + testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$', }; } diff --git a/packages/jest-matchers/src/toThrowMatchers.js b/packages/jest-matchers/src/toThrowMatchers.js index 835fc249b4a5..5f57c3ab9203 100644 --- a/packages/jest-matchers/src/toThrowMatchers.js +++ b/packages/jest-matchers/src/toThrowMatchers.js @@ -152,7 +152,7 @@ const printActualErrorMessage = error => { ' ' + message + formatStackTrace(stack, { noStackTrace: false, rootDir: process.cwd(), - testGlob: [], + testMatch: [], }), ) ); diff --git a/packages/jest-runtime/src/shouldInstrument.js b/packages/jest-runtime/src/shouldInstrument.js index ecd98e1b4321..228d4e14756a 100644 --- a/packages/jest-runtime/src/shouldInstrument.js +++ b/packages/jest-runtime/src/shouldInstrument.js @@ -24,9 +24,9 @@ const shouldInstrument = (filename: Path, config: Config): boolean => { } if ( - config.testGlob && - config.testGlob.length && - micromatch.any(filename, config.testGlob)) { + config.testMatch && + config.testMatch.length && + micromatch.any(filename, config.testMatch)) { return false; } diff --git a/packages/jest-runtime/src/transform.js b/packages/jest-runtime/src/transform.js index 7920b27def71..1c52d9819650 100644 --- a/packages/jest-runtime/src/transform.js +++ b/packages/jest-runtime/src/transform.js @@ -61,7 +61,7 @@ const getCacheKey = ( moduleFileExtensions: config.moduleFileExtensions, moduleNameMapper: config.moduleNameMapper, rootDir: config.rootDir, - testGlob: config.testGlob, + testMatch: config.testMatch, testPathDirs: config.testPathDirs, testRegex: config.testRegex, transformIgnorePatterns: config.transformIgnorePatterns, diff --git a/packages/jest-util/src/messages.js b/packages/jest-util/src/messages.js index 56676efeda70..7da0edc2dc88 100644 --- a/packages/jest-util/src/messages.js +++ b/packages/jest-util/src/messages.js @@ -120,8 +120,8 @@ const formatPaths = ( let filePath = path.relative(config.rootDir, match[2]); // highlight paths from the current test file if ( - (config.testGlob && config.testGlob.length - && micromatch(filePath, config.testGlob)) || + (config.testMatch && config.testMatch.length + && micromatch(filePath, config.testMatch)) || filePath === relativeTestPath ) { filePath = chalk.reset.cyan(filePath); @@ -132,7 +132,7 @@ const formatPaths = ( type StackTraceOptions = { noStackTrace: boolean, rootDir: string, - testGlob: Array, + testMatch: Array, }; const formatStackTrace = ( diff --git a/types/Config.js b/types/Config.js index 25e76f000480..26e05a41adf9 100644 --- a/types/Config.js +++ b/types/Config.js @@ -42,7 +42,7 @@ export type DefaultConfig = {| resetModules: boolean, snapshotSerializers: Array, testEnvironment: string, - testGlob: Array, + testMatch: Array, testPathDirs: Array, testPathIgnorePatterns: Array, testRegex: string, @@ -94,7 +94,7 @@ export type Config = {| silent: boolean, snapshotSerializers: Array, testEnvironment: string, - testGlob: Array, + testMatch: Array, testNamePattern: string, testPathDirs: Array, testPathIgnorePatterns: Array, @@ -154,7 +154,7 @@ export type InitialConfig = {| silent?: boolean, snapshotSerializers?: Array, testEnvironment?: string, - testGlob?: Array, + testMatch?: Array, testNamePattern?: string, testPathDirs?: Array, testPathIgnorePatterns?: Array,