From 87858e6726d2829e9f3514da6dccc28adf1a1852 Mon Sep 17 00:00:00 2001 From: Kirk McKelvey Date: Mon, 27 Jul 2020 11:02:43 -0400 Subject: [PATCH] enhance tests for multi-param hooks --- scripts/test-install.sh | 31 +++++++++++++++++++++++++++++++ src/runner/__tests__/index.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/test-install.sh b/scripts/test-install.sh index 1459624e9..820d11a72 100644 --- a/scripts/test-install.sh +++ b/scripts/test-install.sh @@ -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" diff --git a/src/runner/__tests__/index.ts b/src/runner/__tests__/index.ts index 729d6fab3..03c831d62 100644 --- a/src/runner/__tests__/index.ts +++ b/src/runner/__tests__/index.ts @@ -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', {