gpt4 book ai didi

node.js - 如何判断 Jasmine 中哪些测试花费的时间最多?

转载 作者:搜寻专家 更新时间:2023-10-31 22:50:48 24 4
gpt4 key购买 nike

我注意到整套 Jasmine 测试开始花费的时间比我希望的要多,但我不确定是哪些真正导致了延迟。有没有一种方法可以在不单独运行每个测试的情况下找出答案?

最佳答案

基础ConsoleReporter仅报告所有测试耗时,但如果您查看 source code从中您会发现很容易修改以添加每个规范的耗时。基本上你需要做的是在函数 reportSpecStarting 时记录规范开始的时间。 (就在规范开始运行之前)被调用并输出函数 reportSpecResults 时的差异。 (那是在规范完成运行之后)。

因此,如果您修改了 ConsoleReporter 有了这个,它会输出每个规范的名称及其耗时:

this.reportSpecStarting = function() {
this.specStartingTime = this.now();
};

this.reportSpecResults = function(spec) {
var results = spec.results();

print(results.description + " ");

if (results.skipped) {
yellowStar();
} else if (results.passed()) {
greenDot();
} else {
redF();
}

print(" (" + (this.now() - this.specStartingTime) + "ms)");
newline();
};

关于node.js - 如何判断 Jasmine 中哪些测试花费的时间最多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14030175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com