1

我正在配置Husky阻止commits如果prettieroreslint指责两者erroror warn,并阻止push如果它不通过tests.

但是,在运行时testtest 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"
        ]
    }
}

问题

4

1 回答 1

1

好吧,我必须做的是这个..

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

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

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

关于CI = true

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

笔记

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

于 2021-04-15T13:39:36.637 回答