-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest): create Jest danger plugin (#1)
- Loading branch information
Showing
10 changed files
with
4,509 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,81 @@ | ||
# danger-plugin-jest | ||
|
||
TODO | ||
[](https://travis-ci.org/macklinu/danger-plugin-jest) | ||
[](https://badge.fury.io/js/danger-plugin-jest) | ||
[](https://github.com/semantic-release/semantic-release) | ||
|
||
> [Danger](https://github.com/danger/danger-js) plugin for Jest | ||
## Usage | ||
|
||
### Setup Jest | ||
|
||
This Danger plugin relies on modifying your Jest configuration. | ||
|
||
Install [jest-json-reporter](https://github.com/Vall3y/jest-json-reporter): | ||
|
||
```sh | ||
yarn add jest-json-reporter --dev | ||
``` | ||
|
||
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`): | ||
|
||
```json | ||
{ | ||
"jest": { | ||
"testResultsProcessor": "jest-json-reporter" | ||
}, | ||
"jestJsonReporter": { | ||
"outputFile": "tests/results.json" | ||
} | ||
} | ||
``` | ||
|
||
> You may also want to add the JSON output file to your `.gitignore`, since it doesn't need to be checked into source control. | ||
### Setup Danger | ||
|
||
Install this Danger plugin: | ||
|
||
```sh | ||
yarn add danger-plugin-jest --dev | ||
``` | ||
|
||
If you set `jestJsonReporter.outputFile` in your `package.json`, make sure that `testResultsJsonPath` matches that path: | ||
|
||
```js | ||
// dangerfile.js | ||
import path from 'path' | ||
import jest from 'danger-plugin-jest' | ||
|
||
jest({ | ||
testResultsJsonPath: path.resolve(__dirname, 'tests/results.json'), | ||
}) | ||
``` | ||
|
||
If you _did not_ change the `jestJsonReporter.outputFile` path in your `package.json`, you can just do the following: | ||
|
||
```js | ||
// dangerfile.js | ||
import jest from 'danger-plugin-jest' | ||
|
||
jest() | ||
``` | ||
|
||
See [`src/index.ts`](https://github.com/macklinu/danger-plugin-jest/blob/master/src/index.ts) for more details. | ||
|
||
## Changelog | ||
|
||
See the GitHub [release history](https://github.com/macklinu/danger-plugin-jest/releases). | ||
|
||
## Development | ||
|
||
Install [Yarn](https://yarnpkg.com/en/), and install the dependencies - `yarn install`. | ||
|
||
Run the [Jest](https://facebook.github.io/jest/) test suite with `yarn test`. | ||
|
||
This project uses [semantic-release](https://github.com/semantic-release/semantic-release) for automated NPM package publishing. | ||
|
||
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). | ||
|
||
:heart: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* A simple formatter that formats only test failures for use by Danger. | ||
*/ | ||
export class TestFailureFormatter { | ||
constructor(private results: any) {} | ||
|
||
public format(): string { | ||
return this.results.testResults | ||
.filter((r: any) => r.failureMessage) | ||
.map((r: any) => r.failureMessage) | ||
.join('\n') | ||
} | ||
} |
Oops, something went wrong.