【问题标题】:husky pre-commit hook for 'test' does not finish“测试”的 husky 预提交钩子未完成
【发布时间】:2021-10-21 03:52:26
【问题描述】:

您好,我安装了huskylint-stage,以便为暂存文件提供linttests 的预提交挂钩。

当我转到git commit -m 'something' 时,预提交挂钩起作用,并触发了命令。

我目前所拥有的文件是:


.husky/pre-commit:

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

npx lint-staged

.package.json:

 "lint-staged": {
   "*.{ts,tsx}": "eslint --cache --fix",
   "*": "react-scripts test --env=jest-environment-jsdom-fourteen"
  } 

当我 git commit ..,(2 个文件,1 个 *.test.ts * 和 1 个 *.ts)时,它会启动 lintertest,但测试永远不会完成,除非我打破它(ctrl +c)。

  • *.test.ts 文件,里面有错误。

只有当我打破它时,我才会在屏幕上看到错误:

我还注意到lint-staged: 对象,当我git commit.. 时,它变成了package.json:

一开始我是这样的:

 "lint-staged": {
    "*.{ts,tsx}": "eslint --cache --fix",
    "*.test.{ts, tsx}": "react-scripts test --env=jest-environment-jsdom-fourteen"
 }

结果变成了这样:

 "lint-staged": {
   "*.{ts,tsx}": "eslint --cache --fix",
   "*": "react-scripts test --env=jest-environment-jsdom-fourteen"
 }

欢迎对我错过的配置提供任何帮助。

【问题讨论】:

    标签: git package.json githooks husky lint-staged


    【解决方案1】:

    所以我通过在脚本中添加标志 --watchAll=false 解决了这个问题,我们摆脱了交互:

    react-scripts test --env=jsdom --watchAll=false --bail

    通过添加--bail 标志(可选),它会在第一次失败的测试时退出。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2021-07-07
      • 1970-01-01
      • 2013-12-15
      • 2017-02-08
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多