Skip to content

Commit

Permalink
new module defaults (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored and cpojer committed Sep 14, 2016
1 parent ab1d7f5 commit 2699ed5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1029,11 +1029,11 @@ Note that, if you specify a global reference value (like an object or array) her
A pattern that is matched against file paths to determine which folder contains manual mocks.

### `moduleFileExtensions` [array<string>]
(default: `['js', 'json', 'node']`)
(default: `['js', 'json', 'jsx', 'node']`)

An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for.

If you are using TypeScript this should be `['js', 'json', 'ts']`
If you are using TypeScript this should be `['js', 'jsx', 'json', 'ts', 'tsx']`

### `modulePathIgnorePatterns` [array<string>]
(default: `[]`)
Expand Down Expand Up @@ -1158,9 +1158,9 @@ A regexp pattern string that is matched against all test paths before executing
This is useful if you need to override the default. If you are testing one file at a time the default will be set to `/.*/`, however if you pass a blob rather than a single file the default will then be the absolute path of each test file. The override may be needed on windows machines where, for example, the test full path would be `C:/myproject/__tests__/mystest.jsx.jest` and the default pattern would be set as `/C:\myproject\__tests__\mystest.jsx.jest/`.

### `testRegex` [string]
(default: `(/__tests__/.*|\\.(test|spec))\\.js$`)
(default: `(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$`)

The pattern Jest uses to detect test files. By default it looks for `.js` files
The pattern Jest uses to detect test files. By default it looks for `.js` and `.jsx` files
inside of `__tests__` folders.

### `testResultsProcessor` [string]
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"test": "jest"
},
"jest": {
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"moduleFileExtensions": ["ts", "tsx", "js"],
"scriptPreprocessor": "<rootDir>/preprocessor.js",
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$"
}
}
3 changes: 2 additions & 1 deletion packages/jest-cli/src/__tests__/SearchSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ describe('SearchSource', () => {
const relPaths = data.paths.map(absPath => (
path.relative(rootDir, absPath)
));
expect(relPaths).toEqual([
expect(relPaths.sort()).toEqual([
path.normalize('__testtests__/test.js'),
path.normalize('__testtests__/test.jsx'),
]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports[`normalize Upgrade help throws when using old configuration options 3`]
exports[`normalize Upgrade help throws when using old configuration options 4`] = `
"The settings \`testDirectoryName\` and \`testFileExtensions\` were removed from Jest. Instead, use \`testRegex\` like this:
\"testRegex\": \"(/test/.*|\\\\.(test|spec))\\\\.(js|json|node)$\"
\"testRegex\": \"(/test/.*|\\\\.(test|spec))\\\\.(js|json|jsx|node)$\"
Jest 15 changed the default configuration for tests and makes Jest easier to
use and less confusing for beginners. All previous defaults can be restored
Expand All @@ -93,7 +93,7 @@ exports[`normalize Upgrade help throws when using old configuration options 4`]
exports[`normalize Upgrade help throws when using old configuration options 5`] = `
"The settings \`testDirectoryName\` and \`testFileExtensions\` were removed from Jest. Instead, use \`testRegex\` like this:
\"testRegex\": \"(/__tests__/.*|\\\\.(test|spec))\\\\.(js|ts|json|node)$\"
\"testRegex\": \"(/__tests__/.*|\\\\.(test|spec))\\\\.(js|ts|json|jsx|node)$\"
Jest 15 changed the default configuration for tests and makes Jest easier to
use and less confusing for beginners. All previous defaults can be restored
Expand Down
9 changes: 7 additions & 2 deletions packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ module.exports = ({
},
mocksPattern: '__mocks__',
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['js', 'json', 'node'],
moduleFileExtensions: [
'js',
'json',
'jsx',
'node',
],
moduleNameMapper: {},
modulePathIgnorePatterns: [],
noStackTrace: false,
Expand All @@ -45,7 +50,7 @@ module.exports = ({
testPathIgnorePatterns: [
utils.replacePathSepForRegex(constants.NODE_MODULES),
],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.js$',
testRegex: '(/__tests__/.*|\\.(test|spec))\\.jsx?$',
testURL: 'about:blank',
timers: 'real',
useStderr: false,
Expand Down

0 comments on commit 2699ed5

Please sign in to comment.