Skip to content

Commit

Permalink
enhance tests for multi-param hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirk McKelvey committed Jul 27, 2020
1 parent afac6c4 commit 87858e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions scripts/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,36 @@ 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"
2 changes: 1 addition & 1 deletion src/runner/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('run', (): void => {
)

// 'commit-msg' takes one parameter from git
const status = await index(['', '', 'commit-msg', 'git fake param'], {
const status = await index(['', '', 'commit-msg', 'git', 'fake', 'param'], {
cwd: dir,
})
expectSpawnSyncToHaveBeenCalledWith(dir, 'echo success', {
Expand Down

0 comments on commit 87858e6

Please sign in to comment.