This GitHub Action requires writing the tests in Pull Requests, by requesting changes and posting a comment if tests are missing.
To install it, copy and paste the following snippet into your .github/workflows/require-tests.yml
file.
name: 'Require tests if source code is changed'
on:
pull_request_target:
types: [opened]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: infection/tests-checker-action@v1.0.2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Default values are:
comment: 'Could you please add tests to make sure this change works as expected?',
fileExtensions: '.php,.ts,.js,.c,.cs,.cpp,.rb,.java'
testDir: 'tests'
testPattern: ''
where
comment
- a text that bot will post when it won't find tests in the PRfileExtensions
- extensions of the files that should be treated as asource code
. Bot will do nothing if you just updatingREADME.md
because usually no tests are required to cover such change.testDir
- folder, where tests are located. Make sure to set it correctly, otherwise bot will not be able to understand whether the test file was added or not.testPattern
- a shell glob pattern that should match test files. For example, you can set it totestPattern: *_test.go
and Bot will be able to understand, that added test has this pattern instead of located intestDir
.testDir
andtestPattern
are alternatives, however can be used together.
How to override? You can configure the action by overriding any of the settings listed above.
- name: Require tests if source code is changed
uses: infection/tests-checker-action@v1
with:
fileExtensions: '.ts,.js'
testDir: '__tests__'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
First, you'll need to have a reasonably modern version of
node
handy. This won't work with versions older than 9, for instance.
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build && npm run package
Run the tests ✔️
$ npm test
PASS ./index.test.js
✓ test runs (95ms)
...
Actions are run from GitHub repos so we will checkin the packed dist folder.
Then run ncc and push the results:
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
Note: We recommend using the --license
option for ncc, which will create a license file for all of the production node modules used in your project.
Your action is now published! 🚀
See the versioning documentation