typescript - 有没有办法在 jest hooks 中获取测试的文件名?
问题描述
基于https://jestjs.io/docs/en/configuration#testenvironment-string,在我的 jest 配置中我有
"testEnvironment": "<rootDir>/scripts/testEnvironment.js"
. 此 testEnvironment.js 文件包含具有 setup()、teardown() 和 handleTestEvent() 方法的自定义类。
有什么方法可以从一个玩笑的钩子中获取文件名,比如run_describe_start
,test_start
或者其他什么?
解决方案
如同一参考部分所示,环境类接收测试文件的完整路径:
class CustomEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context);
this.testPath = context.testPath;
...
}
文件名可以提取为
this.testFile = path.basename(this.testPath);
当在构造函数中赋值时,它在其他方法中可用。
推荐阅读
- azure - 使用 Azure Pipelines 在虚拟机规模集上进行 Azure Python 函数分解
- python - 由于缺少存根文件,Sphinx 没有迭代 .rst 文件
- api - 如何获取 facebook webhook 请求的静态 IP/域
- vba - (SQL Like 语句) + (ACCESS Combobox IMPUT) + (ACCESS SubFormulary OUTPUT)
- python - 如何将噪声签名/配置文件/指纹/PRNU 应用于新图像?
- r - r中的“情节”打包问题
- sql - 为表中的每一列创建一行视图
- configuration - 高级配置属性/属性页面在 VS2019 中消失了
- linux - 在 NAT 后面设置 Libreswan IPSec
- jspdf - 尝试测试页时自动打印失败