Skip to content

Commit

Permalink
feat: include preset with defaults for prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
keplersj committed Aug 26, 2019
1 parent 3f21fc2 commit c4c5283
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,46 @@

### Install

Install `jest`_(it needs Jest 21+)_ and `jest-runner-prettier`
Install `jest`, `prettier` and `jest-runner-prettier`

```bash
yarn add --dev jest jest-runner-prettier
yarn add --dev jest prettier jest-runner-prettier

# or with NPM

npm install --save-dev jest jest-runner-prettier
npm install --save-dev jest prettier jest-runner-prettier
```

### Add it to your Jest config

#### Using Built-in Preset

This package includes a [Jest preset](https://jestjs.io/docs/en/configuration#preset-string) which configures Jest to run Prettier on all files supported by Prettier. To use it set the following in your `package.json`:

```json
{
"jest": {
"preset": "jest-runner-prettier"
}
}
```

or `jest.config.js`:

```js
module.exports = {
preset: "jest-runner-prettier"
};
```

#### Manually

In your `package.json`

```json
{
"jest": {
"runner": "jest-runner-prettier",
"runner": "prettier",
"moduleFileExtensions": [
"js",
"jsx",
Expand Down Expand Up @@ -74,7 +96,7 @@ Or in `jest.config.js`

```js
module.exports = {
runner: "jest-runner-prettier",
runner: "prettier",
moduleFileExtensions: [
"js",
"jsx",
Expand Down Expand Up @@ -107,5 +129,9 @@ module.exports = {
### Run Jest

```bash
npx jest

# or, with yarn

yarn jest
```
29 changes: 29 additions & 0 deletions jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
runner: "prettier",
moduleFileExtensions: [
"js",
"jsx",
"json",
"ts",
"tsx",
"css",
"less",
"scss",
"graphql",
"md",
"markdown"
],
testMatch: [
"**/*.js",
"**/*.jsx",
"**/*.json",
"**/*.ts",
"**/*.tsx",
"**/*.css",
"**/*.less",
"**/*.scss",
"**/*.graphql",
"**/*.md",
"**/*.markdown"
]
};

0 comments on commit c4c5283

Please sign in to comment.