K
K
Klein Maximus2021-06-03 11:54:09
git
Klein Maximus, 2021-06-03 11:54:09

How to run git pre-push via husky conditionally?

There is a project consisting of several folders. Husky is configured to run tests in one of them:

{
  "scripts": {
    "test:coverage": "jest ./client/public/app-react/src --coverage",
  },
  "husky": {
    "hooks": {
      "pre-push": "npm run test:coverage"
    }
  }
}


Is it possible to somehow configure pre-push so that it starts only if changes from the specified folder are "pushed", and so that it does not react to the rest?

Or is there some other way to set it up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-06-03
@Lynn

Husky can't be configured this way, but you can "configure" the command he runs to check for changes. The most popular way today is probably the use of lint-staged .

// package.json
{
  "husky": {
    "hooks": {
      "pre-push": "lint-staged"
    }
  }
}

// lint-staged.config.js
module.exports = {
  './client/public/app-react/src/**/*.js': () => 'jest ./client/public/app-react/src --coverage',
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question