pre-commit
allows you to run linting & unit tests in a pre commit hook.
Generally a pre-commit
hook should only test & lint that which has changed.
This one is easy.
jshint --verbose $(git diff --cached --name-only | grep '\\.js$')
To be able to test what has changed we need a command called node-parents
node-parents $(git diff --cached --name-only | grep '\\.js$') \
| grep 'test' \
| grep -v 'node_modules' \
| xargs -L node
node-parents
will take a list of files and print all the parents & grandparents & etc that require it recursively.
This allows you to find test/foo.js
that requires the changed file directly or indirectly
For node-parents
to be useful in this context it should have an mtime based stat cache.