如何判断哪些测试花在茉莉花上的时间最多?

Flu*_*ffy 5 node.js jasmine

我注意到整套Jasmine测试开始花费我想要的更多时间,但我不确定,哪些实际上会造成延迟.有没有办法在不单独运行每个测试的情况下找到它?

HoL*_*ieR 2

基本ConsoleReporter仅报告所有测试所用的时间,但如果您查看它的源代码,您会发现很容易修改以添加每个规范的所用时间。基本上,您需要做的是记录调用函数(即在规范开始运行之前)时规范启动的时间,并输出函数(即在规范运行完成之后)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();
};
Run Code Online (Sandbox Code Playgroud)