husky-commit-test.js 619 B

1234567891011121314151617181920212223
  1. const chalk = require('chalk')
  2. const spawn = require('child_process').spawn
  3. console.log(chalk.yellow('🐶 Checking tests before committing...'))
  4. const child = spawn('npm run test', [], { shell: true })
  5. child.stdout.on('data', function (data) {
  6. process.stdout.write(data)
  7. })
  8. child.on('error', function (err) {
  9. console.log(chalk.red(err))
  10. })
  11. child.on('exit', function (code) {
  12. if(code === 0){
  13. console.log(chalk.yellow('🐶 ✓ Tests run well, we can commit...'))
  14. } else {
  15. console.log(chalk.yellow('🐶 ✗ Tests are failing, please fix them before committing.'))
  16. process.exit(code);
  17. }
  18. })