From 61e271b88735844cbd4c83794f4ee600cd1a5b0b Mon Sep 17 00:00:00 2001 From: typicode Date: Tue, 2 Mar 2021 03:42:27 +0100 Subject: [PATCH] test: fix and refactor tests --- package.json | 2 +- test/init-yarn-1.sh | 2 +- test/init-yarn-2.sh | 14 ++++++++++---- test/{init-npm.sh => init.sh} | 0 4 files changed, 12 insertions(+), 6 deletions(-) rename test/{init-npm.sh => init.sh} (100%) diff --git a/package.json b/package.json index c2c02526c..37653c49b 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "prepublishOnly": "pinst --disable", "postpublish": "pinst --enable", "pretest": "npm run build --silent && npm pack --silent", - "test": "sh ./test/init-npm.sh && sh ./test/init-yarn-2.sh && sh ./test/default.sh && sh ./test/sub-dir.sh && sh ./test/config-dir.sh && sh ./test/not-git-dir.sh", + "test": "sh ./test/init.sh && sh ./test/init-yarn-2.sh && sh ./test/default.sh && sh ./test/sub-dir.sh && sh ./test/config-dir.sh && sh ./test/not-git-dir.sh", "posttest": "rm husky-*.tgz", "commit": "commit" }, diff --git a/test/init-yarn-1.sh b/test/init-yarn-1.sh index d29f62d63..9785efcc4 100644 --- a/test/init-yarn-1.sh +++ b/test/init-yarn-1.sh @@ -3,7 +3,7 @@ # shellcheck source=./_functions.sh . "$(dirname "$0")/_functions.sh" -title "init" +title "yarn v1" tempDir="/tmp/husky-yarn-1-test" rm -rf $tempDir diff --git a/test/init-yarn-2.sh b/test/init-yarn-2.sh index 09811245f..5c632112f 100644 --- a/test/init-yarn-2.sh +++ b/test/init-yarn-2.sh @@ -3,7 +3,7 @@ # shellcheck source=./_functions.sh . "$(dirname "$0")/_functions.sh" -title "init" +title "yarn v2" tempDir="/tmp/husky-yarn-2-test" rm -rf $tempDir @@ -16,11 +16,12 @@ mkdir -p $tempDir # Install cp $tgz $tempDir/husky.tgz -yarn set version berry -cd $tempDir && yarn init -y && yarn add ./husky.tgz +cd $tempDir +yarn set version berry && yarn init -y && yarn add ./husky.tgz init_git yarn husky init +yarn # will install pinst npm set-script test "echo \"msg from pre-commit hook\" && exit 1" # Test package.json scripts @@ -36,5 +37,10 @@ git add package.json git commit -m "should fail" || ok # Uninstall +# Prevent yarn remove from failing due to missing husky command in postinstall +npm set-script postinstall "" yarn remove husky -git config core.hooksPath || ok + +# Yarn 2 doesn't run husky's uninstall script, so core.hooksPath is still set +# and needs to be manually removed +git config core.hooksPath && ok diff --git a/test/init-npm.sh b/test/init.sh similarity index 100% rename from test/init-npm.sh rename to test/init.sh