You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
sources-peterbabic.dev/prevent-push-when-skipping-...
Peter Babič 24634bdeaf
insert post cypress husky stop-only
3 years ago
..
cypress insert posts sources 3 years ago
.gitignore insert posts sources 3 years ago
README.md insert post cypress husky stop-only 3 years ago
cypress.json insert posts sources 3 years ago
demo.gif insert posts sources 3 years ago
package-lock.json insert posts sources 3 years ago
package.json insert posts sources 3 years ago
server.js insert posts sources 3 years ago

README.md

Prevent push when skipping Cypress tests

Make sure your Cypress testing pipeline never let's you push broken code when accidentally skipping tests.

Setup

git clone https://git.peterbabic.dev/demo/cypress-prevent-push-skips.git
cd cypress-prevent-push-skips
npm install

How does it work

demo

Edit spec.js, add .skip or .only modifier to the test or tests and try to push any committed changes this way to the repository. The push shooed fail due to pre-push hook, that makes sure that the push fails in two situations:

  1. Any test contains .skip or .only, which means not all of them would be executed
  2. Any test fails, step 1 endures all tests are executed

The detection happens in the package.json

grep -Rvzq -e '.skip' -e '.only' cypress/integration

More details described in the blog post located at:

https://peterbabic.dev/blog/prevent-push-when-skipping-cypress-tests

Preventing the behavior

The push can be executed even with skipping or failing tests by supplying --no-verify

git push origin master --no-verify

Possible improvements

Currently, the message provided looks like this:

$ git push origin master
husky > pre-push (node v14.9.0)
husky > pre-push hook failed (add --no-verify to bypass)
error: failed to push some refs to 'git.peterbabic.dev:demo/cypress-prevent-push-skips.git'

However, it is not clear why the pre-push hook failed. The verbosity could be improved.

License

MIT