gpt4 book ai didi

Husky Hook 不能与测试一起正常工作

转载 作者:行者123 更新时间:2023-12-05 06:01:45 26 4
gpt4 key购买 nike

如果 prettiereslint 同时指责 ,我正在配置 Husky 来阻止 commits错误警告,如果未通过测试,则阻止push

但是,当运行test时,testCLI显示(如下图所示),有了这个,没有任何键起作用,但我只能通过单击快捷键 ctrl+z 来完成, 暂停我的

我的代码在 .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"
]
}
}

Problem

最佳答案

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

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

  2. 我在 “测试” 脚本中插入了以下内容:

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

关于 CI = true

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

注意

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

关于Husky Hook 不能与测试一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67101563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com