Documenting running tests in precommit hook
See original GitHub issueI want a git pre-commit hook that runs test on staged files before commits (similar to this)
This will require access to jest configs such as bail and findRelatedTests.
currently i am running this pre-commit
#!/bin/sh
PASS=true
echo "running tests"
CI=true npm test
if [[ "$?" == 0 ]]; then
echo "\t\033[32mJest Tests Passed\033[0m"
else
echo "\t\033[41mJest Tests Failed\033[0m"
PASS=false
fi
but this results in every single test being run, which takes a long time. i want to effectively run
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "js$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
echo "running tests"
jest --bail --findRelatedTests $STAGED_FILES
if [[ "$?" == 0 ]]; then
echo "\t\033[32mJest Tests Passed\033[0m"
else
echo "\t\033[41mJest Tests Failed\033[0m"
PASS=false
fi
I believe allowing for this will encourage better practices and am willing to take a stab at it if the maintainers think that it would be useful.
(also open to other solutions that people might use to achieve the same functionality)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Supported hooks - pre-commit
php-unit - Run the full php unit test. Checks which PHPUnit executable is available first and then runs it. Preference order is vendor/bin,...
Read more >Git Pre-Commit Hooks and Specta's Focused Examples
A Git pre-commit hook to prevent accidentally committing a Specta test suite with a focused examples (fit or fdescribe).
Read more >Automate Your Python Code Documentation with Pre-commit ...
Automate Your Python Code Documentation with Pre-commit Hooks. A hands-on guide to automating docstrings checks and auto-generating ...
Read more >Git Hooks - Git SCM
The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to...
Read more >Useful git pre-commit hooks for R - README
Pre-commit hooks are tests that run each time you attempt to commit. If the tests pass, the commit will be made, otherwise not....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
any plan to use https://github.com/okonet/lint-staged?
you can then implement what I suggested in https://github.com/facebookincubator/create-react-app/issues/2336#issuecomment-303349467
then
for the env variable, use cross-env… it is cross platform
hope it helps!
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.