本文介绍了不在观察模式下运行Create-React-App测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用Create-React-App创建的项目.我希望添加一个 precommit
钩子来运行我们的linter并使用 pre-commit
包进行测试.
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"
],
但是,由于测试脚本默认在监视模式下运行,因此可以防止实际发生提交.如何在预提交中添加不在监视中的测试?
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测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!