【问题标题】:Husky Hook does not work properly with TestHusky Hook 无法与 Test 一起正常工作
【发布时间】:2021-07-10 01:59:39
【问题描述】:

如果prettiereslint 同时指责errorwarn,我将Husky 配置为阻止commits,如果push 未通过@987654330,则阻止push @。

但是,在运行test 时,会显示test CLI (在下图中),这样,没有任何键可以工作,但我只能完成点击快捷方式ctrl+z其中 暂停我的 push

我的代码 .HUSKY 文件夹:

预提交

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn prettier-check
yarn lint-check

预推

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test

我的PACKAGE.JSON:

{
    "name": "web-whatsapp",
    "version": "0.0.0",
    "private": true,
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "prettier-check": "prettier --check 'src/**/*.{ts,tsx}'",
        "prettier-fix": "prettier --write 'src/**/*.{ts,tsx}'",
        "lint-check": "eslint 'src/**/*.{ts,tsx}'",
        "lint-fix": "eslint --fix 'src/**/*.{ts,tsx}'",
        "prepare": "husky install"
    },
    "dependencies": {
        "@testing-library/jest-dom": "^5.11.4",
        "@testing-library/react": "^11.1.0",
        "@testing-library/user-event": "^12.1.10",
        "@types/jest": "^26.0.15",
        "@types/node": "^12.0.0",
        "@types/react": "^17.0.0",
        "@types/react-dom": "^17.0.0",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-scripts": "4.0.3",
        "styled-components": "^5.2.3",
        "typescript": "^4.1.2",
        "web-vitals": "^1.0.1"
    },
    "devDependencies": {
        "@typescript-eslint/eslint-plugin": "^4.22.0",
        "@typescript-eslint/parser": "^4.22.0",
        "eslint": "^7.24.0",
        "eslint-config-airbnb": "^18.2.1",
        "eslint-config-prettier": "^8.2.0",
        "eslint-plugin-import": "^2.22.1",
        "eslint-plugin-jest": "^24.3.5",
        "eslint-plugin-jsx-a11y": "^6.4.1",
        "eslint-plugin-prettier": "^3.3.1",
        "eslint-plugin-react": "^7.23.2",
        "eslint-plugin-react-hooks": "^4.2.0",
        "eslint-plugin-testing-library": "^4.0.1",
        "husky": "^6.0.0",
        "lint-staged": "^10.5.4",
        "prettier": "^2.2.1"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }
}

【问题讨论】:

    标签: husky git-husky


    【解决方案1】:

    好吧,我要做的就是这个..

    1. 开发模式下安装cross-env库。该库导致终端在测试运行结束时清除缓冲区,以便继续使用pre-push Hook。

    2. 我在"test" 脚本中插入了以下内容:

      "test": "cross-env CI = true react-scripts test --passWithNoTests"

    关于CI = true

    这个环境变量是Continuous Integration的缩写,通常定义在各种CI环境中,例如Travis CIGithub Actions ,等等。

    注意

    不要使用 --watchAll 标志,因为它会“锁定”终端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 2020-08-19
      • 2013-02-06
      • 2019-02-02
      • 2021-10-15
      • 2016-07-05
      • 2016-09-13
      相关资源
      最近更新 更多