|
1 | 1 | # danger-plugin-jest
|
2 | 2 |
|
3 |
| -TODO |
| 3 | +[](https://travis-ci.org/macklinu/danger-plugin-jest) |
| 4 | +[](https://badge.fury.io/js/danger-plugin-jest) |
| 5 | +[](https://github.com/semantic-release/semantic-release) |
| 6 | + |
| 7 | +> [Danger](https://github.com/danger/danger-js) plugin for Jest |
| 8 | +
|
| 9 | +## Usage |
| 10 | + |
| 11 | +### Setup Jest |
| 12 | + |
| 13 | +This Danger plugin relies on modifying your Jest configuration. |
| 14 | + |
| 15 | +Install [jest-json-reporter](https://github.com/Vall3y/jest-json-reporter): |
| 16 | + |
| 17 | +```sh |
| 18 | +yarn add jest-json-reporter --dev |
| 19 | +``` |
| 20 | + |
| 21 | +Modify your `package.json` to process test results with jest-json-reporter. You may optionally set the output path of the JSON test results using the `jestJsonReporter.outputFile` path (which otherwise defaults to `./test-results.json`): |
| 22 | + |
| 23 | +```json |
| 24 | +{ |
| 25 | + "jest": { |
| 26 | + "testResultsProcessor": "jest-json-reporter" |
| 27 | + }, |
| 28 | + "jestJsonReporter": { |
| 29 | + "outputFile": "tests/results.json" |
| 30 | + } |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +> You may also want to add the JSON output file to your `.gitignore`, since it doesn't need to be checked into source control. |
| 35 | +
|
| 36 | +### Setup Danger |
| 37 | + |
| 38 | +Install this Danger plugin: |
| 39 | + |
| 40 | +```sh |
| 41 | +yarn add danger-plugin-jest --dev |
| 42 | +``` |
| 43 | + |
| 44 | +If you set `jestJsonReporter.outputFile` in your `package.json`, make sure that `testResultsJsonPath` matches that path: |
| 45 | + |
| 46 | +```js |
| 47 | +// dangerfile.js |
| 48 | +import path from 'path' |
| 49 | +import jest from 'danger-plugin-jest' |
| 50 | + |
| 51 | +jest({ |
| 52 | + testResultsJsonPath: path.resolve(__dirname, 'tests/results.json'), |
| 53 | +}) |
| 54 | +``` |
| 55 | + |
| 56 | +If you _did not_ change the `jestJsonReporter.outputFile` path in your `package.json`, you can just do the following: |
| 57 | + |
| 58 | +```js |
| 59 | +// dangerfile.js |
| 60 | +import jest from 'danger-plugin-jest' |
| 61 | + |
| 62 | +jest() |
| 63 | +``` |
| 64 | + |
| 65 | +See [`src/index.ts`](https://github.com/macklinu/danger-plugin-jest/blob/master/src/index.ts) for more details. |
| 66 | + |
| 67 | +## Changelog |
| 68 | + |
| 69 | +See the GitHub [release history](https://github.com/macklinu/danger-plugin-jest/releases). |
| 70 | + |
| 71 | +## Development |
| 72 | + |
| 73 | +Install [Yarn](https://yarnpkg.com/en/), and install the dependencies - `yarn install`. |
| 74 | + |
| 75 | +Run the [Jest](https://facebook.github.io/jest/) test suite with `yarn test`. |
| 76 | + |
| 77 | +This project uses [semantic-release](https://github.com/semantic-release/semantic-release) for automated NPM package publishing. |
| 78 | + |
| 79 | +The main caveat: instead of running `git commit`, run `yarn commit` and follow the prompts to input a conventional changelog message via [commitizen](https://github.com/commitizen/cz-cli). |
| 80 | + |
| 81 | +:heart: |
0 commit comments