reactjs - Jest 应该只在预提交钩子的更改文件上运行
问题描述
--only-changed
我有一个使用 jest 和标志设置的预提交挂钩。但是,有时即使我在单个文件中进行了更改,我的整个测试套件仍会运行(800 个测试!)。
我查看了其他一些jest
标志,例如
--lastCommit Run all tests affected by file changes in
the last commit made. Behaves similarly to
`--onlyChanged`.
--findRelatedTests Find related tests for a list of source
files that were passed in as arguments.
Useful for pre-commit hook integration to
run the minimal amount of tests necessary.
--changedSince Runs tests related to the changes since the
provided branch. If the current branch has
diverged from the given branch, then only
changes made locally will be tested. Behaves
similarly to `--onlyChanged`. [string]
然而他们都有同样的问题。在进行一些挖掘时,我了解到 “如果找到的文件是测试文件, Jest运行它,很简单。如果找到的文件是源文件,则将其命名为 found-file.js,然后任何测试文件导入 found-file.js 和导入任何源文件的测试文件,这些源文件本身导入 found-file.js。 "
我正在做一个对我来说相对较新的项目。我想知道我是否有可能让我的预提交挂钩只运行编辑后的测试,而不是所有受影响的测试,或者我是否有办法追踪这棵“传递逆依赖”树并尝试解决不同进口或其他东西的问题。
这是尝试的一些输出示例--find-related-tests
Test Suites: 2 failed, 309 passed, 311 total
Tests: 2 failed, 803 passed, 805 total
Snapshots: 308 passed, 308 total
Time: 102.366 s
Ran all test suites related to files matching /\/Users\/me\/repo\/project\/src\/modules\/dogs\/components\/spots\/SpotsSpotter.tsx/i.
> @dogsapp/project@1.0.0 test:staged
> jest --findRelatedTests --passWithNoTests "/Users/me/repo/project/src/modules/dogs/components/spots/SpotsSpotter.tsx"
ERROR: "husky:lint-staged" exited with 1.
husky - pre-commit hook exited with code 1 (error)
当我只对一个文件进行简单更改时,它花费的时间太长了。任何人都知道我怎样才能找到为什么会这样?
似乎在这里为 --watch 标志解决了类似的问题:https ://www.gitmemory.com/issue/facebook/jest/8276/483695303
解决方案
推荐阅读
- r - 如何使用ggplot获取箱线图中的所有点?
- c# - 无法转换协变泛型接口
- python-3.x - Discord.py 运行后显示 SSLCertVerificationError。Git openssl lib 和 conda openssl 版本不匹配。视窗 10
- powershell - PowerShell 中的递归 DFS
- google-cloud-sql - Google Cloud SQL 迁移作业卡在运行中
- arrays - 如何从 Java 中的 json 文件中读取 int 值?
- mongodb - db.collection.find() 返回省略 mongodb 中没有值的键
- javascript - 循环遍历对象数组以搜索来源 -> 目的地和目的地 -> 来源和拉取计数
- c++ - 从 resource.rc 创建文件返回 null
- angular - 如何处理对 asObservable() 公开的私有主题的多个订阅