Skip to content

Commit

Permalink
Added ability to configure Jest via package.json (#1785)
Browse files Browse the repository at this point in the history
- works when NOT ejected by merging default and app Jest options
- eject simply combines app and default into a single package.json jest field
  • Loading branch information
danjamin committed Apr 25, 2017
1 parent d721d4a commit 367e2b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = (resolve, rootDir, isEjecting) => {
? '<rootDir>/src/setupTests.js'
: undefined;

const appJestConfig = require(paths.appPackageJson).jest;

// TODO: I don't know if it's safe or not to just use / as path separator
// in Jest configs. We need help from somebody with Windows to determine this.
const config = {
Expand All @@ -45,5 +47,10 @@ module.exports = (resolve, rootDir, isEjecting) => {
if (rootDir) {
config.rootDir = rootDir;
}
return config;

if (Object.prototype.toString.call(appJestConfig) === '[object Object]') {
return Object.assign({}, config, appJestConfig);
} else {
return config;
}
};
15 changes: 15 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
- [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files)
- [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page)
- [Running Tests](#running-tests)
- [Configuring Jest](#configuring-jest)
- [Filename Conventions](#filename-conventions)
- [Command Line Interface](#command-line-interface)
- [Version Control Integration](#version-control-integration)
Expand Down Expand Up @@ -924,6 +925,20 @@ While Jest provides browser globals such as `window` thanks to [jsdom](https://g

We recommend that you use a separate tool for browser end-to-end tests if you need them. They are beyond the scope of Create React App.


### Configuring Jest

To override default configurations of Jest, simply add a `jest` field to your `package.json`, for example:

```js
"jest": {
"verbose": true,
"testResultsProcessor": "./node_modules/jest-junit"
},
```

See [Jest Configuration](https://facebook.github.io/jest/docs/configuration.html) for more.

### Filename Conventions

Jest will look for test files with any of the following popular naming conventions:
Expand Down

0 comments on commit 367e2b8

Please sign in to comment.