From c4c5283bf48c7578b46a5c001432daa196feb6fa Mon Sep 17 00:00:00 2001 From: Kepler Sticka-Jones Date: Mon, 26 Aug 2019 14:16:19 -0600 Subject: [PATCH] feat: include preset with defaults for prettier --- README.md | 36 +++++++++++++++++++++++++++++++----- jest-preset.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 jest-preset.js diff --git a/README.md b/README.md index 0f780ff..2f549d1 100644 --- a/README.md +++ b/README.md @@ -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", @@ -74,7 +96,7 @@ Or in `jest.config.js` ```js module.exports = { - runner: "jest-runner-prettier", + runner: "prettier", moduleFileExtensions: [ "js", "jsx", @@ -107,5 +129,9 @@ module.exports = { ### Run Jest ```bash +npx jest + +# or, with yarn + yarn jest ``` diff --git a/jest-preset.js b/jest-preset.js new file mode 100644 index 0000000..334997a --- /dev/null +++ b/jest-preset.js @@ -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" + ] +};