不在监视模式下运行 Create-React-App 测试 [英] Run Create-React-App Tests not in Watch Mode

查看:22
本文介绍了不在监视模式下运行 Create-React-App 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Create-React-App 创建的项目.我希望添加一个 precommit 钩子,以使用 pre-commit 包运行我们的 linter 和测试.

I have a project created using Create-React-App. I am looking to add in a precommit hook to run our linter and tests with the pre-commit package.

"pre-commit": [
  "precommit-msg",
  "lint",
  "test"
],

然而,由于测试脚本默认在监视模式下运行,这会阻止提交实际发生.如何在预提交中添加不在 watch move 中的测试?

However, since the test script runs by default in watch mode, this prevents the commit from ever actually happening. How can add the tests not in watch move in the pre-commit?

推荐答案

您可以使用 --watchAll=false 参数.例如,您可以像这样创建另一个脚本:

You can use the --watchAll=false parameter. So for example you can create another script like this:

"scripts": {
  "test:nowatch": "react-scripts test --watchAll=false",
}

然后运行

"pre-commit": [
  "precommit-msg",
  "lint",
  "test:nowatch"
],

这篇关于不在监视模式下运行 Create-React-App 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆