Jest和Commilizen:即使测试失败,Commit也能工作



我目前正在使用Jest、Husky、Commitizen和Vuepress。然而,当jest测试或构建失败时,提交挂钩仍然有效。当事情失败时,我如何解决这个问题以退出commitizen挂钩?以下是package.json:中的相关行

{
"scripts": {
"build": "vuepress build docs
"lint": "eslint --fix --ext .js,.vue docs/.vuepress",
"test": "npm run lint && jest --coverage --coverageDirectory='__coverage__'",
"test:full": "npm run test && npm run build",
"commit": "cz",
...
},
"husky": {
"hooks": {
"prepare-commit-msg": "npm run test:full && exec < /dev/tty && git cz --hook || true"
}
},
"dependencies": {
...
},
"devDependencies": {
"babel-jest": "^26.6.3",
"commitizen": "^4.2.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.18.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
...
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

想明白了——很简单。我需要添加以下到哈士奇:

"husky": {
"hooks": {
"pre-commit": "npm run test:full",
...
}
},

最新更新