Jest 和 Commitizen:即使测试失败,Commit 仍然有效
Jest and Commitizen: Commit works even if tests fail
我目前正在使用 Jest、Husky、Commitizen 和 Vuepress。但是,当玩笑测试或构建失败时,提交挂钩仍然有效。当事情失败时,我该如何解决这个问题以退出 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 添加以下内容:
"husky": {
"hooks": {
"pre-commit": "npm run test:full",
...
}
},
我目前正在使用 Jest、Husky、Commitizen 和 Vuepress。但是,当玩笑测试或构建失败时,提交挂钩仍然有效。当事情失败时,我该如何解决这个问题以退出 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 添加以下内容:
"husky": {
"hooks": {
"pre-commit": "npm run test:full",
...
}
},