Skip to content

Commit

Permalink
[#69] Apply danger-plugin-istanbul-coverage following vote
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Apr 21, 2022
1 parent 02c595e commit d03cd62
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
5 changes: 5 additions & 0 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"scripts": {
"start": "react-scripts -r @cypress/instrument-cra start",
"test:coverage": "react-scripts test --coverage --watchAll=false && npm run cypress:run && node ./scripts/coverage-merge.js && nyc report",
"test:merge-coverage": "node ./scripts/coverage-merge.js",
"lint": "eslint ./src ./cypress --ext .ts,.tsx",
"lint:fix": "eslint ./src ./cypress --ext .ts,.tsx --fix",
"stylelint": "stylelint '**/*.scss'",
Expand All @@ -65,6 +66,10 @@
},
"devDependencies": {
"@cypress/instrument-cra": "1.4.0",
"danger": "10.9.0",
"danger-plugin-code-coverage": "1.1.9",
"danger-plugin-istanbul-coverage": "1.6.2",
"danger-plugin-jest-codecov": "0.0.8",
"start-server-and-test": "1.14.0"
}
}
Expand Down
38 changes: 10 additions & 28 deletions template/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: push
on: pull_request

jobs:
test:
Expand Down Expand Up @@ -28,33 +28,15 @@ jobs:
run: npm run lint

- name: Run unit tests
run: npm run test
run: npm test -- --coverage

cypress-run:
name: Run Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cypress run
uses: cypress-io/github-action@v2
with:
build: npm run build
start: npm start
- name: Run integration tests
run: npm run cypress

coverage:
name: Merge coverage data
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Merge code coverage reports
run: npm run test:merge-coverage

- name: Jest Coverage report
uses: artiomtr/jest-coverage-report-action@v2.0.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
package-manager: npm
test-script: npm run test
threshold: 80 # prevent PR merge under 80% coverage
- name: Danger
run: npx danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions template/dangerfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { schedule } from 'danger';
import { istanbulCoverage } from 'danger-plugin-istanbul-coverage';

schedule(
istanbulCoverage({
// Set a custom success message
customSuccessMessage: 'Congrats, coverage is good',

// Set a custom failure message
customFailureMessage: 'Coverage is a little low, take a look',

// How to sort the entries in the table
entrySortMethod: 'least-coverage', // || 'alphabetically' || 'most-coverage' || 'largest-file-size' ||'smallest-file-size' || 'uncovered-lines'

// Add a maximum number of entries to display
numberOfEntries: 15,

// The location of the istanbul coverage file.
// coveragePath: './.nyc_output/out.json', // The merged JSON coverage data
// Alternatively, if you have multiple coverage summaries, you can merge them into one report
// coveragePaths: ["./coverage/reports/from-cypress.json", "./coverage/reports/from-jest.json"],
// You can also specify the format, instead of letting it be inferred from the file name
coveragePath: { path: './coverage/merged/lcov.info', type: 'lcov' /* || "json-summary" */ },

// Which set of files to summarise from the coverage file.
reportFileSet: 'all', // || "modified" || "created" || "createdOrModified"

// What to do when the PR doesn't meet the minimum code coverage threshold
reportMode: 'message', // || "warn" || "fail"

// Minimum coverage threshold percentages. Compared against the cumulative coverage of the reportFileSet.
threshold: {
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
})
);

0 comments on commit d03cd62

Please sign in to comment.