Skip to content

Commit

Permalink
Rename testGlob to testMatch, and remove testMatch deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
pugnascotia committed Jan 24, 2017
1 parent 1b0f158 commit d700650
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 80 deletions.
17 changes: 15 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>]](#snapshotserializers-array-string)
- [`testEnvironment` [string]](#testenvironment-string)
- [`testGlob` [string]](#testglob-string-or-array)
- [`testMatch` [array<string>]](#testglob-array-string)
- [`testPathDirs` [array<string>]](#testpathdirs-array-string)
- [`testPathIgnorePatterns` [array<string>]](#testpathignorepatterns-array-string)
- [`testRegex` [string]](#testregex-string)
- [`testResultsProcessor` [string]](#testresultsprocessor-string)
- [`testRunner` [string]](#testrunner-string)
- [`testURL` [string]](#testurl-string)
Expand Down Expand Up @@ -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<string>]
### `testMatch` [array<string>]
(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
Expand All @@ -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<string>]
(default: `["<rootDir>"]`)

Expand All @@ -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 `<rootDir>` 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: `["<rootDir>/build/", "<rootDir>/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<string>]](#testglob-array-string), but note
that you cannot specify both options.

### `testResultsProcessor` [string]
(default: `undefined`)

Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"transform": {
"^.+\\.(ts|tsx)$": "<rootDir>/preprocessor.js"
},
"testGlob": ["**/__tests__/*.(ts|tsx|js)"]
"testMatch": ["**/__tests__/*.(ts|tsx|js)"]
}
}
2 changes: 1 addition & 1 deletion integration_tests/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/typescript-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"transform": {
"^.+\\.(ts|js)$": "<rootDir>/typescript-preprocessor.js"
},
"testGlob": ["**/__tests__/*.(ts|tsx|js)"],
"testMatch": ["**/__tests__/*.(ts|tsx|js)"],
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@
"\\.snap$",
"/packages/.*/build"
],
"testGlob": ["**/*-test.js"]
"testMatch": ["**/*-test.js"]
}
}
6 changes: 3 additions & 3 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
} = require('jest-util');

type SearchSourceConfig = {
testGlob: Array<Glob>,
testMatch: Array<Glob>,
testPathDirs: Array<Path>,
testRegex: string,
testPathIgnorePatterns: Array<string>,
Expand Down Expand Up @@ -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,
Expand All @@ -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 ||
Expand Down
32 changes: 16 additions & 16 deletions packages/jest-cli/src/__tests__/SearchSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('SearchSource', () => {
config = normalizeConfig({
name,
rootDir: '.',
testGlob: null,
testMatch: null,
testPathDirs: [],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$',
});
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -136,7 +136,7 @@ describe('SearchSource', () => {
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testGlob: null,
testMatch: null,
testRegex: 'test\.jsx?',
});
return findMatchingTests(config).then(data => {
Expand All @@ -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 => {
Expand All @@ -173,7 +173,7 @@ describe('SearchSource', () => {
const config = normalizeConfig({
name,
rootDir,
testGlob: null,
testMatch: null,
testRegex,
});
return findMatchingTests(config).then(data => {
Expand All @@ -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 => {
Expand All @@ -210,7 +210,7 @@ describe('SearchSource', () => {
moduleFileExtensions: ['jsx'],
name,
rootDir,
testGlob,
testMatch,
});
return findMatchingTests(config).then(data => {
const relPaths = data.paths.map(absPath => (
Expand All @@ -227,7 +227,7 @@ describe('SearchSource', () => {
moduleFileExtensions: ['foobar'],
name,
rootDir,
testGlob,
testMatch,
});
return findMatchingTests(config).then(data => {
const relPaths = data.paths.map(absPath => (
Expand All @@ -244,7 +244,7 @@ describe('SearchSource', () => {
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testGlob,
testMatch,
});
return findMatchingTests(config).then(data => {
const relPaths = data.paths.map(absPath => (
Expand All @@ -261,7 +261,7 @@ describe('SearchSource', () => {
const config = normalizeConfig({
name,
rootDir,
testGlob: null,
testMatch: null,
testRegex,
});
return findMatchingTests(config).then(data => {
Expand All @@ -279,7 +279,7 @@ describe('SearchSource', () => {
const config = normalizeConfig({
name,
rootDir,
testGlob,
testMatch,
testRegex: '',
});
return findMatchingTests(config).then(data => {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 5 additions & 19 deletions packages/jest-config/src/__tests__/normalize-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = ({
resetModules: false,
snapshotSerializers: [],
testEnvironment: 'jest-environment-jsdom',
testGlob: [
testMatch: [
'**/__tests__/**/*.js?(x)',
'**/?(*.)(spec|test).js?(x)',
],
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-config/src/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
8 changes: 4 additions & 4 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/validConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ['<rootDir>'],
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-editor-support/src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const {jestChildProcessWithArgs} = require('./Process');
type Glob = string;

type ConfigRepresentation = {
testGlob: Array<Glob>
testRegex: string,
testMatch: Array<Glob>
}

module.exports = class Settings extends EventEmitter {
Expand All @@ -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?$',
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/toThrowMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const printActualErrorMessage = error => {
' ' + message + formatStackTrace(stack, {
noStackTrace: false,
rootDir: process.cwd(),
testGlob: [],
testMatch: [],
}),
)
);
Expand Down
Loading

0 comments on commit d700650

Please sign in to comment.