0

嗨,我安装了husky&以便为暂存文件提供&lint-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"
  } 

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

  • * .test.ts文件,其中有错误。

在此处输入图像描述

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

在此处输入图像描述

我还注意到lint-staged:,当我git commit..

最初我是这样的:

 "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"
 }

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

4

1 回答 1

1

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

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

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

于 2021-08-20T09:52:20.580 回答