问题描述
我目前正在使用 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"
}
}
}
解决方法
想通了 - 这很简单。我需要向哈士奇添加以下内容:
$(document).ready(function () {
$('.filter').change(function () {
var values = [];
$('.filter option:selected').each(function () {
if ($(this).val() != "") values.push($(this).text());
});
filter('table > tbody > tr',values);
});
function filter(selector,values) {
$(selector).each(function () {
var sel = $(this);
var tokens = sel.text().split('\n');
var toknesObj = [],i;
for(i=0;i<tokens.length;i++){
toknesObj.push( {text:tokens[i].trim(),found:false});
}
var show = false;
console.log(values);
$.each(values,function (i,val) {
for(i=0;i<toknesObj.length;i++){
if (!toknesObj[i].found && toknesObj[i].text.search(new RegExp("\\b"+val+"\\b")) >= 0) {
toknesObj[i].found = true;
}
}
});
var count = 0;
$.each(toknesObj,val) {
if (val.found){
count+=1;
}
});
show = (count === values.length);
show ? sel.show() : sel.hide();
});
}
});