From cbd0e06b3d04cf6b8559cbd602a7a31e03b9748f Mon Sep 17 00:00:00 2001 From: typicode Date: Fri, 11 Dec 2020 14:56:47 +0100 Subject: [PATCH] add prepare-commit-msg test all credit goes to @kirkoman Co-authored-by: Kirk McKelvey --- scripts/test-install.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scripts/test-install.sh b/scripts/test-install.sh index 1459624e9..54866f115 100644 --- a/scripts/test-install.sh +++ b/scripts/test-install.sh @@ -152,5 +152,37 @@ if [ "$exitCode" -eq 0 ]; then exit 1 fi +# --- +test "hook should run and pass all HUSKY_GIT_PARAMS" +cat > .huskyrc << EOL +{ + "skipCI": false, + "hooks": { + "prepare-commit-msg": "echo \"prepare-commit-msg hook from Husky\" && echo \$HUSKY_GIT_PARAMS > $hookParamsFile" + } +} +EOL +if [ -f $hookParamsFile ]; then + rm $hookParamsFile +fi + +commit sixth + +if [ ! -f $hookParamsFile ]; then + echo "Fail: hook script didn't run" + exit 1 +fi + +actual=$(cat $hookParamsFile) +expected=".git/COMMIT_EDITMSG message" + +if [ "$actual" != "$expected" ]; then + echo "Fail: HUSKY_GIT_PARAMS weren't set correctly" + echo "$actual != $expected" + exit 1 +fi + echo echo "Success: all tests passed" + +