How to configure husky pre-push hook to run tests
Asked Answered
B

3

10

I am trying to configure husky pre-push hook to run tests before push. Everything looks fine. After run git push origin hook is fired and tests are runing. Problem is that when tests are done and even if operation is successed, push is freezed and nothing else happened.

package.json

  "scripts": {
    ...
    "pre-commit": "npm run lint",
    "pre-push": "npm run test"
  }

.husky/pre-push

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run pre-push

enter image description here

Buddha answered 30/3, 2022 at 6:14 Comment(0)
I
6

By default unit tests run in watch mode. You can override this by doing ng test --watch=false

Incogitable answered 30/3, 2022 at 14:45 Comment(1)
--watchAll=falseMorel
A
4

If you re using Vitest:

yarn vitest --run
Averill answered 15/3, 2023 at 15:30 Comment(1)
vitest.dev/guide/cli "Don't forget that Vitest runs with enabled watch mode by default. If you are using tools like lint-staged, you should also pass --run option, so that command can exit normally."Newfangled
S
1

This is what worked for me

npm test -- --watchAll=false

I've added that to the pre-commit file that was generated in the husky folder in the repo

This is the whole content of the file

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test -- --watchAll=false
Scathe answered 2/9, 2022 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.