Husky Hook 无法与 Test 一起正常工作

问题描述

如果 Huskycommits 同时指控 prettiereslint,我正在配置 error 以阻止 warn,并阻止push 如果它没有通过 tests

但是,在运行 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,"lint-check": "eslint 'src/**/*.{ts,"lint-fix": "eslint --fix 'src/**/*.{ts,"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"
        ]
    }
}

Problem

解决方法

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

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

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

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

关于CI = true

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

注意

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...