Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to configure Jest via package.json #1990

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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